Skip to content

Commit

Permalink
Merge pull request #404 from halkyonio/add-credential-type
Browse files Browse the repository at this point in the history
Issue-403
  • Loading branch information
aureamunoz authored Sep 27, 2023
2 parents 70dc27b + 6701ff8 commit 9116132
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 161 deletions.
3 changes: 2 additions & 1 deletion .github/register_service_credential_in_primaza.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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)

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&params=database:$DATABASE_NAME"
BODY="name=$CREDENTIAL_NAME&type=$CREDENTIAL_TYPE&serviceId=$SERVICE_ID&username=$USERNAME&password=$PASSWORD&params=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"* ]]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-atomic-fruits-vault-crossplane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-atomic-fruits-vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/halkyon/model/Credential.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class CredentialRequest {
@FormParam
public String name;

@NotBlank
@FormParam
public String type;

@NotNull
@FormParam
public Long serviceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 9116132

Please sign in to comment.