diff --git a/docker-compose.yaml b/docker-compose.yaml index ae94f6b..048fcd7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,6 +11,12 @@ services: build: context: . dockerfile: Dockerfile + environment: + # Fill these in with your own tokens + - GITEA_REGISTRY_RO_TOKEN= + - GITEA_RW_PACKAGE_TOKEN= + - GITEA_ORG= + - GITEA_USER= networks: dcntrlized_net: diff --git a/src/handlers/registry/registry.go b/src/handlers/registry/registry.go index 02c7f6d..6753aee 100644 --- a/src/handlers/registry/registry.go +++ b/src/handlers/registry/registry.go @@ -4,11 +4,11 @@ import ( "encoding/json" "fmt" "net/http" + "os" "sort" "strings" "time" - "git.dcntrlized.org/Dcntrlized/Maestro/lib/consts" "git.dcntrlized.org/Dcntrlized/Maestro/lib/logger" "github.com/google/go-containerregistry/pkg/authn" @@ -42,7 +42,7 @@ type RawPackage struct { func GetRegistry(w http.ResponseWriter, r *http.Request) { // 1. Query Gitea REST API using the exact Org name - apiURL := fmt.Sprintf("https://git.dcntrlized.org/api/v1/packages/%s?type=container", consts.GITEA_ORG) + apiURL := fmt.Sprintf("https://git.dcntrlized.org/api/v1/packages/%s?type=container", os.Getenv("GITEA_ORG")) req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, apiURL, nil) if err != nil { @@ -51,7 +51,8 @@ func GetRegistry(w http.ResponseWriter, r *http.Request) { return } - req.Header.Set("Authorization", "token "+consts.GITEA_RW_PACKAGE_TOKEN) + logger.Debug(fmt.Sprintf("%s", os.Getenv("GITEA_RW_PACKAGE_TOKEN"))) + req.Header.Set("Authorization", "token "+os.Getenv("GITEA_RW_PACKAGE_TOKEN")) client := &http.Client{Timeout: 10 * time.Second} resp, err := client.Do(req) @@ -116,11 +117,11 @@ func GetRegistry(w http.ResponseWriter, r *http.Request) { } ociAuth := remote.WithAuth(&authn.Basic{ - Username: consts.GITEA_USER, - Password: consts.GITEA_RW_PACKAGE_TOKEN, + Username: os.Getenv("GITEA_USER"), + Password: os.Getenv("GITEA_RO_TOKEN"), }) - ociOrg := strings.ToLower(consts.GITEA_ORG) + ociOrg := strings.ToLower(os.Getenv("GITEA_ORG")) var registryItems []RegistryContainer // 4. Fetch OCI metadata only for the highest version of each package diff --git a/src/lib/consts/admin.go b/src/lib/consts/admin.go deleted file mode 100644 index dc8a49e..0000000 --- a/src/lib/consts/admin.go +++ /dev/null @@ -1,6 +0,0 @@ -package consts - -const GITEA_RO_TOKEN = "" -const GITEA_RW_PACKAGE_TOKEN = "" -const GITEA_ORG = "" -const GITEA_USER = ""