feat: implement os-based env variables instead of static code-based env variables
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package consts
|
||||
|
||||
const GITEA_RO_TOKEN = ""
|
||||
const GITEA_RW_PACKAGE_TOKEN = ""
|
||||
const GITEA_ORG = ""
|
||||
const GITEA_USER = ""
|
||||
Reference in New Issue
Block a user