Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cache/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestCache(t *testing.T) {
resp = &http.Response{
StatusCode: 200,
}
resp = cacher.OnResponse(resp, ctx)
_ = cacher.OnResponse(resp, ctx)
if len(cacher.cacheDB) != 1 {
t.Error("cache should have 1 entry, got", len(cacher.cacheDB))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func (c Credential) Host() string {
// GetListOfStrings returns an array of strings
func (c Credential) GetListOfStrings(key string) []string {
value := c[key]
switch value.(type) {
switch val := value.(type) {
case []string:
return value.([]string)
return val
case []interface{}:
strings := make([]string, len(value.([]interface{})))
for i, v := range value.([]interface{}) {
strings := make([]string, len(val))
for i, v := range val {
if str, ok := v.(string); ok {
strings[i] = str
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type control func(network, address string, conn syscall.RawConn) error

func safeControl(blockedIps []net.IP) control {
return func(network string, address string, conn syscall.RawConn) error {
if !(network == "tcp4" || network == "tcp6") {
if network != "tcp4" && network != "tcp6" {
return fmt.Errorf("%s is not a safe network type", network)
}

Expand Down
14 changes: 7 additions & 7 deletions internal/handlers/docker_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDockerRegistryHandler(t *testing.T) {
// Regular private registry
req := httptest.NewRequest("GET", "https://registry.hub.docker.com/my-repo", nil)
ctx := &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
rt, ok := ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.True(t, ok, "request is assigned a docker registry transport")
trans := rt.transport.(*registry.BasicTransport)
Expand All @@ -75,7 +75,7 @@ func TestDockerRegistryHandler(t *testing.T) {
// Registry using URL not registry key
req = httptest.NewRequest("GET", "https://registry.hub.docker.com/my-repo", nil)
ctx = &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
rt, ok = ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.True(t, ok, "request is assigned a docker registry transport")
trans = rt.transport.(*registry.BasicTransport)
Expand All @@ -85,7 +85,7 @@ func TestDockerRegistryHandler(t *testing.T) {
// Different private registry
req = httptest.NewRequest("GET", "https://docker.bigco.com/their-repo", nil)
ctx = &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
rt, ok = ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.True(t, ok, "request is assigned a docker registry transport")
trans = rt.transport.(*registry.BasicTransport)
Expand Down Expand Up @@ -119,28 +119,28 @@ func TestDockerRegistryHandler(t *testing.T) {
// Missing repo subdomain
req = httptest.NewRequest("GET", "https://bigco.com/their-repo", nil)
ctx = &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
_, ok = ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.False(t, ok, "different subdomain request isn't assigned a docker registry transport")

// HTTP, not HTTPS
req = httptest.NewRequest("GET", "http://docker.bigco.com/their-repo", nil)
ctx = &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
_, ok = ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.False(t, ok, "request isn't assigned a docker registry transport")

// Not a GET request
req = httptest.NewRequest("POST", "https://docker.bigco.com/their-repo", nil)
ctx = &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
_, ok = ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.False(t, ok, "request isn't assigned a docker registry transport")

// Nexus, BasicAuth
req = httptest.NewRequest("GET", "https://nexus.someco.com/a-repo", nil)
ctx = &goproxy.ProxyCtx{}
req, _ = handler.HandleRequest(req, ctx)
_, _ = handler.HandleRequest(req, ctx)
rt, ok = ctx.RoundTripper.(*dockerRegistryRoundTripper)
assert.True(t, ok, "request is assigned a docker registry transport")
trans = rt.transport.(*registry.BasicTransport)
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/goproxy_server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (h *GoProxyServerHandler) HandleRequest(req *http.Request, ctx *goproxy.Pro

// Fall back to static credentials
for _, cred := range h.credentials {
if !(helpers.UrlMatchesRequest(req, cred.url, true) || helpers.CheckHost(req, cred.host)) {
if !helpers.UrlMatchesRequest(req, cred.url, true) && !helpers.CheckHost(req, cred.host) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/maven_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (h *MavenRepositoryHandler) HandleRequest(req *http.Request, ctx *goproxy.P

// Fall back to static credentials
for _, cred := range h.credentials {
if !(helpers.UrlMatchesRequest(req, cred.url, true) || helpers.CheckHost(req, cred.host)) {
if !helpers.UrlMatchesRequest(req, cred.url, true) && !helpers.CheckHost(req, cred.host) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/nuget_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (h *NugetFeedHandler) HandleRequest(req *http.Request, ctx *goproxy.ProxyCt

// Fall back to static credentials
for _, cred := range h.credentials {
if (cred.token == "" && cred.password == "") || !(helpers.UrlMatchesRequest(req, cred.url, true) || helpers.CheckHost(req, cred.host)) {
if (cred.token == "" && cred.password == "") || (!helpers.UrlMatchesRequest(req, cred.url, true) && !helpers.CheckHost(req, cred.host)) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/python_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (h *PythonIndexHandler) HandleRequest(req *http.Request, ctx *goproxy.Proxy
for _, cred := range h.credentials {
re, _ := regexp.Compile(`/\+?simple/?\z`)
indexURL := re.ReplaceAllString(cred.indexURL, "/")
if !(helpers.UrlMatchesRequest(req, indexURL, true) || helpers.CheckHost(req, cred.host)) {
if !helpers.UrlMatchesRequest(req, indexURL, true) && !helpers.CheckHost(req, cred.host) {
continue
}

Expand Down
5 changes: 3 additions & 2 deletions internal/metrics/collector_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ func (c *CollectorClient) SendMetric(name string, metricType string, value float
"type": metricType,
"tags": combinedTags,
}
if metricType == "increment" {
switch metricType {
case "increment":
metricData["value"] = value
} else if metricType == "distribution" {
case "distribution":
metricData["values"] = []float64{value}
}

Expand Down
1 change: 1 addition & 0 deletions internal/oidc/oidc_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func TestTryCreateOIDCCredential(t *testing.T) {

if actual == nil {
t.Fatalf("expected credential, but got nil")
return
}

// check type
Expand Down
Loading