Skip to content

Commit

Permalink
Add basic auth support
Browse files Browse the repository at this point in the history
Closes gh-4
  • Loading branch information
philwebb committed Mar 21, 2024
1 parent 1503c8d commit 8ecb652
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ antora:
- url: https://repo.example.com/com/example/myproject/my-project-docs/${version}/my-project-docs-${version}-${name}.zip
----

You can also configure basic auth by using `username` and `password` configuration:

.antora-playbook.yml
[,yaml]
----
antora:
extensions:
- require: '@springio/antora-zip-contents-collector-extension'
version_file: gradle.properties
username: me
password: ${env.MY_SECRET_PASSWORD}"
locations:
- url: https://repo.example.com/com/example/myproject/my-project-docs/${version}/my-project-docs-${version}-${name}.zip
----



=== Local Files
Expand Down
6 changes: 6 additions & 0 deletions packages/antora-zip-contents-collector-extension/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ function register ({ config, downloadLog }) {
for (const location of locations) {
if (considerLocation(location, versionClassification)) {
const url = resolvePlaceholders(location.url, locationVariables)
const username = location.username || config.username
const password = location.password || config.password
const httpHeaders = { ...config.httpHeaders, ...location.httpHeaders }
if (username || password) {
const credentials = Buffer.from(`${username ?? ''}:${password ?? ''}`).toString('base64')
httpHeaders.Authorization = `Basic ${credentials}`
}
if (['http:', 'https:'].some((prefix) => url.toLowerCase().startsWith(prefix))) {
try {
return await download(name, url, httpHeaders, downloadCacheDir, downloadLog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,32 @@ describe('zip contents collector extension', () => {
})
})

it('should download zip and collect files with global username / password', async () => {
process.env.MY_PASSWORD = 'secret'
const extensionConfig = () => ({
username: 'admin',
password: 'secret',
locations: [{ url: `http://localhost:${httpServerPort}/\${name}.zip` }],
})
const componentConfig = { include: ['start-page'] }
await runScenario({
repoName: 'test-at-root',
extensionConfig,
componentConfig,
zipFiles: ['start-page'],
httpPath: '/',
httpUsers: { admin: 'secret' },
before: ({ contentAggregate }) => {
expect(contentAggregate).to.have.lengthOf(1)
expect(contentAggregate[0].files).to.be.empty()
},
after: ({ contentAggregate }) => {
expect(contentAggregate[0].files).to.have.lengthOf(1)
expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc')
},
})
})

it('should update component metadata from antora.yml file, if found in root', async () => {
const extensionConfig = () => ({
locations: [{ url: `http://localhost:${httpServerPort}/\${name}.zip` }],
Expand Down

0 comments on commit 8ecb652

Please sign in to comment.