-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfallback_factory.go
More file actions
74 lines (71 loc) · 2.93 KB
/
fallback_factory.go
File metadata and controls
74 lines (71 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package fallback
import (
"net/url"
"strings"
"github.com/tweag/credential-helper/api"
authenticateAzStorage "github.com/tweag/credential-helper/authenticate/azstorage"
authenticateGAR "github.com/tweag/credential-helper/authenticate/gar"
authenticateGCS "github.com/tweag/credential-helper/authenticate/gcs"
authenticateGitHub "github.com/tweag/credential-helper/authenticate/github"
authenticateNull "github.com/tweag/credential-helper/authenticate/null"
authenticateOCI "github.com/tweag/credential-helper/authenticate/oci"
authenticateRemoteAPIs "github.com/tweag/credential-helper/authenticate/remoteapis"
authenticateS3 "github.com/tweag/credential-helper/authenticate/s3"
"github.com/tweag/credential-helper/logging"
)
func FallbackHelperFactory(rawURL string) (api.Helper, error) {
u, err := url.Parse(rawURL)
if err != nil {
return nil, err
}
switch {
case strings.HasSuffix(u.Hostname(), ".amazonaws.com"):
return &authenticateS3.S3{}, nil
case strings.EqualFold(u.Hostname(), "storage.googleapis.com"):
return &authenticateGCS.GCS{}, nil
case strings.EqualFold(u.Hostname(), "github.com"):
fallthrough
case strings.HasSuffix(strings.ToLower(u.Host), ".github.com"):
fallthrough
case strings.EqualFold(u.Hostname(), "raw.githubusercontent.com"):
return &authenticateGitHub.GitHub{}, nil
case strings.HasSuffix(strings.ToLower(u.Hostname()), ".r2.cloudflarestorage.com") && !u.Query().Has("X-Amz-Expires"):
return &authenticateS3.S3{}, nil
case strings.HasSuffix(u.Hostname(), ".buildbuddy.io"):
return &authenticateRemoteAPIs.RemoteAPIs{}, nil
case strings.HasSuffix(u.Hostname(), "pkg.dev"):
return &authenticateGAR.GAR{}, nil
case strings.HasSuffix(u.Hostname(), "blob.core.windows.net"):
return &authenticateAzStorage.AzStorage{}, nil
// container registries using the default OCI resolver
case strings.HasSuffix(u.Hostname(), ".app.snowflake.com"):
fallthrough
case strings.HasSuffix(u.Hostname(), ".azurecr.io"):
fallthrough
case strings.EqualFold(u.Hostname(), "cgr.dev"):
fallthrough
case strings.EqualFold(u.Hostname(), "docker.elastic.co"):
fallthrough
case strings.EqualFold(u.Hostname(), "gcr.io"):
fallthrough
case strings.EqualFold(u.Hostname(), "ghcr.io"):
fallthrough
case strings.EqualFold(u.Hostname(), "index.docker.io"):
fallthrough
case strings.EqualFold(u.Hostname(), "nvcr.io"):
fallthrough
case strings.EqualFold(u.Hostname(), "public.ecr.aws"):
fallthrough
case strings.EqualFold(u.Hostname(), "quay.io"):
fallthrough
case strings.EqualFold(u.Hostname(), "registry.gitlab.com"):
return authenticateOCI.NewFallbackOCI(), nil
default:
if authenticateOCI.GuessOCIRegistry(rawURL) {
logging.Debugf("$CREDENTIAL_HELPER_GUESS_OCI_REGISTRY is set and uri looks like a registry: %s\n", rawURL)
return authenticateOCI.NewFallbackOCI(), nil
}
logging.Basicf("no matching credential helper found for %s - returning empty response\n", rawURL)
return authenticateNull.Null{}, nil
}
}