Fixed inverted basic and bearer
Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
@@ -65,7 +65,7 @@ There is some configuration that needs to be setup to use this action, here are
|
||||
```yaml
|
||||
confluence:
|
||||
baseUrl: 'https://confluence.example.com'
|
||||
auth: 'basic'
|
||||
auth: 'bearer'
|
||||
token: '${CONFLUENCE_TOKEN}'
|
||||
email: 'example@company.org'
|
||||
username: 'your-username'
|
||||
@@ -80,16 +80,7 @@ If you are using a self-hosted Confluence instance this does not apply to you. Y
|
||||
|
||||
#### Auth Methods
|
||||
|
||||
The default authorization method is `basic` but `bearer` and `userpass` are also supported. Here's how you would configure each of these:
|
||||
|
||||
For `basic`:
|
||||
|
||||
```yaml
|
||||
confluence:
|
||||
baseUrl: 'https://confluence.example.com'
|
||||
auth: 'basic'
|
||||
token: '${CONFLUENCE_TOKEN}'
|
||||
```
|
||||
The default authorization method is `bearer` but `basic` and `userpass` are also supported. Here's how you would configure each of these:
|
||||
|
||||
For `bearer`:
|
||||
|
||||
@@ -98,6 +89,15 @@ confluence:
|
||||
baseUrl: 'https://confluence.example.com'
|
||||
auth: 'bearer'
|
||||
token: '${CONFLUENCE_TOKEN}'
|
||||
```
|
||||
|
||||
For `basic`:
|
||||
|
||||
```yaml
|
||||
confluence:
|
||||
baseUrl: 'https://confluence.example.com'
|
||||
auth: 'basic'
|
||||
token: '${CONFLUENCE_TOKEN}'
|
||||
email: 'example@company.org'
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
apiVersion: scaffolder.backstage.io/v1beta3
|
||||
kind: Template
|
||||
metadata:
|
||||
name: confluence-to-markdown
|
||||
title: Confluence to Markdown
|
||||
description: This template converts a single confluence document to Markdown for Techdocs and adds it to a given GitHub repo.
|
||||
tags:
|
||||
- do-not-use
|
||||
- poc
|
||||
spec:
|
||||
owner: team-d
|
||||
type: service
|
||||
parameters:
|
||||
- title: Confluence and Github Repo Information
|
||||
properties:
|
||||
confluenceUrls:
|
||||
type: array
|
||||
description: Urls for confluence doc to be converted to markdown. In format <CONFLUENCE_BASE_URL>/display/<SPACEKEY>/<PAGE+TITLE> or <CONFLUENCE_BASE_URL>/spaces/<SPACEKEY>/pages/<PAGEID>/<PAGE+TITLE> for Confluence cloud
|
||||
items:
|
||||
type: string
|
||||
default: confluence url
|
||||
ui:options:
|
||||
addable: true
|
||||
minItems: 1
|
||||
maxItems: 5
|
||||
repoUrl:
|
||||
type: string
|
||||
title: GitHub URL mkdocs.yaml link
|
||||
description: The GitHub repo URL to your mkdocs.yaml file. Example <https://github.com/blob/master/mkdocs.yml>
|
||||
steps:
|
||||
- id: create-docs
|
||||
name: Get markdown file created and update markdown.yaml file
|
||||
action: confluence:transform:markdown
|
||||
input:
|
||||
confluenceUrls: ${{ parameters.confluenceUrls }}
|
||||
repoUrl: ${{ parameters.repoUrl }}
|
||||
- id: publish
|
||||
name: Publish PR to GitHub
|
||||
action: publish:github:pull-request
|
||||
input:
|
||||
repoUrl: <GITHUB_BASE_URL>?repo=${{ steps['create-docs'].output.repo }}&owner=${{ steps['create-docs'].output.owner }}
|
||||
branchName: confluence-to-markdown
|
||||
title: Confluence to Markdown
|
||||
description: PR for converting confluence page to mkdocs
|
||||
+12
-12
@@ -53,11 +53,11 @@ describe('createConfluenceVariables', () => {
|
||||
});
|
||||
|
||||
describe('getConfluenceConfig', () => {
|
||||
it('should return validate basic Confluence config', async () => {
|
||||
it('should return validate bearer Confluence config', async () => {
|
||||
const config = new ConfigReader({
|
||||
confluence: {
|
||||
baseUrl: 'https://example.atlassian.net',
|
||||
auth: 'basic',
|
||||
auth: 'bearer',
|
||||
token: 'fake_token',
|
||||
},
|
||||
});
|
||||
@@ -66,7 +66,7 @@ describe('getConfluenceConfig', () => {
|
||||
|
||||
expect(validated).toEqual({
|
||||
baseUrl: 'https://example.atlassian.net',
|
||||
auth: 'basic',
|
||||
auth: 'bearer',
|
||||
token: 'fake_token',
|
||||
email: undefined,
|
||||
username: undefined,
|
||||
@@ -74,11 +74,11 @@ describe('getConfluenceConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return validate bearer Confluence config', async () => {
|
||||
it('should return validate basic Confluence config', async () => {
|
||||
const config = new ConfigReader({
|
||||
confluence: {
|
||||
baseUrl: 'https://example.atlassian.net',
|
||||
auth: 'bearer',
|
||||
auth: 'basic',
|
||||
token: 'fake_token',
|
||||
email: 'example@example.atlassian.net',
|
||||
},
|
||||
@@ -88,7 +88,7 @@ describe('getConfluenceConfig', () => {
|
||||
|
||||
expect(validated).toEqual({
|
||||
baseUrl: 'https://example.atlassian.net',
|
||||
auth: 'bearer',
|
||||
auth: 'basic',
|
||||
token: 'fake_token',
|
||||
email: 'example@example.atlassian.net',
|
||||
username: undefined,
|
||||
@@ -120,22 +120,22 @@ describe('getConfluenceConfig', () => {
|
||||
});
|
||||
|
||||
describe('getAuthorizationHeaderValue', () => {
|
||||
it('should return basic auth header value', async () => {
|
||||
it('should return bearer auth header value', async () => {
|
||||
const config = {
|
||||
baseUrl: 'https://example.atlassian.net',
|
||||
auth: 'basic',
|
||||
auth: 'bearer',
|
||||
token: 'fake_token',
|
||||
};
|
||||
|
||||
const authHeaderValue = getAuthorizationHeaderValue(config);
|
||||
|
||||
expect(authHeaderValue).toEqual('Basic fake_token');
|
||||
expect(authHeaderValue).toEqual('Bearer fake_token');
|
||||
});
|
||||
|
||||
it('should return bearer auth header value', async () => {
|
||||
it('should return basic auth header value', async () => {
|
||||
const config = {
|
||||
baseUrl: 'https://example.atlassian.net',
|
||||
auth: 'bearer',
|
||||
auth: 'basic',
|
||||
token: 'fake_token',
|
||||
email: 'example@example.atlassian.net',
|
||||
};
|
||||
@@ -144,7 +144,7 @@ describe('getAuthorizationHeaderValue', () => {
|
||||
|
||||
// Note: this is fake and just the encoded result
|
||||
expect(authHeaderValue).toEqual(
|
||||
'Bearer ZXhhbXBsZUBleGFtcGxlLmF0bGFzc2lhbi5uZXQ6ZmFrZV90b2tlbg==',
|
||||
'Basic ZXhhbXBsZUBleGFtcGxlLmF0bGFzc2lhbi5uZXQ6ZmFrZV90b2tlbg==',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
+6
-6
@@ -55,7 +55,7 @@ export type ConfluenceConfig = {
|
||||
export const getConfluenceConfig = (config: Config) => {
|
||||
const confluenceConfig: ConfluenceConfig = {
|
||||
baseUrl: config.getString('confluence.baseUrl'),
|
||||
auth: config.getOptionalString('confluence.auth') ?? 'basic',
|
||||
auth: config.getOptionalString('confluence.auth') ?? 'bearer',
|
||||
token: config.getOptionalString('confluence.token'),
|
||||
email: config.getOptionalString('confluence.email'),
|
||||
username: config.getOptionalString('confluence.username'),
|
||||
@@ -71,7 +71,7 @@ export const getConfluenceConfig = (config: Config) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (confluenceConfig.auth === 'bearer' && !confluenceConfig.email) {
|
||||
if (confluenceConfig.auth === 'basic' && !confluenceConfig.email) {
|
||||
throw new Error(
|
||||
`No email provided for the configured '${confluenceConfig.auth}' auth method`,
|
||||
);
|
||||
@@ -92,12 +92,12 @@ export const getConfluenceConfig = (config: Config) => {
|
||||
export const getAuthorizationHeaderValue = (config: ConfluenceConfig) => {
|
||||
let authHeaderValue: string = '';
|
||||
switch (config.auth) {
|
||||
case 'basic':
|
||||
authHeaderValue = `Basic ${config.token}`;
|
||||
case 'bearer':
|
||||
authHeaderValue = `Bearer ${config.token}`;
|
||||
break;
|
||||
case 'bearer': {
|
||||
case 'basic': {
|
||||
const buffer = Buffer.from(`${config.email}:${config.token}`, 'utf8');
|
||||
authHeaderValue = `Bearer ${buffer.toString('base64')}`;
|
||||
authHeaderValue = `Basic ${buffer.toString('base64')}`;
|
||||
break;
|
||||
}
|
||||
case 'userpass': {
|
||||
|
||||
Reference in New Issue
Block a user