Types¶
The commands in this repository and the interactive scripts in the
replication template
(tools/) authenticate to Jira and Bitbucket with Atlassian API tokens, and to
Box with a Box JWT app.
Where to set the variables¶
All credentials can be read from environment variables.
The
aea-box-*commands andaeagit-createalso read variables not set in the environment from~/.envvars, a file ofKEY=valuelines.The replication template’s
tools/scripts read only the environment (exceptjira_add_comment.py, which also reads~/.envvars).
Keep ~/.envvars (and the Box config file) in the home
directory there.
Set the variables as Codespaces secrets (see Cloud authentication).
Secured variables are documented in the replication template.
| Variable | Value |
|---|---|
JIRA_USERNAME | Atlassian account email |
JIRA_API_KEY | Jira API token |
P_BITBUCKET_PAT | Bitbucket API token (scoped) |
P_BITBUCKET_EMAIL | Atlassian account email for the Bitbucket REST API; defaults to JIRA_USERNAME |
P_BITBUCKET_USERNAME | Bitbucket username, for git over HTTPS (aeagit, aeagit-create) |
BOX_CONFIG_PATH | Directory with the Box config file (see Box) |
BOX_ENTERPRISE_ID, BOX_PRIVATE_KEY_ID | IDs from the Box config file name |
BOX_FOLDER_PRIVATE | Box folder holding the aearep-NNNN case folders |
BOX_PRIVATE_JSON | Base64-encoded Box config file, instead of the file |
Jira and Bitbucket API tokens¶
Bitbucket can be confusing¶
The Bitbucket REST API accepts the account email with the token; git over
HTTPS accepts only the Bitbucket username (shown under Personal settings in
Bitbucket).
Note
The older name P_BITBUCKET_USER
is still read when P_BITBUCKET_USERNAME is unset, with a deprecation notice.
Creating a token¶
Scoped and unscoped tokens are created at id.atlassian.com → Security → API tokens. Create only scoped tokens (Create API token with scopes). Unscoped tokens (Create API token) are deprecated: they act with all of the account’s permissions. Replace an existing unscoped token with a scoped one.
Tokens expire after at most one year; a command that uses Jira stops with an
error naming JIRA_USERNAME/JIRA_API_KEY when the token is no longer accepted.
Jira (JIRA_API_KEY)¶
Click Create API token with scopes.
Name it and pick an expiry date.
Select the app Jira.
Select the scopes listed under Scopes (Jira tabs), then Create.
Copy the token into
JIRA_API_KEY, and the account email intoJIRA_USERNAME.
The Jira commands connect through the Atlassian API gateway
(https://api.atlassian.com/ex/jira/c342e627-3ea3-47e3-b3dd-58b188a34a9e, set in
aea_editor_scripts/jira_auth.py), which accepts scoped tokens. Browse links
printed by the commands point to https://aeadataeditors.atlassian.net.
Bitbucket (P_BITBUCKET_PAT)¶
Click Create API token with scopes.
Name it and pick an expiry date.
Select the app Bitbucket.
Select the scopes listed under Scopes (Bitbucket tab), then Create.
Copy the token into
P_BITBUCKET_PAT.
Scopes¶
Scopes per command. Every command reads the current user
(read:jira-user) to verify the token on connecting.
| Command | read:jira-user | read:jira-work | write:jira-work | Other |
|---|---|---|---|---|
aea-box-clean-folders | ✓ | ✓ | ✓ | |
aea-box-create-folder | ✓ | ✓ | ✓ | |
aea-box-recover-files | ✓ | ✓ | ||
aeagit (--all only) | ✓ | ✓ | ||
aeagit-create | ✓ | ✓ | ✓ | |
jira-approval-manager | ✓ | ✓ | ✓ | |
jira-openicpsr-changes | ✓ | ✓ | --apply | |
jira-purge-query | ✓ | ✓ | ||
jira-reason-sync | ✓ | ✓ | --execute | |
jira-status-manager | ✓ | ✓ | when changing | |
jira_workflow_cleanup.py | manage:jira-configuration, or granular read:workflow:jira and delete:workflow:jira (separate scoped token) |
The write:jira-work operations are editing fields, transitions, comments, and
(in aea-box-create-folder) creating a subtask.
Equivalent granular scopes, for all commands except
jira_workflow_cleanup.py:
read:
read:application-role:jira,read:audit-log:jira,read:avatar:jira,read:comment:jira,read:comment.property:jira,read:field:jira,read:field-configuration:jira,read:group:jira,read:issue:jira,read:issue-details:jira,read:issue-meta:jira,read:issue-security-level:jira,read:issue.changelog:jira,read:issue.transition:jira,read:issue.vote:jira,read:project:jira,read:project-category:jira,read:project-role:jira,read:status:jira,read:user:jirawrite:
write:attachment:jira,write:comment:jira,write:comment.property:jira,write:issue:jira,write:issue.property:jira
| Command | read:repository | write:repository | admin:repository | delete:repository | read:pipeline | write:pipeline |
|---|---|---|---|---|---|---|
aeagit (HTTPS) | ✓ | to push | ||||
aeagit-create | ✓ | ✓ | ✓ | --delete | ✓ | ✓ |
jira-openicpsr-changes (--apply) | ✓ | ✓ | ✓ | ✓ |
All scopes carry the :bitbucket suffix (e.g. read:repository:bitbucket).
admin:repository covers creating a repository and enabling Pipelines on it.
A single token for all commands needs:
read:repository:bitbucketwrite:repository:bitbucketadmin:repository:bitbucketdelete:repository:bitbucketread:pipeline:bitbucketwrite:pipeline:bitbucket
Box¶
Box access uses a Box JWT app. Its credentials are a JSON file named
<ENTERPRISE_ID>_<KEY_ID>_config.json, available at 🔒
this private Box link. Most Box commands use
BOX_FOLDER_PRIVATE, which is the folder on Box holding the
aearep-NNNN case folders. The link to the JSON file is provided privately (here called <SECRETURL>)
Store the file in ~/.config/box/, readable only by you:
mkdir -p ~/.config/box
wget <SECRETURL> -P ~/Downloads
mv ~/Downloads/*_config.json ~/.config/box/
chmod 600 ~/.config/box/*_config.jsonThen add to ~/.envvars, taking the two IDs from the file name:
BOX_CONFIG_PATH=${HOME}/.config/box
BOX_ENTERPRISE_ID=<ENTERPRISE_ID>
BOX_PRIVATE_KEY_ID=<KEY_ID>
BOX_FOLDER_PRIVATE=144685329952The credentials can instead be stored as the Base64-encoded content of the JSON
file in BOX_PRIVATE_JSON, so that no config file needs to stay on disk. First add
BOX_ENTERPRISE_ID, BOX_PRIVATE_KEY_ID, and BOX_FOLDER_PRIVATE to
~/.envvars as in the Config file tab. Then:
source ~/.envvars
wget <SECRETURL> -P ~/Downloads
CONFIG=~/Downloads/${BOX_ENTERPRISE_ID}_${BOX_PRIVATE_KEY_ID}_config.json
# drop any existing BOX_PRIVATE_JSON line, then append the new one
sed -i.bak '/^BOX_PRIVATE_JSON=/d' ~/.envvars && rm ~/.envvars.bak
printf '\nBOX_PRIVATE_JSON=%s\n' "$(base64 < "$CONFIG" | tr -d '\n')" >> ~/.envvars
rm "$CONFIG"