Skip to content

Commit 4aca636

Browse files
authored
Merge pull request #12 from ft-circleci-orbs/default_settings
Extract Cloudsmith Org and Download Domains to Environment Variables
2 parents 61a82b4 + c11c129 commit 4aca636

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

.circleci/test-deploy.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ jobs:
3333
- run:
3434
name: Assert environment variables have been set
3535
command: |
36+
if [ $CLOUDSMITH_ORGANISATION != "financial-times" ]
37+
then
38+
echo "Test failed: CLOUDSMITH_ORGANISATION has not been set correctly."
39+
exit 1
40+
fi
3641
if [ $CLOUDSMITH_SERVICE_IDENTIFIER != "circleci-orb-testing" ]
3742
then
3843
echo "Test failed: CLOUDSMITH_SERVICE_IDENTIFIER has not been set."
@@ -56,6 +61,11 @@ jobs:
5661
- run:
5762
name: Assert environment variables have been set
5863
command: |
64+
if [ $CLOUDSMITH_DOWNLOADS_DOMAIN != "packages.ft.com" ]
65+
then
66+
echo "Test failed: CLOUDSMITH_DOWNLOADS_DOMAIN has not been set correctly."
67+
exit 1
68+
fi
5969
if [ -z $CLOUDSMITH_PIP_INDEX_URL ]
6070
then
6171
echo "Test failed: CLOUDSMITH_PIP_INDEX_URL has not been set."

src/commands/authenticate_with_oidc.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ parameters:
99
type: string
1010
steps:
1111
- run:
12-
name: Prepare script parameters
12+
name: Configure Cloudsmith organisation
1313
command: |
14-
echo "export CLOUDSMITH_SERVICE_IDENTIFIER=\"<<parameters.service_identifier>>\"" >> $BASH_ENV
14+
if [ -z "$CLOUDSMITH_ORGANISATION" ]
15+
then
16+
echo "export CLOUDSMITH_ORGANISATION=\"financial-times\"" >> "$BASH_ENV"
17+
fi
1518
- run:
16-
name: Authenticate with OIDC and generate a temporary OIDC token
19+
name: Configure Cloudsmith service account
20+
command: |
21+
echo "export CLOUDSMITH_SERVICE_IDENTIFIER=\"<<parameters.service_identifier>>\"" >> "$BASH_ENV"
22+
- run:
23+
name: Authenticate with OIDC
1724
command: <<include(scripts/authenticate_with_oidc.sh)>>

src/commands/set_env_vars_for_pip.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ steps:
1111
- authenticate_with_oidc:
1212
service_identifier: <<parameters.service_identifier>>
1313
- run:
14-
name: Prepare script parameters
14+
name: Configure Cloudsmith domains
15+
command: <<include(scripts/configure_cloudsmith_domains.sh)>>
16+
- run:
17+
name: Configure Cloudsmith repository
1518
command: |
1619
echo "export CLOUDSMITH_REPOSITORY_IDENTIFIER=\"<<parameters.repository_identifier>>\"" >> $BASH_ENV
20+
echo "CLOUDSMITH_REPOSITORY_IDENTIFIER=<<parameters.repository_identifier>>"
1721
- run:
1822
name: Set environment variables for pip
1923
command: <<include(scripts/set_env_vars_for_pip.sh)>>

src/scripts/authenticate_with_oidc.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55

66
set +e
77

8+
if [ -z "$CLOUDSMITH_ORGANISATION" ]
9+
then
10+
echo "Unable to generate OIDC token. Environment variable CLOUDSMITH_ORGANISATION is not set."
11+
exit 1
12+
fi
13+
814
if [ -z "$CLOUDSMITH_SERVICE_IDENTIFIER" ]
915
then
1016
echo "Unable to generate OIDC token. Environment variable CLOUDSMITH_SERVICE_IDENTIFIER is not set."
1117
exit 1
1218
fi
1319

14-
echo "Generating Cloudsmith OIDC token for service account: $CLOUDSMITH_SERVICE_IDENTIFIER"
20+
echo "Generating Cloudsmith OIDC token for service account: $CLOUDSMITH_ORGANISATION/$CLOUDSMITH_SERVICE_IDENTIFIER"
1521

1622
RESPONSE=$(curl -X POST -H "Content-Type: application/json" \
1723
-d "{\"oidc_token\":\"$CIRCLE_OIDC_TOKEN_V2\", \"service_slug\":\"$CLOUDSMITH_SERVICE_IDENTIFIER\"}" \
18-
--silent --show-error "https://api.cloudsmith.io/openid/financial-times/")
24+
--silent --show-error "https://api.cloudsmith.io/openid/$CLOUDSMITH_ORGANISATION/")
1925

2026
CLOUDSMITH_OIDC_TOKEN=$(echo "$RESPONSE" | grep -o '"token": "[^"]*' | grep -o '[^"]*$')
2127

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
if [ -z "$CLOUDSMITH_DOWNLOADS_DOMAIN" ]
4+
then
5+
echo "export CLOUDSMITH_DOWNLOADS_DOMAIN=\"packages.ft.com\"" >> "$BASH_ENV"
6+
fi
7+

src/scripts/set_env_vars_for_pip.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set +e
77

88
if [ -z "$CLOUDSMITH_SERVICE_IDENTIFIER" ] || [ -z "$CLOUDSMITH_OIDC_TOKEN" ]
99
then
10-
echo "Unable to find an OIDC token to use. Please ensure the authenticate-with-oidc command has been run before this command."
10+
echo "Unable to find an OIDC token to use. Please ensure the authenticate_with_oidc command has been run before this command."
1111
exit 1
1212
fi
1313

@@ -17,10 +17,17 @@ then
1717
exit 1
1818
fi
1919

20-
CLOUDSMITH_PIP_INDEX_URL="https://$CLOUDSMITH_SERVICE_IDENTIFIER:$CLOUDSMITH_OIDC_TOKEN@packages.ft.com/basic/$CLOUDSMITH_REPOSITORY_IDENTIFIER/python/simple/"
20+
if [ -z "$CLOUDSMITH_DOWNLOADS_DOMAIN" ]
21+
then
22+
echo "Unable to set environment variables for pip. Env var CLOUDSMITH_DOWNLOADS_DOMAIN is not defined."
23+
exit 1
24+
fi
25+
26+
27+
CLOUDSMITH_PIP_INDEX_URL="https://$CLOUDSMITH_SERVICE_IDENTIFIER:$CLOUDSMITH_OIDC_TOKEN@$CLOUDSMITH_DOWNLOADS_DOMAIN/basic/$CLOUDSMITH_REPOSITORY_IDENTIFIER/python/simple/"
2128

2229
echo "export CLOUDSMITH_PIP_INDEX_URL=\"$CLOUDSMITH_PIP_INDEX_URL\"" >> "$BASH_ENV"
2330

2431
echo "The following environment variables have been exported. Note, the OIDC token has been masked below."
2532
echo ""
26-
echo "CLOUDSMITH_PIP_INDEX_URL=https://$CLOUDSMITH_SERVICE_IDENTIFIER:********@packages.ft.com/basic/$CLOUDSMITH_REPOSITORY_IDENTIFIER/python/simple/"
33+
echo "CLOUDSMITH_PIP_INDEX_URL=https://$CLOUDSMITH_SERVICE_IDENTIFIER:********@$CLOUDSMITH_DOWNLOADS_DOMAIN/basic/$CLOUDSMITH_REPOSITORY_IDENTIFIER/python/simple/"

0 commit comments

Comments
 (0)