-
Notifications
You must be signed in to change notification settings - Fork 175
feature: adding private repo capability #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
fcfe308
d6fea4f
f8e9196
3b00739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import ( | |
| "crypto/tls" | ||
| "errors" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "io" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
|
|
@@ -13,13 +13,13 @@ import ( | |
| "github.com/yannh/kubeconform/pkg/cache" | ||
| ) | ||
|
|
||
| type httpGetter interface { | ||
| Get(url string) (resp *http.Response, err error) | ||
| type httpDoer interface { | ||
| Do(*http.Request) (resp *http.Response, err error) | ||
| } | ||
|
|
||
| // SchemaRegistry is a file repository (local or remote) that contains JSON schemas for Kubernetes resources | ||
| type SchemaRegistry struct { | ||
| c httpGetter | ||
| c httpDoer | ||
| schemaPathTemplate string | ||
| cache cache.Cache | ||
| strict bool | ||
|
|
@@ -72,8 +72,13 @@ func (r SchemaRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8sVers | |
| return url, b.([]byte), nil | ||
| } | ||
| } | ||
| req, _ := http.NewRequest("GET", url, nil) | ||
|
|
||
| resp, err := r.c.Get(url) | ||
| if token, exist := os.LookupEnv("GITHUB_TOKEN"); exist { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having some thoughts on how this will work when using multiple schema registries. When using the default registry plus one private one, we will be passing a GITHUB_TOKEN for the default registry too - does this work? This also won't work for multiple registries that might require different GITHUB_TOKENS, though I might be ok with that simplification for the sake of UI.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the first question, if you pass the token to github in a non-authenticated it works (and also all of them will fail if you have an invalid token)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can make it 2 env vars?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh another option might be creating a private registry struct implementing the registerer, and passing the values like |
||
| req.Header.Add("Authorization", fmt.Sprintf("token %s", token)) | ||
| } | ||
|
|
||
| resp, err := r.c.Do(req) | ||
| if err != nil { | ||
| msg := fmt.Sprintf("failed downloading schema at %s: %s", url, err) | ||
| if r.debug { | ||
|
|
@@ -99,7 +104,7 @@ func (r SchemaRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8sVers | |
| return url, nil, fmt.Errorf(msg) | ||
| } | ||
|
|
||
| body, err := ioutil.ReadAll(resp.Body) | ||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| msg := fmt.Sprintf("failed parsing schema from %s: %s", url, err) | ||
| if r.debug { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the error? 🙏