diff --git a/.github/register_service_credential_in_primaza.sh b/.github/register_service_credential_in_primaza.sh index 286871cb..cabde37f 100755 --- a/.github/register_service_credential_in_primaza.sh +++ b/.github/register_service_credential_in_primaza.sh @@ -5,6 +5,7 @@ SERVICE_NAME=$2 USERNAME=$3 PASSWORD=$4 DATABASE_NAME=$5 +CREDENTIAL_TYPE=$6 PRIMAZA_KUBERNETES_NAMESPACE=sb POD_NAME=$(kubectl get pod -l app.kubernetes.io/name=primaza-app -n $PRIMAZA_KUBERNETES_NAMESPACE -o name) @@ -12,7 +13,7 @@ POD_NAME=$(kubectl get pod -l app.kubernetes.io/name=primaza-app -n $PRIMAZA_KUB SERVICE=$(kubectl exec -i $POD_NAME --container primaza-app -n $PRIMAZA_KUBERNETES_NAMESPACE -- sh -c "curl -H 'Accept: application/json' -s localhost:8080/services/name/$SERVICE_NAME") SERVICE_ID=$(echo "$SERVICE" | jq -r '.id') -BODY="name=$CREDENTIAL_NAME&serviceId=$SERVICE_ID&username=$USERNAME&password=$PASSWORD¶ms=database:$DATABASE_NAME" +BODY="name=$CREDENTIAL_NAME&type=$CREDENTIAL_TYPE&serviceId=$SERVICE_ID&username=$USERNAME&password=$PASSWORD¶ms=database:$DATABASE_NAME" echo "Sending service credential with body: $BODY" RESULT=$(kubectl exec -i $POD_NAME --container primaza-app -n $PRIMAZA_KUBERNETES_NAMESPACE -- sh -c "curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d '$BODY' -s -i localhost:8080/credentials") if [[ "$RESULT" = *"500 Internal Server Error"* ]] diff --git a/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml b/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml index e55b8417..ccc15b95 100644 --- a/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml +++ b/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml @@ -85,7 +85,7 @@ jobs: ./scripts/data/services.sh url=$PRIMAZA_URL service_name=activemq-artemis version=2.26 type=activemq endpoint=tcp:8161 ./scripts/data/services.sh url=$PRIMAZA_URL service_name=mariadb version=10.9 type=mariadb endpoint=tcp:3306 - ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits + ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_type=vault credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits - name: Installing Vault run: | diff --git a/.github/workflows/e2e-atomic-fruits-vault.yml b/.github/workflows/e2e-atomic-fruits-vault.yml index d600e989..c8b0f118 100644 --- a/.github/workflows/e2e-atomic-fruits-vault.yml +++ b/.github/workflows/e2e-atomic-fruits-vault.yml @@ -84,7 +84,7 @@ jobs: ./scripts/data/services.sh url=$PRIMAZA_URL service_name=activemq-artemis version=2.26 type=activemq endpoint=tcp:8161 ./scripts/data/services.sh url=$PRIMAZA_URL service_name=mariadb version=10.9 type=mariadb endpoint=tcp:3306 - ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits + ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_type=vault credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits - name: Installing Vault run: | diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 541ce438..4306a31b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -140,6 +140,7 @@ jobs: PASSWORD=superman TYPE=postgresql DATABASE_NAME=database + CREDENTIAL_TYPE=basic # First, we install Postgresql via Helm. helm repo add bitnami https://charts.bitnami.com/bitnami @@ -150,7 +151,7 @@ jobs: .github/register_service_in_primaza.sh postgresql 11 tcp:5432 $TYPE # We create the credentials for the PostgreSQL service recently registered - .github/register_service_credential_in_primaza.sh postgresql-credentials postgresql $USERNAME $PASSWORD $DATABASE_NAME + .github/register_service_credential_in_primaza.sh postgresql-credentials postgresql $USERNAME $PASSWORD $DATABASE_NAME $CREDENTIAL_TYPE - name: Register claim run: .github/register_claim_in_primaza.sh heroClaimDb postgresql-11 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e44ab76e..927b175d 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -147,6 +147,7 @@ jobs: PASSWORD=superman TYPE=postgresql DATABASE_NAME=database + CREDENTIAL_TYPE=basic # First, we install Postgresql via Helm. helm repo add bitnami https://charts.bitnami.com/bitnami @@ -157,7 +158,7 @@ jobs: .github/register_service_in_primaza.sh postgresql 11 tcp:5432 $TYPE # And finally the credentials - .github/register_service_credential_in_primaza.sh postgresql-credentials postgresql $USERNAME $PASSWORD $DATABASE_NAME + .github/register_service_credential_in_primaza.sh postgresql-credentials postgresql $USERNAME $PASSWORD $DATABASE_NAME $CREDENTIAL_TYPE - name: Register claim run: .github/register_claim_in_primaza.sh heroClaimDb postgresql-11 diff --git a/app/src/main/java/io/halkyon/model/Credential.java b/app/src/main/java/io/halkyon/model/Credential.java index f1f1b886..add7bede 100644 --- a/app/src/main/java/io/halkyon/model/Credential.java +++ b/app/src/main/java/io/halkyon/model/Credential.java @@ -38,6 +38,8 @@ public class Credential extends PanacheEntityBase { @JoinColumn(name = "service_id", nullable = false) public Service service; + public String type; + public String vaultKvPath; public String username; diff --git a/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java b/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java index 3caa5f8b..6731b0ce 100644 --- a/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java +++ b/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java @@ -16,6 +16,10 @@ public class CredentialRequest { @FormParam public String name; + @NotBlank + @FormParam + public String type; + @NotNull @FormParam public Long serviceId; diff --git a/app/src/main/java/io/halkyon/services/CredentialService.java b/app/src/main/java/io/halkyon/services/CredentialService.java index 533a2f0f..375987f2 100644 --- a/app/src/main/java/io/halkyon/services/CredentialService.java +++ b/app/src/main/java/io/halkyon/services/CredentialService.java @@ -59,6 +59,7 @@ private Credential mergeEntities(Credential old, Credential edited) { public Credential initializeCredential(CredentialRequest request) { Credential credential = new Credential(); credential.name = request.name; + credential.type = request.type; credential.username = request.username; credential.password = request.password; if (request.vaultKvPath != null) { diff --git a/app/src/main/resources/templates/credentials/form.html b/app/src/main/resources/templates/credentials/form.html index abc1a9b0..38a884f0 100644 --- a/app/src/main/resources/templates/credentials/form.html +++ b/app/src/main/resources/templates/credentials/form.html @@ -1,139 +1,202 @@ {@java.lang.Integer items} {#include base} - {#title}Credential{/title} - {#body} -
- {#if credential.id == null } -

New Credential

-
- {#else} -

Update Credential

- - {/if} - -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- - - - - - - - - - - - - - - - {#for param in credential.params} - - - - - - {/for} - -
NameValue
- - - - - -
{param.paramName}{param.paramValue} - - -
-
-
-
-
- -
-
-
-
-
- Back -
-
-
-
- - {/body} + // Attach the event listener to the select element + document.getElementById("credential_type").addEventListener("change", handleSelectChange); + + function addParameterRow() { + var nameInput = document.getElementById("new-param-name"); + var valueInput = document.getElementById("new-param-value"); + var table = document.getElementById("credential-params"); + + // hidden input for form + var formInput = document.createElement("input"); + formInput.type = "hidden"; + formInput.name = "params"; + formInput.value = nameInput.value + ":" + valueInput.value; + + // delete button + var button = document.createElement("button"); + button.setAttribute("class", "btn btn-secondary"); + button.type = "button"; + button.innerHTML = "Delete"; + button.setAttribute("onclick", "deleteParameterRow(this)"); + + var newRow = table.insertRow(-1); + var cell1 = newRow.insertCell(0); + var cell2 = newRow.insertCell(1); + var cell3 = newRow.insertCell(2); + cell1.innerHTML = nameInput.value; + cell2.innerHTML = valueInput.value; + cell3.appendChild(button); + cell3.appendChild(formInput); + + nameInput.value = ""; + valueInput.value = ""; + } + + function deleteParameterRow(row) { + var i = row.parentNode.parentNode.rowIndex; + document.getElementById("credential-params").deleteRow(i - 1); + } + + {/body} {/include} \ No newline at end of file diff --git a/app/src/main/resources/templates/credentials/item.html b/app/src/main/resources/templates/credentials/item.html index 2924f637..f12e054f 100644 --- a/app/src/main/resources/templates/credentials/item.html +++ b/app/src/main/resources/templates/credentials/item.html @@ -4,6 +4,7 @@ {credential.name} {credential.username} {credential.password} + {credential.vaultKvPath}