Split container name and authUser.
continuous-integration/drone/push Build is passing Details

master
Thomas Bellembois 2 years ago
parent ab22c9b27d
commit 5028f127da

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"os" "os"
"strings"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
@ -80,11 +81,17 @@ func main() {
} }
if devel { if devel {
authUser = "thomasbellembois" authUser = "thomas.bellembois"
} else { } else {
authUser = os.Getenv("DRONE_REPO_OWNER") 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 { if len(authUser) == 0 {
fmt.Println("Not authenticated.") fmt.Println("Not authenticated.")
os.Exit(1) os.Exit(1)
@ -118,7 +125,7 @@ func exist() bool {
resp, err := client.R(). resp, err := client.R().
SetHeader("x-forwarded-user", authUser). 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -154,7 +161,7 @@ func logs() {
resp, err := client.R(). resp, err := client.R().
SetHeader("x-forwarded-user", authUser). 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -180,7 +187,7 @@ func start() {
resp, err := client.R(). resp, err := client.R().
SetHeader("x-forwarded-user", authUser). SetHeader("x-forwarded-user", authUser).
SetBody(container). 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -207,7 +214,7 @@ func create() {
resp, err := client.R(). resp, err := client.R().
SetHeader("x-forwarded-user", authUser). SetHeader("x-forwarded-user", authUser).
SetBody(container). 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -226,7 +233,7 @@ func delete(bypassError bool) {
resp, err := client.R(). resp, err := client.R().
SetHeader("x-forwarded-user", authUser). 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 { if err != nil {
fmt.Println(err) fmt.Println(err)

Loading…
Cancel
Save