CODE STREAM - CUSTOM INTEGRATION - GENERATE BASIC AUTHENTICATION HEADER

To generate a basic authentication header from a username and password in Code Stream you could use a CI task and execute echo -n username:password | base64
in the shell then export the result for use later on. A more repeatable way is to create a Custom Integration that takes the two inputs, and returns the encoded header as an output.
To create the Custom Integration:
- Create a new Custom Integration named “Create Basic Authentication Header”
- Select the Runtime - the examples below are
shell
andpython3
respectively - Replace the placeholder code with the example from below
- Save and version the Custom Integration, ensuring you eanble the “Release Version” toggle
To use the Custom Integration in a pipeline:
- Configure the Host (you’ll need a Docker endpoint configured for this) and Builder image URL settings in the Workspace tab of your pipeline (e.g.
python:latest
) - Add a new Custom task, to your Stage, select the “Create Basic Authentication Header” integration and configure the inputs
- Use the tasks
output.properties
to refer to the header value in your later tasks - e.g. I’m using${Stage0.Create Auth Header.output.properties.basicAuthHeader}
to refer to the output in a REST task below:
Below are the shell and a Python3 examples, in the YAML format to paste into your custom integration:
1---
2runtime: shell
3code: |
4 export basicAuthHeader=$(echo -n $username:$password | base64)
5inputProperties: # Enter fields for input section of a task
6 # Username input
7 - name: 'username'
8 type: text
9 title: 'Username'
10 placeHolder: 'Enter basic authentication usename'
11 required: true
12 bindable: true
13 # Password input
14 - name: 'password'
15 type: password
16 title: 'Password'
17 placeHolder: 'Enter basic authentication password'
18 defaultValue: ''
19 required: true
20 bindable: true
21outputProperties:
22 - name: basicAuthHeader
23 type: label
24 title: Basic Authentication Header
1---
2runtime: "python3"
3code: |
4 from base64 import b64encode
5 from context import getInput, setOutput
6 username = getInput('username')
7 password = getInput('password')
8 usernameAndPassword = b64encode(bytes(f'{username}:{password}',encoding='ascii')).decode('ascii')
9 setOutput('basicAuthHeader', "Basic "+usernameAndPassword)
10inputProperties: # Enter fields for input section of a task
11 # Username input
12 - name: 'username'
13 type: text
14 title: 'Username'
15 placeHolder: 'Enter basic authentication usename'
16 required: true
17 bindable: true
18 # Password input
19 - name: 'password'
20 type: password
21 title: 'Password'
22 placeHolder: 'Enter basic authentication password'
23 defaultValue: ''
24 required: true
25 bindable: true
26outputProperties:
27 - name: basicAuthHeader
28 type: label
29 title: Basic Authentication Header