Skip to content

Commit

Permalink
feat(composer): custom gitlab host auth (#8612)
Browse files Browse the repository at this point in the history
Generates the COMPOSER_AUTH env variable for all gitlab host rules
  • Loading branch information
cjose3 committed May 6, 2021
1 parent c9c961c commit e49213a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/manager/composer/__snapshots__/artifacts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Array [
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
"env": Object {
"COMPOSER_AUTH": "{\\"github-oauth\\":{\\"github.com\\":\\"github-token\\"},\\"gitlab-token\\":{\\"gitlab.com\\":\\"gitlab-token\\"},\\"http-basic\\":{\\"packagist.renovatebot.com\\":{\\"username\\":\\"some-username\\",\\"password\\":\\"some-password\\"},\\"artifactory.yyyyyyy.com\\":{\\"username\\":\\"some-other-username\\",\\"password\\":\\"some-other-password\\"}}}",
"COMPOSER_AUTH": "{\\"github-oauth\\":{\\"github.com\\":\\"github-token\\"},\\"gitlab-token\\":{\\"gitlab.com\\":\\"gitlab-token\\"},\\"gitlab-domains\\":[\\"gitlab.com\\"],\\"http-basic\\":{\\"packagist.renovatebot.com\\":{\\"username\\":\\"some-username\\",\\"password\\":\\"some-password\\"},\\"artifactory.yyyyyyy.com\\":{\\"username\\":\\"some-other-username\\",\\"password\\":\\"some-other-password\\"}}}",
"COMPOSER_CACHE_DIR": "/tmp/renovate/cache/others/composer",
"HOME": "/home/user",
"HTTPS_PROXY": "https://example.com",
Expand Down
24 changes: 15 additions & 9 deletions lib/manager/composer/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface UserPass {
interface AuthJson {
'github-oauth'?: Record<string, string>;
'gitlab-token'?: Record<string, string>;
'gitlab-domains'?: string[];
'http-basic'?: Record<string, UserPass>;
}

Expand All @@ -51,15 +52,20 @@ function getAuthJson(): string | null {
};
}

const gitlabCredentials = hostRules.find({
hostType: PLATFORM_TYPE_GITLAB,
url: 'https://gitlab.com/api/v4/',
});
if (gitlabCredentials?.token) {
authJson['gitlab-token'] = {
'gitlab.com': gitlabCredentials.token,
};
}
hostRules
.findAll({ hostType: PLATFORM_TYPE_GITLAB })
?.forEach((gitlabHostRule) => {
if (gitlabHostRule?.token) {
const host = gitlabHostRule.hostName || 'gitlab.com';
authJson['gitlab-token'] = authJson['gitlab-token'] || {};
authJson['gitlab-token'][host] = gitlabHostRule.token;
// https://getcomposer.org/doc/articles/authentication-for-private-packages.md#gitlab-token
authJson['gitlab-domains'] = [
host,
...(authJson['gitlab-domains'] || []),
];
}
});

hostRules
.findAll({ hostType: datasourcePackagist.id })
Expand Down

0 comments on commit e49213a

Please sign in to comment.