Skip to content

Commit

Permalink
Fix: don't use underscores in Go names
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Vrba <[email protected]>
  • Loading branch information
Jiri Vrba committed Feb 16, 2024
1 parent 76fbe83 commit 97cce99
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/pkg/reg/adapter/dockerhub/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func getAdapterInfo() *model.AdapterPattern {
// - Pauses for given time when limit is hit.
// - Allows 2 more attempts before giving up.
// Reason: Observed (02/2024) penalty for hitting the limit is 120s, normal reset is 60s,
// so it is better to not hit the wall.
func (a *adapter) limit_aware_http_do(method string, path string, body io.Reader) (*http.Response, error) {
//
// so it is better to not hit the wall.
func (a *adapter) limitAwareDo(method string, path string, body io.Reader) (*http.Response, error) {
var attempts_left int = 3
for attempts_left > 0 {
resp, err := a.client.Do(method, path, body)
Expand Down Expand Up @@ -205,7 +206,7 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
}

func (a *adapter) listNamespaces() ([]string, error) {
resp, err := a.limit_aware_http_do(http.MethodGet, listNamespacePath, nil)
resp, err := a.limitAwareDo(http.MethodGet, listNamespacePath, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -253,7 +254,7 @@ func (a *adapter) CreateNamespace(namespace *model.Namespace) error {
return err
}

resp, err := a.limit_aware_http_do(http.MethodPost, createNamespacePath, bytes.NewReader(b))
resp, err := a.limitAwareDo(http.MethodPost, createNamespacePath, bytes.NewReader(b))
if err != nil {
return err
}
Expand All @@ -274,7 +275,7 @@ func (a *adapter) CreateNamespace(namespace *model.Namespace) error {

// getNamespace get namespace from DockerHub, if the namespace not found, two nil would be returned.
func (a *adapter) getNamespace(namespace string) (*model.Namespace, error) {
resp, err := a.limit_aware_http_do(http.MethodGet, getNamespacePath(namespace), nil)
resp, err := a.limitAwareDo(http.MethodGet, getNamespacePath(namespace), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -435,7 +436,7 @@ func (a *adapter) DeleteManifest(repository, reference string) error {
return fmt.Errorf("dockerhub only support repo in format <namespace>/<name>, but got: %s", repository)
}

resp, err := a.limit_aware_http_do(http.MethodDelete, deleteTagPath(parts[0], parts[1], reference), nil)
resp, err := a.limitAwareDo(http.MethodDelete, deleteTagPath(parts[0], parts[1], reference), nil)
if err != nil {
return err
}
Expand All @@ -456,7 +457,7 @@ func (a *adapter) DeleteManifest(repository, reference string) error {

// getRepos gets a page of repos from DockerHub
func (a *adapter) getRepos(namespace, name string, page, pageSize int) (*ReposResp, error) {
resp, err := a.limit_aware_http_do(http.MethodGet, listReposPath(namespace, name, page, pageSize), nil)
resp, err := a.limitAwareDo(http.MethodGet, listReposPath(namespace, name, page, pageSize), nil)
if err != nil {
return nil, err
}
Expand All @@ -483,7 +484,7 @@ func (a *adapter) getRepos(namespace, name string, page, pageSize int) (*ReposRe

// getTags gets a page of tags for a repo from DockerHub
func (a *adapter) getTags(namespace, repo string, page, pageSize int) (*TagsResp, error) {
resp, err := a.limit_aware_http_do(http.MethodGet, listTagsPath(namespace, repo, page, pageSize), nil)
resp, err := a.limitAwareDo(http.MethodGet, listTagsPath(namespace, repo, page, pageSize), nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 97cce99

Please sign in to comment.