You've already forked docker-hub-description-updater
Compare commits
1 Commits
master
...
0d505a3d60
Author | SHA1 | Date | |
---|---|---|---|
0d505a3d60
|
@ -26,4 +26,4 @@ jobs:
|
|||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
- uses: golangci/golangci-lint-action@v8.0.0
|
- uses: golangci/golangci-lint-action@v8.0.0
|
||||||
with:
|
with:
|
||||||
version: v2.4.0 # renovate: datasource=github-releases depName=golangci/golangci-lint
|
version: v2.3.1 # renovate: datasource=github-releases depName=golangci/golangci-lint
|
||||||
|
@ -26,7 +26,7 @@ jobs:
|
|||||||
GITEA_TOKEN: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }}
|
||||||
GONOSUMDB: ${{ vars.GONOSUMDB }}
|
GONOSUMDB: ${{ vars.GONOSUMDB }}
|
||||||
GOPROXY: ${{ vars.GOPROXY }}
|
GOPROXY: ${{ vars.GOPROXY }}
|
||||||
uses: goreleaser/goreleaser-action@v6.4.0
|
uses: goreleaser/goreleaser-action@v6.3.0
|
||||||
with:
|
with:
|
||||||
version: v2.11.2 # renovate: datasource=github-releases depName=goreleaser/goreleaser
|
version: v2.11.2 # renovate: datasource=github-releases depName=goreleaser/goreleaser
|
||||||
args: release --clean
|
args: release --clean
|
||||||
|
@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on:
|
runs-on:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.3.0
|
- uses: actions/checkout@v4.2.2
|
||||||
- uses: peter-evans/dockerhub-description@v4.0.2
|
- uses: peter-evans/dockerhub-description@v4.0.2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_IO_USERNAME }}
|
username: ${{ secrets.DOCKER_IO_USERNAME }}
|
||||||
|
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -58,8 +59,7 @@ func runE(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("can not find file: %v", file)
|
return fmt.Errorf("can not find file: %v", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #nosec G304
|
f, err := ioutil.ReadFile(file)
|
||||||
f, err := os.ReadFile(file)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can not read file %v: %v", file, err)
|
return fmt.Errorf("can not read file %v: %v", file, err)
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package hub
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errFailedToCreateRequest = errors.New("failed to create http request")
|
errorFailedToCreateRequest = errors.New("failed to create http request")
|
||||||
errFailedToParseJSON = errors.New("failed to parse json")
|
errorFailedToParseJSON = errors.New("failed to parse json")
|
||||||
errFailedToParseURL = errors.New("failed to parse url")
|
errorFailedToParseURL = errors.New("failed to parse url")
|
||||||
errFailedToSendRequest = errors.New("failed to send http request")
|
errorFailedToSendRequest = errors.New("failed to send http request")
|
||||||
errNoNamespaceDefined = errors.New("no Namespace defined")
|
errorNoNamespaceDefined = errors.New("no Namespace defined")
|
||||||
errNoRepositoryDefined = errors.New("no Repository defined")
|
errorNoRepositoryDefined = errors.New("no Repository defined")
|
||||||
errUnexpectedHTTPStatuscode = errors.New("unexpected HTTP-Statuscode")
|
errorUnexpectedHTTPStatuscode = errors.New("unexpected HTTP-Statuscode")
|
||||||
)
|
)
|
||||||
|
@ -25,22 +25,22 @@ type Hub struct {
|
|||||||
func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, error) {
|
func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, error) {
|
||||||
|
|
||||||
if len(namespace) <= 0 {
|
if len(namespace) <= 0 {
|
||||||
return nil, errNoNamespaceDefined
|
return nil, errorNoNamespaceDefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(name) <= 0 {
|
if len(name) <= 0 {
|
||||||
return nil, errNoRepositoryDefined
|
return nil, errorNoRepositoryDefined
|
||||||
}
|
}
|
||||||
|
|
||||||
rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, namespace, name)
|
rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, namespace, name)
|
||||||
url, err := url.Parse(rawURL)
|
url, err := url.Parse(rawURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToParseURL, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToParseURL, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
|
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.token == nil {
|
if h.token == nil {
|
||||||
@ -54,18 +54,18 @@ func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, e
|
|||||||
|
|
||||||
resp, err := h.client.Do(req)
|
resp, err := h.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToSendRequest, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToSendRequest, err)
|
||||||
}
|
}
|
||||||
defer func() { _ = resp.Body.Close() }()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("%v: expect %v, received %v", errUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
repository := new(types.Repository)
|
repository := new(types.Repository)
|
||||||
jsonDecoder := json.NewDecoder(resp.Body)
|
jsonDecoder := json.NewDecoder(resp.Body)
|
||||||
if err := jsonDecoder.Decode(repository); err != nil {
|
if err := jsonDecoder.Decode(repository); err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository, nil
|
return repository, nil
|
||||||
@ -75,30 +75,30 @@ func (h *Hub) getToken() (*types.Token, error) {
|
|||||||
loginBuffer := new(bytes.Buffer)
|
loginBuffer := new(bytes.Buffer)
|
||||||
jsonEncoder := json.NewEncoder(loginBuffer)
|
jsonEncoder := json.NewEncoder(loginBuffer)
|
||||||
if err := jsonEncoder.Encode(h.credentials); err != nil {
|
if err := jsonEncoder.Encode(h.credentials); err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rawURL := fmt.Sprintf("%v/users/login/", dockerHubAPI)
|
rawURL := fmt.Sprintf("%v/users/login/", dockerHubAPI)
|
||||||
req, err := http.NewRequest(http.MethodPost, rawURL, loginBuffer)
|
req, err := http.NewRequest(http.MethodPost, rawURL, loginBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||||
}
|
}
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
resp, err := h.client.Do(req)
|
resp, err := h.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||||
}
|
}
|
||||||
defer func() { _ = resp.Body.Close() }()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("%v: expect %v, received %v", errUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
token := new(types.Token)
|
token := new(types.Token)
|
||||||
jsonDecoder := json.NewDecoder(resp.Body)
|
jsonDecoder := json.NewDecoder(resp.Body)
|
||||||
if err := jsonDecoder.Decode(token); err != nil {
|
if err := jsonDecoder.Decode(token); err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return token, nil
|
return token, nil
|
||||||
@ -108,11 +108,11 @@ func (h *Hub) getToken() (*types.Token, error) {
|
|||||||
func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository, error) {
|
func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository, error) {
|
||||||
|
|
||||||
if len(repository.Namespcace) <= 0 {
|
if len(repository.Namespcace) <= 0 {
|
||||||
return nil, errNoNamespaceDefined
|
return nil, errorNoNamespaceDefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(repository.Name) <= 0 {
|
if len(repository.Name) <= 0 {
|
||||||
return nil, errNoRepositoryDefined
|
return nil, errorNoRepositoryDefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.token == nil {
|
if h.token == nil {
|
||||||
@ -127,7 +127,7 @@ func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository,
|
|||||||
rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, repository.Namespcace, repository.Name)
|
rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, repository.Namespcace, repository.Name)
|
||||||
patchURL, err := url.Parse(rawURL)
|
patchURL, err := url.Parse(rawURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToParseURL, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToParseURL, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := &url.Values{}
|
data := &url.Values{}
|
||||||
@ -136,24 +136,24 @@ func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository,
|
|||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPatch, patchURL.String(), nil)
|
req, err := http.NewRequest(http.MethodPatch, patchURL.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("JWT %v", h.token.Token))
|
req.Header.Set("Authorization", fmt.Sprintf("JWT %v", h.token.Token))
|
||||||
|
|
||||||
resp, err := h.client.Do(req)
|
resp, err := h.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||||
}
|
}
|
||||||
defer func() { _ = resp.Body.Close() }()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("%v: expect %v, received %v", errUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
patchedRepository := new(types.Repository)
|
patchedRepository := new(types.Repository)
|
||||||
jsonDecoder := json.NewDecoder(resp.Body)
|
jsonDecoder := json.NewDecoder(resp.Body)
|
||||||
if err := jsonDecoder.Decode(h.token); err != nil {
|
if err := jsonDecoder.Decode(h.token); err != nil {
|
||||||
return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
|
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchedRepository, nil
|
return patchedRepository, nil
|
||||||
|
Reference in New Issue
Block a user