From 5028f127dad7e45833982e8ce280283114054aad Mon Sep 17 00:00:00 2001 From: Thomas Bellembois Date: Wed, 28 Dec 2022 19:05:45 +0100 Subject: [PATCH] Split container name and authUser. --- main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index cd22b04..464f478 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "strings" "github.com/go-resty/resty/v2" ) @@ -80,11 +81,17 @@ func main() { } if devel { - authUser = "thomasbellembois" + authUser = "thomas.bellembois" } else { authUser = os.Getenv("DRONE_REPO_OWNER") } + containerName = authUser + "-" + containerName + containerName = strings.ReplaceAll(containerName, ".", "") + + fmt.Printf("authUser: %s\n", authUser) + fmt.Printf("new containerName: %s\n", containerName) + if len(authUser) == 0 { fmt.Println("Not authenticated.") os.Exit(1) @@ -118,7 +125,7 @@ func exist() bool { resp, err := client.R(). SetHeader("x-forwarded-user", authUser). - Get(fmt.Sprintf("%s://%s/containers/%s/json", proxyScheme, proxyHost, authUser+"-"+containerName)) + Get(fmt.Sprintf("%s://%s/containers/%s/json", proxyScheme, proxyHost, containerName)) if err != nil { fmt.Println(err) @@ -154,7 +161,7 @@ func logs() { resp, err := client.R(). SetHeader("x-forwarded-user", authUser). - Get(fmt.Sprintf("%s://%s/containers/%s/logs", proxyScheme, proxyHost, authUser+"-"+containerName)) + Get(fmt.Sprintf("%s://%s/containers/%s/logs", proxyScheme, proxyHost, containerName)) if err != nil { fmt.Println(err) @@ -180,7 +187,7 @@ func start() { resp, err := client.R(). SetHeader("x-forwarded-user", authUser). SetBody(container). - Post(fmt.Sprintf("%s://%s/containers/%s/start", proxyScheme, proxyHost, authUser+"-"+containerName)) + Post(fmt.Sprintf("%s://%s/containers/%s/start", proxyScheme, proxyHost, containerName)) if err != nil { fmt.Println(err) @@ -207,7 +214,7 @@ func create() { resp, err := client.R(). SetHeader("x-forwarded-user", authUser). SetBody(container). - Post(fmt.Sprintf("%s://%s/containers/create/%s", proxyScheme, proxyHost, authUser+"-"+containerName)) + Post(fmt.Sprintf("%s://%s/containers/create/%s", proxyScheme, proxyHost, containerName)) if err != nil { fmt.Println(err) @@ -226,7 +233,7 @@ func delete(bypassError bool) { resp, err := client.R(). SetHeader("x-forwarded-user", authUser). - Delete(fmt.Sprintf("%s://%s/containers/%s", proxyScheme, proxyHost, authUser+"-"+containerName)) + Delete(fmt.Sprintf("%s://%s/containers/%s", proxyScheme, proxyHost, containerName)) if err != nil { fmt.Println(err)