Skip to content

Commit

Permalink
chore: linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Nov 6, 2022
1 parent 743f9b1 commit 7613caf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
18 changes: 7 additions & 11 deletions scrapers/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package file
import (
"crypto/md5"
"encoding/hex"
"math/rand"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/flanksource/commons/logger"
v1 "github.com/flanksource/config-db/api/v1"
Expand All @@ -23,12 +21,6 @@ import (
type FileScrapper struct {
}

const charset = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

var seededRand *rand.Rand = rand.New(
rand.NewSource(time.Now().UnixNano()))

func isIgnored(config v1.File, path string) (bool, error) {
if !isYaml(path) && !isJson(path) {
logger.Tracef("skipping file %s, not a yaml or json file", path)
Expand Down Expand Up @@ -58,18 +50,22 @@ func stripSecrets(uri string) string {
}

func stripPrefix(filename string) string {
return regexp.MustCompile("^\\w+::").ReplaceAllString(filename, "")
filename = regexp.MustCompile(`^\w+::`).ReplaceAllString(filename, "")
return strings.Replace(filename, "file://", "", 1)
}

// convert url into a local path supported on linx filesystems
// convert url into a local path supported on linux filesystems
func convertToLocalPath(uri string) string {
_uri, err := url.Parse(stripPrefix(uri))
if err != nil {
return uri
}
hash := md5.Sum([]byte(uri))
return path.Base(_uri.Path) + "-" + hex.EncodeToString(hash[:])
p := ""
if _uri.Host != "" {
p = _uri.Host + "-"
}
return p + path.Base(_uri.Path) + "-" + hex.EncodeToString(hash[:])[0:8]
}

// Scrape ...
Expand Down
41 changes: 41 additions & 0 deletions scrapers/file/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package file

import "testing"

//test stripPrefix
func TestStripPrefix(t *testing.T) {
cases := []struct {
input string
expected string
}{
{"file://foo", "foo"},
{"git::foo", "foo"},
{"git::https://foo", "https://foo"},
{"foo", "foo"},
{"", ""},
}
for _, c := range cases {
actual := stripPrefix(c.input)
if actual != c.expected {
t.Errorf("stripPrefix(%s) == %s, expected %s", c.input, actual, c.expected)
}
}
}

func TestConvertLocalPath(t *testing.T) {
cases := []struct {
input string
expected string
}{
{"file://foo", "foo-ecf5c8ee"},
{"git::foo", "foo-b943d8a5"},
{"git::https://foo/path?query=abc", "foo-path-8f49fbdc"},
{"foo", "foo-acbd18db"},
}
for _, c := range cases {
actual := convertToLocalPath(c.input)
if actual != c.expected {
t.Errorf("convertToLocalPath(%s) == %s, expected %s", c.input, actual, c.expected)
}
}
}
9 changes: 0 additions & 9 deletions scrapers/kubernetes/kubernetes_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ func findDeployments(ctx *v1.ScrapeContext, client *kubernetes.Clientset, config
return deployments, nil
}

func findStatefulsets(ctx *v1.ScrapeContext, client *kubernetes.Clientset, config v1.ResourceSelector) ([]appsv1.Deployment, error) {
return nil, nil
}

func findDaemonsets(ctx *v1.ScrapeContext, client *kubernetes.Clientset, config v1.ResourceSelector) ([]appsv1.Deployment, error) {
return nil, nil
}

func findBySelector(ctx *v1.ScrapeContext, client *kubernetes.Clientset, config v1.KubernetesFile, namespace, selector, id string, count int) ([]pod, error) {

podsList, err := findPods(ctx, client, v1.ResourceSelector{
Namespace: namespace,
LabelSelector: selector,
Expand Down

0 comments on commit 7613caf

Please sign in to comment.