Skip to content

Commit

Permalink
feat: update verifiable to digital credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
NithinKuruba committed Nov 2, 2023
1 parent 4f6ce37 commit 0880aaf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const async = require('async');

const STANDARD_REALM = 'standard';

const VC_REALM = 'verifiablecredential';
const DC_REALM = 'digitalcredential';

async function removeVcUsers(runnerName, pgClient, env = 'dev', callback) {
try {
let deletedUserCount = 0;
const adminClient = await getAdminClient(env);
const idpSuffix = '@verifiablecredential';
const idpSuffix = '@digitalcredential';
await pgClient.connect();
const text = 'INSERT INTO kc_deleted_vc_users (environment, username, realm_id, attributes) VALUES($1, $2, $3, $4)';
const text = 'INSERT INTO kc_deleted_dc_users (environment, username, realm_id, attributes) VALUES($1, $2, $3, $4)';
const max = 500;
let first = 0;
let total = 0;
Expand All @@ -32,14 +32,14 @@ async function removeVcUsers(runnerName, pgClient, env = 'dev', callback) {
await adminClient.users.del({ realm: STANDARD_REALM, id });

const parentRealmUsers = await adminClient.users.find({
realm: VC_REALM,
realm: DC_REALM,
username: username.split('@')[0],
max: 1
});

if (parentRealmUsers.length > 0) {
// delete user from verifiable credential realm
await adminClient.users.del({ realm: VC_REALM, id: parentRealmUsers[0]?.id });
// delete user from digital credential realm
await adminClient.users.del({ realm: DC_REALM, id: parentRealmUsers[0]?.id });
}

const values = [env, username, STANDARD_REALM, users[x].attributes || {}];
Expand Down Expand Up @@ -83,22 +83,22 @@ async function main() {
if (err) {
console.error(err.message);
await sendRcNotification(
'vc-remove-users',
`**[${process.env.NAMESPACE}] Failed to remove vc users** \n\n` + err.message,
'dc-remove-users',
`**[${process.env.NAMESPACE}] Failed to remove digital credential users** \n\n` + err.message,
true
);
} else {
const a = results.map((res) => JSON.stringify(res));
await sendRcNotification(
'vc-remove-users',
`**[${process.env.NAMESPACE}] Successfully removed vc users** \n\n` + a.join('\n\n'),
'dc-remove-users',
`**[${process.env.NAMESPACE}] Successfully removed digital credential users** \n\n` + a.join('\n\n'),
false
);
}
}
);

await deleteLegacyData('kc_deleted_vc_users', process.env.VC_USERS_RETENTION_DAYS || 60);
await deleteLegacyData('kc_deleted_dc_users', process.env.DC_USERS_RETENTION_DAYS || 60);
}

main();
2 changes: 1 addition & 1 deletion helm/kc-cron-job/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ kc-cron-job-secret:
--from-literal=bceid-service-id-test=${BCEID_SERVICE_ID_TEST} \
--from-literal=prod-kc-client-id=${PROD_KEYCLOAK_CLIENT_ID} \
--from-literal=rc-webhook=${RC_WEBHOOK} \
--from-literal=vc-users-retention-days=${VC_USERS_RETENTION_DAYS} \
--from-literal=dc-users-retention-days=${DC_USERS_RETENTION_DAYS} \
--from-literal=inactive-idir-users-retention-days=${INACTIVE_IDIR_USERS_RETENTION_DAYS} \
--from-literal=dev-kc-url=${DEV_KEYCLOAK_URL} \
--from-literal=test-kc-url=${TEST_KEYCLOAK_URL} \
Expand Down
2 changes: 1 addition & 1 deletion helm/kc-cron-job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export PGDATABASE=
export CSS_API_URL=http://localhost:8080/app
export CSS_API_AUTH_SECRET=
export RC_WEBHOOK=
export VC_USERS_RETENTION_DAYS=
export DC_USERS_RETENTION_DAYS=
export INACTIVE_IDIR_USERS_RETENTION_DAYS=

# update <namespace> and run to create the secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "..fullname" . }}-rm-vc-users
name: {{ include "..fullname" . }}-rm-dc-users
namespace: {{ .Values.namespace.rmVcUsers }}
labels:
app.kubernetes.io/name: {{ include "..name" . }}
Expand Down Expand Up @@ -31,7 +31,7 @@ spec:
set -euo pipefail;
echo "select 'create database $PGDATABASE' where NOT exists (select from pg_database where datname = '$PGDATABASE')\gexec" | psql -d postgres
psql -d $PGDATABASE -qtA --set ON_ERROR_STOP=1 <<EOF
create table if not exists public.kc_deleted_vc_users (
create table if not exists public.kc_deleted_dc_users (
id serial NOT NULL,
timestamp timestamp with time zone default current_timestamp,
environment varchar(50),
Expand Down Expand Up @@ -60,7 +60,7 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- node
- remove-vc-users.js
- remove-dc-users.js
env:
- name: RELEASE_REVISION
value: "{{ .Release.Revision }}"
Expand Down Expand Up @@ -127,11 +127,11 @@ spec:
secretKeyRef:
name: kc-cron-job-secret
key: rc-webhook
- name: VC_USERS_RETENTION_DAYS
- name: DC_USERS_RETENTION_DAYS
valueFrom:
secretKeyRef:
name: kc-cron-job-secret
key: vc-users-retention-days
key: dc-users-retention-days
- name: NAMESPACE
value: {{ .Values.namespace.rmVcUsers }}
restartPolicy: Never
Expand Down

0 comments on commit 0880aaf

Please sign in to comment.