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

@ -16,28 +16,26 @@ Create an ArgoCD application
### argocd.#App Inputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.username* | `string` |Username |
|*config.password* | `dagger.#Secret` |Password |
|*name* | `string` |App name |
|*repo* | `string` |Repository url (git or helm) |
|*path* | `string` |Folder to deploy |
|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server |
|*namespace* | `*"default" \| string` |Destination namespace |
|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*ctr.image.config.server* | `string` |ArgoCD server |
|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project |
|*ctr.image.config.username* | `string` |Username |
|*ctr.image.config.password* | `dagger.#Secret` |Password |
|*ctr.env.APP_NAME* | `string` |- |
|*ctr.env.APP_REPO* | `string` |- |
|*ctr.env.APP_PATH* | `string` |- |
|*ctr.env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- |
|*ctr.env.APP_NAMESPACE* | `*"default" \| string` |- |
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.token* | `dagger.#Secret` |ArgoCD authentication token |
|*name* | `string` |App name |
|*repo* | `string` |Repository url (git or helm) |
|*path* | `string` |Folder to deploy |
|*server* | `*"https://kubernetes.default.svc" \| string` |Destination server |
|*namespace* | `*"default" \| string` |Destination namespace |
|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*ctr.image.config.server* | `string` |ArgoCD server |
|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project |
|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token |
|*ctr.env.APP_NAME* | `string` |- |
|*ctr.env.APP_REPO* | `string` |- |
|*ctr.env.APP_PATH* | `string` |- |
|*ctr.env.APP_SERVER* | `*"https://kubernetes.default.svc" \| string` |- |
|*ctr.env.APP_NAMESPACE* | `*"default" \| string` |- |
### argocd.#App Outputs
@ -49,13 +47,12 @@ Re-usable CLI component
### argocd.#CLI Inputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.username* | `string` |Username |
|*config.password* | `dagger.#Secret` |Password |
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.token* | `dagger.#Secret` |ArgoCD authentication token |
### argocd.#CLI Outputs
@ -67,13 +64,12 @@ ArgoCD configuration
### argocd.#Config Inputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*server* | `string` |ArgoCD server |
|*project* | `*"default" \| string` |ArgoCD project |
|*username* | `string` |Username |
|*password* | `dagger.#Secret` |Password |
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*server* | `string` |ArgoCD server |
|*project* | `*"default" \| string` |ArgoCD project |
|*token* | `dagger.#Secret` |ArgoCD authentication token |
### argocd.#Config Outputs
@ -85,14 +81,13 @@ Get application's status
### argocd.#Status Inputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.username* | `string` |Username |
|*config.password* | `dagger.#Secret` |Password |
|*name* | `string` |ArgoCD application |
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.token* | `dagger.#Secret` |ArgoCD authentication token |
|*name* | `string` |ArgoCD application |
### argocd.#Status Outputs
@ -111,21 +106,19 @@ Sync an application to its targer state
### argocd.#Sync Inputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.username* | `string` |Username |
|*config.password* | `dagger.#Secret` |Password |
|*application* | `string` |ArgoCD application |
|*wait* | `*false \| bool` |Wait the application to sync correctly |
|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*ctr.image.config.server* | `string` |ArgoCD server |
|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project |
|*ctr.image.config.username* | `string` |Username |
|*ctr.image.config.password* | `dagger.#Secret` |Password |
|*ctr.env.APPLICATION* | `string` |- |
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*config.server* | `string` |ArgoCD server |
|*config.project* | `*"default" \| string` |ArgoCD project |
|*config.token* | `dagger.#Secret` |ArgoCD authentication token |
|*application* | `string` |ArgoCD application |
|*wait* | `*false \| bool` |Wait the application to sync correctly |
|*ctr.image.config.version* | `*"v2.0.5" \| string` |ArgoCD CLI binary version |
|*ctr.image.config.server* | `string` |ArgoCD server |
|*ctr.image.config.project* | `*"default" \| string` |ArgoCD project |
|*ctr.image.config.token* | `dagger.#Secret` |ArgoCD authentication token |
|*ctr.env.APPLICATION* | `string` |- |
### argocd.#Sync Outputs

View File

@ -13,14 +13,14 @@ sops:
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBuV3FTdWpWRjUxSS9hcVU4
T094TC9GRkcxQThPMVI3NzVCb2d3Q2cvUFRvClVHT1J6OFRVY1ZTYWQ2eDZmWXN3
N1VjdC9WNnlBNzRIdFVBN0E4Zm0xUzAKLS0tIEc2VFFSYmRqYUI5VDBDRGtTK2k1
WG5JdHlKYUlnZnZlMVNIRjczSld5ek0KF0z0UqtoGcYFFeOyMwIDAY1pyKosaOii
IVqsMSYfj4+vz7mRd8HoXoSiSnuc7mLJek/izsdZtYUTfD/QnTC71Q==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBhZEhvaGFiVGVUcWZhcjVj
WmthWWRMMmFXSmRIbzNKUm9IMms0TUltcjBvClE4UHlwcHVGcjVJTHRhNUx1Lyt4
UHZlTlBRRnhtMmMzcmFPUGlBTXlVMncKLS0tIFpkSXU1SDUvZTR4MVgxNWxKV3V3
LzM4MENHSVZFNVJza3FhVGkyd0R4d3cKPI6V2o1BR8WVrsAdsuuKOW9Lw32c+KUh
WBHXbYucWjPeogNVIZK+/iJs4Pz92fQ1awdj0H47ro3d7I3QfZoeJQ==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2021-09-09T12:42:58Z"
mac: ENC[AES256_GCM,data:CMNfY3kBAbDOkyh1s3csD7uGToV/5TubN/0z3NaG0rVOeHzgPx//PUw7jfhBe3iTCe5m7z5jpGwbI9h6+GoANrsPX887/XYvC22JLQ7vqfOqJYOrYY9YbEJnYK+GXthQB7bqn5Yh2+yiNRVk9vHJkXyhqea9/ud32kiKhG2tE3o=,iv:eT3sjgmh4NF1sS+MSsOEZbgvAiWOwep72aM2fDenG0s=,tag:HcKVlnDpn6kQxFdlKSCALg==,type:str]
lastmodified: "2021-09-10T09:08:35Z"
mac: ENC[AES256_GCM,data:RhRtuEL1xqfJ8pvofq91JMKElZY4Pqvb3SY3IhVevotGBAR6UvmKBA6Nfi3VsvbjfAlbA8/Ip+ifHNhuv6iS1kcj+u5Y7E+6esMdXoXlPmry1Jpt8fWu+zeO2t2XiVGsSEw8nLhPyZfMsp0KBoec1I43NUIKQXoPMbUFMMy1rLQ=,iv:Q817XyIlU/0BgUc6tNVZ8f9cz83I/3FbF8wvqaWNtso=,tag:/Ui9/AAT4RnnwfrOw83xew==,type:str]
pgp: []
encrypted_suffix: secret
version: 3.7.1

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 & {

View File

@ -223,15 +223,15 @@ setup() {
dagger -e argocd-infra up
# Forward port
# We need to kill subprocess to avoid infinity loop
kubectl port-forward svc/argocd-server -n argocd 8080:443 >/dev/null 2>/dev/null &
sleep 3
sleep 3 || (pkill kubectl && exit 1)
# Run test
dagger -e argocd input secret TestConfig.argocdConfig.password "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)"
dagger -e up
dagger -e argocd input unset TestConfig.argocdConfig.password
dagger -e argocd input secret TestConfig.argocdConfig.basicAuth.password "$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)" || (pkill kubectl && exit 1)
dagger -e argocd up || (pkill kubectl && exit 1)
dagger -e argocd input unset TestConfig.argocdConfig.basicAuth.password || (pkill kubectl && exit 1)
# Kill Pid
pkill kubectl
pgrep kubectl && pkill kubectl
}