Skip to content

Commit 1fb387f

Browse files
authored
Merge pull request #1381 from credebl/develop
merge: DEV to QA
2 parents 97af95a + 732ac88 commit 1fb387f

File tree

22 files changed

+568
-893
lines changed

22 files changed

+568
-893
lines changed

.env.demo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ HOSTNAME='localhost'
161161
# To add more clients, simply add comma separated values of client names
162162
SUPPORTED_SSO_CLIENTS=CREDEBL
163163

164+
# Key for agent base wallet
165+
AGENT_API_KEY='supersecret-that-too-16chars'
166+
164167
# To add more client add the following variables for each additional client.
165168
# Replace the `CLIENT-NAME` with the appropriate client name as added in `SUPPORTED_SSO_CLIENTS`
166169
# Default client will not need the following details

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ HOSTNAME='localhost' # Hostname or unique identifier
181181
# To add more clients, simply add comma separated values of client names
182182
SUPPORTED_SSO_CLIENTS=CREDEBL
183183

184+
# Key for agent base wallet
185+
AGENT_API_KEY='supersecret-that-too-16chars'
186+
184187
# To add more client add the following variables for each additional client.
185188
# Replace the `CLIENT-NAME` with the appropriate client name as added in `SUPPORTED_SSO_CLIENTS`
186189
# Default client will not need the following details

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ module.exports = {
101101
'prefer-template': 'error',
102102
quotes: ['warn', 'single', { allowTemplateLiterals: true }]
103103
}
104-
};
104+
};

.github/dco.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
allowRemediationCommits:
2+
individual: true
3+
thirdParty: true

.github/workflows/continuous-delivery.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ jobs:
4444
id: get_tag
4545
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
4646

47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v3
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
4753
- name: Log in to GitHub Container Registry
4854
uses: docker/login-action@v3
4955
with:
@@ -57,6 +63,7 @@ jobs:
5763
context: .
5864
file: Dockerfiles/Dockerfile.${{ matrix.service }}
5965
push: true
66+
platforms: linux/amd64,linux/arm64
6067
tags: |
6168
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.service }}:${{ env.TAG }}
62-
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.service }}:latest
69+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.service }}:latest

apps/agent-provisioning/AFJ/scripts/start_agent.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ AFJ_VERSION=${14}
1919
INDY_LEDGER=${15}
2020
INBOUND_ENDPOINT=${16}
2121
SCHEMA_FILE_SERVER_URL=${17}
22-
22+
AGENT_API_KEY="${18}"
2323
ADMIN_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-admin-port.txt"
2424
INBOUND_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-inbound-port.txt"
2525
ADMIN_PORT=8001
@@ -122,7 +122,7 @@ if [ -f "$CONFIG_FILE" ]; then
122122
rm "$CONFIG_FILE"
123123
fi
124124

125-
cat <<EOF >${CONFIG_FILE}
125+
cat <<EOF >"$CONFIG_FILE"
126126
{
127127
"label": "${AGENCY}_${CONTAINER_NAME}",
128128
"walletId": "$WALLET_NAME",
@@ -154,7 +154,8 @@ cat <<EOF >${CONFIG_FILE}
154154
"webhookUrl": "$WEBHOOK_HOST/wh/$AGENCY",
155155
"adminPort": $ADMIN_PORT,
156156
"tenancy": $TENANT,
157-
"schemaFileServerURL": "$SCHEMA_FILE_SERVER_URL"
157+
"schemaFileServerURL": "$SCHEMA_FILE_SERVER_URL",
158+
"apiKey": "$AGENT_API_KEY"
158159
}
159160
EOF
160161

@@ -238,7 +239,7 @@ if [ $? -eq 0 ]; then
238239
container_logs=$(docker logs $(docker ps -q --filter "name=${AGENCY}_${CONTAINER_NAME}"))
239240

240241
# Extract the token from the logs using sed
241-
token=$(echo "$container_logs" | sed -nE 's/.*API Token: ([^ ]+).*/\1/p')
242+
token=$(echo "$container_logs" | sed -nE 's/.*** API Key: ([^ ]+).*/\1/p')
242243

243244
# Print the extracted token
244245
echo "Token: $token"

apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ random_string=$(generate_random_string)
3737
# Print the generated random string
3838
echo "Random String: $random_string"
3939

40-
SERVICE_NAME="${AGENCY}-${CONTAINER_NAME}-service-${random_string}"
40+
SERVICE_NAME="${CONTAINER_NAME}-service-test"
4141
EXTERNAL_IP=$(echo "$2" | tr -d '[:space:]')
4242
ADMIN_PORT_FILE="$PWD/agent-provisioning/AFJ/port-file/last-admin-port.txt"
4343
INBOUND_PORT_FILE="$PWD/agent-provisioning/AFJ/port-file/last-inbound-port.txt"
@@ -153,7 +153,7 @@ CONTAINER_DEFINITIONS=$(
153153
[
154154
{
155155
"name": "$CONTAINER_NAME",
156-
"image": "${AFJ_IMAGE_URL}",
156+
"image": "${AFJ_VERSION}",
157157
"cpu": 154,
158158
"memory": 307,
159159
"portMappings": [
@@ -194,6 +194,14 @@ CONTAINER_DEFINITIONS=$(
194194
}
195195
],
196196
"volumesFrom": [],
197+
"logConfiguration": {
198+
"logDriver": "awslogs",
199+
"options": {
200+
"awslogs-group": "/ecs/$TESKDEFINITION_FAMILY",
201+
"awslogs-create-group": "true",
202+
"awslogs-region": "ap-south-1",
203+
"awslogs-stream-prefix": "ecs"
204+
},
197205
"ulimits": []
198206
}
199207
]
@@ -262,6 +270,67 @@ if [ $? -eq 0 ]; then
262270
sleep 10
263271
fi
264272
done
273+
# Describe the ECS service and filter by service name
274+
service_description=$(aws ecs describe-services --service $SERVICE_NAME --cluster $CLUSTER_NAME --region $AWS_PUBLIC_REGION)
275+
echo "service_description=$service_description"
276+
277+
278+
# Extract Task ID from the service description events
279+
task_id=$(echo "$service_description" | jq -r '.services[0].events[] | select(.message | test("has started 1 tasks")) | .message | capture("\\(task (?<id>[^)]+)\\)") | .id')
280+
#echo "task_id=$task_id"
281+
282+
# to fetch log group of container
283+
.............................................................
284+
log_group=/ecs/$TESKDEFINITION_FAMILY
285+
echo "log_group=$log_group"
286+
287+
# Get Log Stream Name
288+
log_stream=ecs/$CONTAINER_NAME/$task_id
289+
290+
echo "logstrem=$log_stream"
291+
292+
293+
# Fetch logs
294+
#echo "$(aws logs get-log-events --log-group-name "/ecs/$TESKDEFINITION_FAMILY/$CONTAINER_NAME" --log-stream-name "$log_stream" --region $AWS_PUBLIC_REGION)"
295+
296+
# Check if the token folder exists, and create it if it doesn't
297+
token_folder="$PWD/agent-provisioning/AFJ/token"
298+
if [ ! -d "$token_folder" ]; then
299+
mkdir -p "$token_folder"
300+
fi
301+
302+
# Set maximum retry attempts
303+
RETRIES=3
304+
305+
# Loop to attempt retrieving token from logs
306+
# Loop to attempt retrieving token from logs
307+
for attempt in $(seq 1 $RETRIES); do
308+
echo "Attempt $attempt: Checking service logs for token..."
309+
310+
# Fetch logs and grep for API token
311+
token=$(aws logs get-log-events \
312+
--log-group-name "$log_group" \
313+
--log-stream-name "$log_stream" \
314+
--region ap-southeast-1 \
315+
| grep -o '*** API Key: [^ ]*' \
316+
| cut -d ' ' -f 3
317+
)
318+
# echo "token=$token"
319+
if [ -n "$token" ]; then
320+
echo "Token found: $token"
321+
# Write token to a file
322+
echo "{\"token\": \"$token\"}" > "$PWD/agent-provisioning/AFJ/token/${AGENCY}_${CONTAINER_NAME}.json"
323+
break # Exit loop if token is found
324+
else
325+
echo "Token not found in logs. Retrying..."
326+
if [ $attempt -eq $RETRIES ]; then
327+
echo "Reached maximum retry attempts. Token not found."
328+
fi
329+
fi
330+
# Add a delay of 10 seconds between retries
331+
sleep 10
332+
done
333+
265334

266335
echo "Creating agent config"
267336
cat <<EOF >${PWD}/agent-provisioning/AFJ/endpoints/${AGENCY}_${CONTAINER_NAME}.json
@@ -273,7 +342,7 @@ EOF
273342

274343
cat <<EOF >${PWD}/agent-provisioning/AFJ/token/${AGENCY}_${CONTAINER_NAME}.json
275344
{
276-
"token" : ""
345+
"token" : "$token"
277346
}
278347
EOF
279348

apps/agent-provisioning/src/agent-provisioning.service.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,39 @@ dotenv.config();
99

1010
@Injectable()
1111
export class AgentProvisioningService {
12-
13-
constructor(
14-
private readonly logger: Logger
15-
) { }
12+
constructor(private readonly logger: Logger) {}
1613

1714
/**
1815
* Description: Wallet provision
19-
* @param payload
16+
* @param payload
2017
* @returns Get DID and verkey
2118
*/
2219
async walletProvision(payload: IWalletProvision): Promise<object> {
2320
try {
24-
25-
const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, credoImage, tenant, indyLedger, inboundEndpoint } = payload;
21+
const {
22+
containerName,
23+
externalIp,
24+
orgId,
25+
seed,
26+
walletName,
27+
walletPassword,
28+
walletStorageHost,
29+
walletStoragePassword,
30+
walletStoragePort,
31+
walletStorageUser,
32+
webhookEndpoint,
33+
agentType,
34+
protocol,
35+
credoImage,
36+
tenant,
37+
indyLedger,
38+
inboundEndpoint,
39+
apiKey
40+
} = payload;
2641
if (agentType === AgentType.AFJ) {
2742
// The wallet provision command is used to invoke a shell script
28-
const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${credoImage} "${indyLedger}" ${inboundEndpoint} ${process.env.SCHEMA_FILE_SERVER_URL} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN} ${process.env.CLUSTER_NAME} ${process.env.TESKDEFINITION_FAMILY}`;
43+
const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${credoImage} "${indyLedger}" ${inboundEndpoint} ${process.env.SCHEMA_FILE_SERVER_URL} ${apiKey} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN} ${process.env.CLUSTER_NAME} ${process.env.TESKDEFINITION_FAMILY}`;
2944
const spinUpResponse: object = new Promise(async (resolve) => {
30-
3145
await exec(walletProvision, async (err, stdout, stderr) => {
3246
this.logger.log(`shell script output: ${stdout}`);
3347
if (stderr) {

0 commit comments

Comments
 (0)