Supports both basicAuth & Token

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau
2021-09-10 11:13:10 +02:00
committed by Sam Alba
parent d34200c9f6
commit 05b165bcc8
5 changed files with 120 additions and 91 deletions

View File

@@ -18,11 +18,17 @@ import (
// ArgoCD project
project: *"default" | dagger.#Input & {string}
// Username
username: dagger.#Input & {string}
// Basic authentification to login
basicAuth: {
// Username
username: dagger.#Input & {string}
// Password
password: dagger.#Input & {dagger.#Secret}
// Password
password: dagger.#Input & {dagger.#Secret}
} | *null
// ArgoCD authentication token
token: dagger.#Input & {*null | dagger.#Secret}
}
// Re-usable CLI component
@@ -49,17 +55,45 @@ import (
env: VERSION: config.version
},
// Login to ArgoCD server
op.#Exec & {
args: ["sh", "-c", #"""
argocd login "$ARGO_SERVER" --username "$ARGO_USERNAME" --password $(cat /run/secrets/password) --insecure
"""#,
]
env: {
ARGO_SERVER: config.server
ARGO_USERNAME: config.username
if config.basicAuth != null && config.token == null {
// Login to ArgoCD server
op.#Exec & {
args: ["sh", "-c", #"""
argocd login "$ARGO_SERVER" --username "$ARGO_USERNAME" --password $(cat /run/secrets/password) --insecure
"""#,
]
env: {
ARGO_SERVER: config.server
ARGO_USERNAME: config.basicAuth.username
}
mount: "/run/secrets/password": secret: config.basicAuth.password
}
mount: "/run/secrets/password": secret: config.password
},
if config.token != null && config.basicAuth == null {
// Write config file
op.#Exec & {
args: ["sh", "-c",
#"""
mkdir -p ~/.argocd && cat > ~/.argocd/config << EOF
contexts:
- name: "$SERVER"
server: "$SERVER"
user: "$SERVER"
current-context: "$SERVER"
servers:
- grpc-web-root-path: ""
server: "$SERVER"
users:
- auth-token: $(cat /run/secrets/token)
name: "$SERVER"
EOF
"""#,
]
mount: "/run/secrets/token": secret: config.token
env: SERVER: config.server
}
},
]
}

View File

@@ -6,10 +6,12 @@ import (
)
TestConfig: argocdConfig: #Config & {
version: dagger.#Input & {*"v2.0.5" | string}
server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string}
username: dagger.#Input & {*"admin" | string}
password: dagger.#Input & {dagger.#Secret}
version: dagger.#Input & {*"v2.0.5" | string}
server: dagger.#Input & {*"dagger-example-argocd-server.tld" | string}
basicAuth: {
username: dagger.#Input & {*"admin" | string}
password: dagger.#Input & {dagger.#Secret}
}
}
TestClient: os.#Container & {
@@ -19,7 +21,7 @@ TestClient: os.#Container & {
command: #"""
argocd account list | grep "$ARGOCD_USERNAME"
"""#
env: ARGOCD_USERNAME: TestConfig.argocdConfig.username
env: ARGOCD_USERNAME: TestConfig.argocdConfig.basicAuth.username
}
TestApp: #App & {