Skip to content

Commit 0e666bd

Browse files
BUILD-9877 code review
1 parent 285cf07 commit 0e666bd

File tree

3 files changed

+16
-74
lines changed

3 files changed

+16
-74
lines changed

config-pip/action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ runs:
7474
run: |
7575
echo "ARTIFACTORY_READER_ROLE=${ARTIFACTORY_READER_ROLE}" >> "$GITHUB_ENV"
7676
77-
- name: Fetch Artifactory credentials from Vault
77+
- uses: SonarSource/vault-action-wrapper@320bd31b03e5dacaac6be51bbbb15adf7caccc32 # 3.1.0
7878
id: secrets
79-
uses: SonarSource/vault-action-wrapper@320bd31b03e5dacaac6be51bbbb15adf7caccc32 # 3.1.0
8079
with:
8180
secrets: |
8281
development/artifactory/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_READER_ROLE }} username | ARTIFACTORY_USERNAME;
@@ -85,11 +84,9 @@ runs:
8584
- name: Run pip configuration script
8685
id: config
8786
shell: bash
88-
working-directory: ${{ inputs.working-directory }}
8987
env:
9088
# Use custom Artifactory URL if provided, otherwise construct from repox-url
91-
ARTIFACTORY_URL:
92-
${{ inputs.repox-artifactory-url != '' && inputs.repox-artifactory-url ||
89+
ARTIFACTORY_URL: ${{ inputs.repox-artifactory-url != '' && inputs.repox-artifactory-url ||
9390
format('{0}/artifactory', inputs.repox-url) }}
9491
ARTIFACTORY_USERNAME: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_USERNAME }}
9592
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}

config-pip/config.sh

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,29 @@
1111

1212
set -euo pipefail
1313

14-
# Validate required environment variables
15-
if [[ -z "${ARTIFACTORY_URL:-}" ]]; then
16-
echo "ERROR: ARTIFACTORY_URL is required" >&2
17-
exit 1
18-
fi
19-
20-
if [[ -z "${ARTIFACTORY_USERNAME:-}" ]]; then
21-
echo "ERROR: ARTIFACTORY_USERNAME is required" >&2
22-
exit 1
23-
fi
24-
25-
if [[ -z "${ARTIFACTORY_ACCESS_TOKEN:-}" ]]; then
26-
echo "ERROR: ARTIFACTORY_ACCESS_TOKEN is required" >&2
27-
exit 1
28-
fi
14+
: "${ARTIFACTORY_URL:?}" "${ARTIFACTORY_USERNAME:?}" "${ARTIFACTORY_ACCESS_TOKEN:?}"
2915

3016
configure_pip() {
3117
echo "Configuring pip to use Artifactory..."
3218

3319
# Extract the host from ARTIFACTORY_URL
3420
local repox_host="${ARTIFACTORY_URL#https://}"
3521
repox_host="${repox_host#http://}"
36-
3722
echo "Repox host: $repox_host"
3823

39-
# Create pip config directory
4024
mkdir -p "$HOME/.pip"
41-
42-
# Write pip configuration with Artifactory credentials
43-
cat > ~/.pip/pip.conf <<EOF
25+
cat > "${HOME}/.pip/pip.conf" <<EOF
4426
[global]
45-
index-url = https://$ARTIFACTORY_USERNAME:$ARTIFACTORY_ACCESS_TOKEN@$repox_host/api/pypi/sonarsource-pypi/simple
27+
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@$repox_host/api/pypi/sonarsource-pypi/simple
4628
EOF
47-
48-
echo "✓ pip configuration completed successfully"
49-
echo " Configuration file: ${HOME}/.pip/pip.conf"
50-
29+
echo "Configuration file: ${HOME}/.pip/pip.conf"
5130
return 0
5231
}
5332

5433
main() {
5534
echo "::group::Configure pip"
5635
configure_pip
5736
echo "::endgroup::"
58-
5937
return 0
6038
}
6139

spec/config-pip_spec.sh

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export ARTIFACTORY_ACCESS_TOKEN="test-token"
1111

1212
# Expected output messages
1313
MESSAGE_CONFIGURING_PIP="Configuring pip to use Artifactory..."
14-
MESSAGE_PIP_CONFIGURATION_SUCCESS="✓ pip configuration completed successfully"
1514
MESSAGE_REPOX_HOST="Repox host: repox.jfrog.io/artifactory"
1615

1716
Describe 'config-pip/config.sh'
@@ -45,13 +44,12 @@ Describe 'configure_pip()'
4544
It 'creates pip config directory, file and correct content'
4645
When call configure_pip
4746
The status should be success
48-
The lines of output should equal 4
47+
The lines of output should equal 3
4948
The lines of error should equal 0
5049
The line 1 should equal "$MESSAGE_CONFIGURING_PIP"
5150
The line 2 should equal "$MESSAGE_REPOX_HOST"
52-
The line 3 should equal "$MESSAGE_PIP_CONFIGURATION_SUCCESS"
53-
The line 4 should start with " Configuration file: "
54-
The line 4 should end with "/.pip/pip.conf"
51+
The line 3 should start with "Configuration file: "
52+
The line 3 should end with "/.pip/pip.conf"
5553
The path "${HOME}/.pip" should be directory
5654
The path "${HOME}/.pip/pip.conf" should be file
5755
The contents of file "${HOME}/.pip/pip.conf" should equal "[global]
@@ -62,47 +60,17 @@ index-url = https://test-user:[email protected]/artifactory/api/pypi/son
6260
export ARTIFACTORY_URL="https://repox.jfrog.io:8080/artifactory"
6361
When call configure_pip
6462
The status should be success
65-
The lines of output should equal 4
63+
The lines of output should equal 3
6664
The lines of error should equal 0
6765
The line 1 should equal "$MESSAGE_CONFIGURING_PIP"
6866
The line 2 should equal "Repox host: repox.jfrog.io:8080/artifactory"
69-
The line 3 should equal "$MESSAGE_PIP_CONFIGURATION_SUCCESS"
70-
The line 4 should start with " Configuration file: "
71-
The line 4 should end with "/.pip/pip.conf"
67+
The line 3 should start with "Configuration file: "
68+
The line 3 should end with "/.pip/pip.conf"
7269
The contents of file "${HOME}/.pip/pip.conf" should equal "[global]
7370
index-url = https://test-user:[email protected]:8080/artifactory/api/pypi/sonarsource-pypi/simple"
7471
End
7572
End
7673

77-
Describe 'Environment variable validation'
78-
It 'fails when ARTIFACTORY_URL is not set'
79-
unset ARTIFACTORY_URL
80-
When run script config-pip/config.sh
81-
The status should be failure
82-
The lines of output should equal 0
83-
The lines of error should equal 1
84-
The error should equal "ERROR: ARTIFACTORY_URL is required"
85-
End
86-
87-
It 'fails when ARTIFACTORY_USERNAME is not set'
88-
unset ARTIFACTORY_USERNAME
89-
When run script config-pip/config.sh
90-
The status should be failure
91-
The lines of output should equal 0
92-
The lines of error should equal 1
93-
The error should equal "ERROR: ARTIFACTORY_USERNAME is required"
94-
End
95-
96-
It 'fails when ARTIFACTORY_ACCESS_TOKEN is not set'
97-
unset ARTIFACTORY_ACCESS_TOKEN
98-
When run script config-pip/config.sh
99-
The status should be failure
100-
The lines of output should equal 0
101-
The lines of error should equal 1
102-
The error should equal "ERROR: ARTIFACTORY_ACCESS_TOKEN is required"
103-
End
104-
End
105-
10674
Describe 'main()'
10775
BeforeEach 'common_setup'
10876
AfterEach 'common_cleanup'
@@ -112,15 +80,14 @@ Describe 'main()'
11280
export ARTIFACTORY_ACCESS_TOKEN="my-secret-token"
11381
When run script config-pip/config.sh
11482
The status should be success
115-
The lines of output should equal 6
83+
The lines of output should equal 5
11684
The lines of error should equal 0
11785
The line 1 should equal "::group::Configure pip"
11886
The line 2 should equal "$MESSAGE_CONFIGURING_PIP"
11987
The line 3 should equal "$MESSAGE_REPOX_HOST"
120-
The line 4 should equal "$MESSAGE_PIP_CONFIGURATION_SUCCESS"
121-
The line 5 should start with " Configuration file: "
122-
The line 5 should end with "/.pip/pip.conf"
123-
The line 6 should equal "::endgroup::"
88+
The line 4 should start with "Configuration file: "
89+
The line 4 should end with "/.pip/pip.conf"
90+
The line 5 should equal "::endgroup::"
12491
The path "${HOME}/.pip/pip.conf" should be file
12592
The contents of file "${HOME}/.pip/pip.conf" should equal "[global]
12693
index-url = https://my-user:[email protected]/artifactory/api/pypi/sonarsource-pypi/simple"

0 commit comments

Comments
 (0)