Skip to content

Commit 6ca2574

Browse files
committed
Enable adding an additional composer domain to auth.json.
Currently this is configurable through an environment variable.
1 parent 200d330 commit 6ca2574

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Build the image the same as before, passing a build `--secret`.
7373
**with-cloudsmith** desperately searches the following locations for credentials:
7474

7575
- Environment variables: `CLOUDSMITH_API_KEY`, `CLOUDSMITH_TOKEN`, `CLOUDSMITH_USER`, `CLOUDSMITH_PASSWORD`
76+
- Format Specific Environment Variables
77+
- Composer: `CLOUDSMITH_COMPOSER_ALT_DOMAIN`
7678
- Ini files: `$HOME/.cloudsmith/credentials.ini`, `$HOME/.config/credentials.ini`, `$PWD/credentials.ini`
7779
- Docker build secrets: `/run/secrets/CLOUDSMITH_API_KEY`, et al.
7880
- `/run/secrets/cloudsmith`: A special file that can either be your cloudsmith-cli credentials.ini or a source-able dotenv.

test/test.bats

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ create_osrelease() {
287287
[ -f $TMPDIR$HOME/.composer/auth.json ]
288288
}
289289

290+
@test "composer auth.json supports secondary domain" {
291+
export CLOUDSMITH_API_KEY="test-api-key"
292+
export CLOUDSMITH_COMPOSER_ALT_DOMAIN="example.com"
293+
run with-cloudsmith --composer --keep
294+
cat $TMPDIR$HOME/.composer/auth.json
295+
assert_success
296+
[ -f $TMPDIR$HOME/.composer/auth.json ]
297+
grep "example.com" $TMPDIR$HOME/.composer/auth.json
298+
}
299+
290300
@test "composer auth.json is cleaned up" {
291301
export CLOUDSMITH_API_KEY="test-api-key"
292302
run with-cloudsmith --composer

with-cloudsmith

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,19 @@ function setup_composer {
391391
"dl.cloudsmith.io": {
392392
"username": "$CLOUDSMITH_USER",
393393
"password": "$CLOUDSMITH_PASSWORD"
394+
EOF
395+
if [ -n "$CLOUDSMITH_COMPOSER_ALT_DOMAIN" ]; then
396+
cat >> "$auth_file" << EOF
394397
},
395-
"cloudsmith.secondlife.io": {
398+
"$CLOUDSMITH_COMPOSER_ALT_DOMAIN": {
396399
"username": "$CLOUDSMITH_USER",
397400
"password": "$CLOUDSMITH_PASSWORD"
401+
EOF
402+
fi
403+
404+
# Close the JSON object
405+
cat >> "$auth_file" << EOF
398406
}
399-
}
400407
}
401408
EOF
402409
}

0 commit comments

Comments
 (0)