Skip to content

Commit 037c262

Browse files
Simplify justfile; use updated Cortex CLI
1 parent 6ddf2aa commit 037c262

32 files changed

+708
-873
lines changed

Justfile

Lines changed: 29 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,48 @@
1-
cortex_cli := 'cortex'
2-
3-
help:
4-
@just -l
5-
@echo ""
6-
@echo "Details"
7-
@echo "The setup recipe requires the following environment variables to be set:"
8-
@echo "- CORTEX_API_KEY - must have edit entity permission at a minimum, typically will be an admin key"
9-
@echo "- CORTEX_BASE_URL - API endpoint, defaults to https://api.getcortexapp.com"
10-
@echo "- CORTEX_EMAIL - the user's cortex email address; will be used to assign as owner of the Learn Cortex entity"
11-
@echo ""
12-
@echo "The workflows recipe requires the following environment variables to be set:"
13-
@echo "- GH_PAT - a GitHub personal token that allows read/write access to github.com/cortexapps"
1+
cortex_cli := 'cortex'
2+
3+
export CORTEX_API_KEY := env('CORTEX_API_KEY')
4+
export CORTEX_BASE_URL := env('CORTEX_BASE_URL', "https://api.getcortexapp.com")
5+
export CORTEX_EMAIL := env('CORTEX_EMAIL')
6+
export GH_PAT := env('GH_PAT')
7+
8+
brew := require("brew")
9+
cortex := require("cortex")
10+
jq := require("jq")
11+
yq := require("yq")
12+
13+
@help:
14+
just -l
15+
echo ""
16+
echo "Details"
17+
echo "The setup recipe requires the following environment variables to be set:"
18+
echo "- CORTEX_API_KEY - must have edit entity permission at a minimum, typically will be an admin key"
19+
echo "- CORTEX_BASE_URL - API endpoint, defaults to https://api.getcortexapp.com"
20+
echo "- CORTEX_EMAIL - the user's cortex email address; will be used to assign as owner of the Learn Cortex entity"
21+
echo "- GH_PAT - a GitHub personal token that allows read/write access to github.com/cortexapps"
1422

1523
# Add test entities and Scorecard to Cortex instance
16-
setup: _check load-data _success
17-
18-
_check-vars:
19-
#!/bin/bash
20-
21-
echo "Checking environment variables"
22-
23-
if [[ -z "${CORTEX_API_KEY}" ]]; then
24-
echo ""
25-
echo "ERROR: CORTEX_API_KEY environment variable is not set."
26-
echo "------------------------------------------------------"
27-
echo "Please set environment variable CORTEX_API_KEY and retry."
28-
echo "Refer to https://docs.cortex.io/docs/walkthroughs/workspace-settings/personal-tokens for details on creating a personal token"
29-
echo "Example: export CORTEX_API_KEY=<your personal token>"
30-
echo ""
31-
exit 1
32-
fi
33-
34-
if [[ -z "${CORTEX_EMAIL}" ]]; then
35-
echo ""
36-
echo "ERROR: CORTEX_EMAIL environment variable is not set."
37-
echo "----------------------------------------------------"
38-
echo "Please set environment variable CORTEX_EMAIL and retry."
39-
echo "It will be used as the owner of the Learn Cortex entity"
40-
echo "Example: export [email protected]"
41-
echo ""
42-
exit 1
43-
fi
44-
45-
CORTEX_BASE_URL=${CORTEX_BASE_URL:-https://api.getcortexapp.com}
46-
47-
_check-pat:
48-
#!/bin/bash
49-
50-
echo "Checking if GitHub PAT environment variable is set"
51-
52-
if [[ -z "${GH_PAT}" ]]; then
53-
echo ""
54-
echo "ERROR: GH_PAT environment variable is not set."
55-
echo "------------------------------------------------------"
56-
echo "This setup script will create a GitHub Personal token integration in Cortex."
57-
echo "It requires a GitHub Personal Access Token to be set as an environment variable."
58-
echo "Refer to https://docs.cortex.io/docs/reference/integrations/github#how-to-configure-github-with-cortex"
59-
echo "for details on creating the token."
60-
echo ""
61-
echo "Once set, copy the content of the token and use it to set an environment variable as follows:"
62-
echo "export GH_PAT=yourTokenValue"
63-
echo ""
64-
exit 1
65-
fi
66-
67-
68-
_check: _check-brew _check-jq _check-yq _check-vars _check-cortex _mkdirs
69-
70-
_check-brew:
71-
@echo "Checking if brew is installed"
72-
@which brew > /dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
73-
74-
_check-jq:
75-
@echo "Checking if jq is installed"
76-
@which jq > /dev/null || brew install jq
77-
78-
_check-yq:
79-
@echo "Checking if yq is installed"
80-
@which yq > /dev/null || brew install yq
81-
82-
_check-cortex:
83-
#!/bin/bash
84-
echo "Checking if cortex CLI can access tenant"
85-
{{cortex_cli}} audit-logs get -p 0 -z 1 > /dev/null 2>&1
86-
if [[ $? -ne 0 ]]; then
87-
echo "ERROR: Unable to access tenant with Cortex CLI."
88-
echo "-----------------------------------------------"
89-
echo "Check API key in ~/.cortex/config under the [default] section."
90-
echo "To debug: run {{cortex_cli}} audit-logs get -o 0 -z 1"
91-
exit 1
92-
fi
93-
94-
_mkdirs:
95-
#!/bin/bash
96-
if [[ ! -d data/teams ]]; then
97-
mkdir data/teams
98-
fi
99-
if [[ ! -d data/resource-definitions ]]; then
100-
mkdir data/resource-definitions
101-
fi
24+
setup: load-data _success
10225

10326
_success:
10427
@echo "SUCCESS!"
10528
@echo "Login to your tenant and navigate to your Learn Cortex entity to starting learning Cortex."
10629

10730
# Install a single Cortex Scorecard file
108-
scorecard file: _check
31+
scorecard file:
10932
{{cortex_cli}} scorecard create -f {{file}}
11033

11134
# Load data from 'data' directory into Cortex
112-
load-data: _check
35+
load-data: _github
11336
@echo "Adding data to tenant"
114-
@{{cortex_cli}} backup import -d data > /dev/null 2>&1
37+
{{cortex_cli}} backup import -d data
11538

116-
@cat data/catalog/learn-cortex.yaml | yq -e ".info.x-cortex-owners = [{ \"name\": \"${CORTEX_EMAIL}\", \"type\": \"EMAIL\" }]" | cortex catalog create -f- > /dev/null 2>&1
39+
@cat data/catalog/learn-cortex.yaml | yq -e ".info.x-cortex-owners = [{ \"email\": \"${CORTEX_EMAIL}\", \"type\": \"EMAIL\" }]" | cortex catalog create -f- > /dev/null 2>&1
11740

118-
119-
# Add workflows for the Learn Cortex entity
120-
workflows: _check _github
121-
#!/bin/bash
122-
for workflow in $(ls -1 data/workflows)
123-
do
124-
status_code=$(\
125-
curl \
126-
-s \
127-
-w "%{http_code}" \
128-
-X POST \
129-
--data-binary @data/workflows/${workflow} \
130-
-H "Authorization: Bearer ${CORTEX_API_KEY}" \
131-
-H "Content-Type: application/yaml" \
132-
-o /dev/null \
133-
"${CORTEX_BASE_URL}/api/v1/workflows")
134-
if [ $status_code -ne 200 ]; then
135-
echo "curl failed with HTTP code $status_code"
136-
exit 1
137-
else
138-
echo "Added workflow: ${workflow}"
139-
fi
140-
done
141-
14241
# Add secrets needed for the Learn Cortex entity
143-
_github: _check-pat
42+
_github:
14443
#!/bin/bash
14544

146-
cortex integrations github get-personal -a "cortex - prod" > /dev/null 2>&1
45+
cortex integrations github list | jq -r ".configurations[].alias" | grep -e "cortex-prod\$" > /dev/null
14746
if [[ $? -ne 0 ]]; then
148-
envsubst < data/integrations/github/pat-configuration-json.tmpl | cortex integrations github add-personal -f-
47+
cortex integrations github add-personal -a "cortex-prod" --access-token ${GH_PAT}
14948
fi

data/integrations/github/pat-configuration-json.tmpl

Lines changed: 0 additions & 5 deletions
This file was deleted.

data/scorecards/learn-aws.yaml

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,24 @@ evaluation:
1414
ladder:
1515
name: Default Ladder
1616
levels:
17-
- name: Incomplete
18-
rank: 1
19-
color: "#FF9E9E"
20-
- name: Completed
21-
rank: 2
22-
color: "#7CCB92"
17+
- name: Incomplete
18+
rank: 1
19+
color: "#FF9E9E"
20+
- name: Completed
21+
rank: 2
22+
color: "#7CCB92"
2323
rules:
24-
- title: Learned
25-
expression: dependencies.out().any((dependency) => dependency.type == "AWS::S3::Bucket")
26-
identifier: a335adc6-3bac-381e-9147-e8403fb8c4df
27-
weight: 1
28-
level: Completed
29-
failureMessage: "# About\nThis scorecard rule will walk you through learning AWS\
30-
\ for Cortex.\n\n# Setup\n- Sign up for a [free tier AWS account](https://portal.aws.amazon.com/billing/signup?p=ft&c=hp&z=6&refid=78b916d7-7c94-4cab-98d9-0ce5e648dd5f).\n\
31-
\n- You will be prompted for a credit card. We recommend using a virtual credit\
32-
\ card service like privacy.com. Create a virtual credit card with a $1 total\
33-
\ spend limit. Amazon indicates they may put a temporary $1 hold on your account\
34-
\ to prove who you are.\n\n- Follow the Cortex [documentation](https://docs.cortex.io/docs/reference/integrations/aws)\
35-
\ for configuring the AWS integration.\n\n- Make sure you have enabled [automatic\
36-
\ import of AWS entities](https://docs.cortex.io/docs/reference/integrations/aws#enable-automatic-import-of-aws-entities).\
37-
\ Not required if you complete end up manually importing entities (details below),\
38-
\ but will be helpful for ongoing updates in your workspace.\n\n## Create an S3\
39-
\ bucket via the AWS console\n- Login to the AWS console. This should be a URL\
40-
\ of the form https://<account id>.signin.aws.amazon.com/console.\n\n- Search\
41-
\ for S3 in the search.\n\n- Click on S3 to go to the Simple Storage Service (S3)\
42-
\ page.\n\n- Click on the \"Create Bucket\" button.\n\n- Give the bucket a unique\
43-
\ name. The bucket name needs to be unique, so recommend a format like <firstName>-<lastName>-learn-cortex-bucket.\n\
44-
\n- Click on the add tag button.\n\n- Set key = service, value = learn-cortex.\n\
45-
\n- Optional: click on the add tag button again.\n\n- Set key = owner, value =\
46-
\ <x-cortex-tag for any team entity in your workspace>.\n\n# Task\n\n- AWS entities\
47-
\ are synced daily in Cortex, but you can force a manual sync.\n - Catalogs\
48-
\ -> All Entities -> Import Entities -> Import Discovered Entities -> AWS -> Sync\
49-
\ Entities.\n - Click on your S3 bucket.\n - Confirm Import\n- You should\
50-
\ end up with an AWS::S3::Bucket entity resembling the following entity YAML:\n\
51-
\ \n```\nopenapi: 3.0.1\ninfo:\n title: jeff-schnitter-learn-cortex\n x-cortex-tag:\
52-
\ jeff-schnitter-learn-cortex\n x-cortex-type: AWS::S3::Bucket\n x-cortex-infra:\n\
53-
\ aws:\n cloudControl:\n - type: AWS::S3::Bucket\n region:\
54-
\ us-east-1\n accountId: \"331409392944\"\n identifier: jeff-schnitter-learn-cortex\n\
55-
```\n\n- Outgoing dependencies are synced separately.\n- Navigate to the [relationship\
56-
\ graph](https://app.getcortexapp.com/admin/graph) -> 3 dots -> Sync dependencies.\n\
57-
- Navigate to the Learn Cortex entity\n- You should see an outgoing dependencies\
58-
\ for the Learn Cortex entity that references your S3 bucket.\n\n![Learn Cortex\
59-
\ entity](https://p-a6fkm3vd.t3.n0.cdn.zight.com/items/v1uzNDw6/57432f96-6ea8-40e0-a066-9c4d27086b94.jpg?source=viewer&v=cb5f1793e6e9308cbd5ac04233a3477c)\n\
60-
\n# CQL Rule\nThe CQL rule for this rule verifies that the \"Learn Cortex\" has\
61-
\ an outgoing dependency of type \"AWS::S3::Bucket\"."
24+
- title: Learned
25+
expression: dependencies.out().any((dependency) => dependency.type == "AWS::S3::Bucket")
26+
identifier: a335adc6-3bac-381e-9147-e8403fb8c4df
27+
weight: 1
28+
level: Completed
29+
failureMessage: "# About\nThis scorecard rule will walk you through learning AWS for Cortex.\n\n# Setup\n- Sign up for a [free tier AWS account](https://portal.aws.amazon.com/billing/signup?p=ft&c=hp&z=6&refid=78b916d7-7c94-4cab-98d9-0ce5e648dd5f).\n\n- You will be prompted for a credit card. We recommend using a virtual credit card service like privacy.com. Create a virtual credit card with a $1 total spend limit. Amazon indicates they may put a temporary $1 hold on your account to prove who you are.\n\n- Follow the Cortex [documentation](https://docs.cortex.io/docs/reference/integrations/aws) for configuring the AWS integration.\n\n- Make sure you have enabled [automatic import of AWS entities](https://docs.cortex.io/docs/reference/integrations/aws#enable-automatic-import-of-aws-entities). Not required if you complete end up manually importing entities (details below), but will be helpful for ongoing updates in your workspace.\n\n## Create an S3 bucket via the AWS console\n- Login to the AWS console. This should be a URL of the form https://<account id>.signin.aws.amazon.com/console.\n\n- Search for S3 in the search.\n\n- Click on S3 to go to the Simple Storage Service (S3) page.\n\n- Click on the \"Create Bucket\" button.\n\n- Give the bucket a unique name. The bucket name needs to be unique, so recommend a format like <firstName>-<lastName>-learn-cortex-bucket.\n\n- Click on the add tag button.\n\n- Set key = service, value = learn-cortex.\n\n- Optional: click on the add tag button again.\n\n- Set key = owner, value = <x-cortex-tag for any team entity in your workspace>.\n\n# Task\n\n- AWS entities are synced daily in Cortex, but you can force a manual sync.\n - Catalogs -> All Entities -> Import Entities -> Import Discovered Entities -> AWS -> Sync Entities.\n - Click on your S3 bucket.\n - Confirm Import\n- You should end up with an AWS::S3::Bucket entity resembling the following entity YAML:\n \n```\nopenapi: 3.0.1\ninfo:\n title: jeff-schnitter-learn-cortex\n x-cortex-tag: jeff-schnitter-learn-cortex\n x-cortex-type: AWS::S3::Bucket\n x-cortex-infra:\n aws:\n cloudControl:\n - type: AWS::S3::Bucket\n region: us-east-1\n accountId: \"331409392944\"\n identifier: jeff-schnitter-learn-cortex\n```\n\n- Outgoing dependencies are synced separately.\n- Navigate to the [relationship graph](https://app.getcortexapp.com/admin/graph) -> 3 dots -> Sync dependencies.\n- Navigate to the Learn Cortex entity\n- You should see an outgoing dependencies for the Learn Cortex entity that references your S3 bucket.\n\n![Learn Cortex entity](https://p-a6fkm3vd.t3.n0.cdn.zight.com/items/v1uzNDw6/57432f96-6ea8-40e0-a066-9c4d27086b94.jpg?source=viewer&v=cb5f1793e6e9308cbd5ac04233a3477c)\n\n# CQL Rule\nThe CQL rule for this rule verifies that the \"Learn Cortex\" has an outgoing dependency of type \"AWS::S3::Bucket\"."
6230
filter:
6331
kind: GENERIC
6432
types:
6533
include:
66-
- service
34+
- service
6735
groups:
6836
include:
69-
- learn-cortex
37+
- learn-cortex

data/scorecards/learn-azure-devops.yaml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,40 @@ evaluation:
1414
ladder:
1515
name: Default Ladder
1616
levels:
17-
- name: Unwritten
18-
rank: 1
19-
color: "#D7AC58"
20-
- name: Completed
21-
rank: 2
22-
color: "#7CCB92"
17+
- name: Unwritten
18+
rank: 1
19+
color: "#D7AC58"
20+
- name: Completed
21+
rank: 2
22+
color: "#7CCB92"
2323
rules:
24-
- title: Learned
25-
expression: custom("learned") != null
26-
identifier: 921bc595-5a12-3aa1-af45-e17d17e0d649
27-
weight: 1
28-
level: Completed
29-
failureMessage: |
30-
# About
31-
Describe what the scorecard does.
24+
- title: Learned
25+
expression: custom("learned") != null
26+
identifier: 921bc595-5a12-3aa1-af45-e17d17e0d649
27+
weight: 1
28+
level: Completed
29+
failureMessage: |
30+
# About
31+
Describe what the scorecard does.
3232
33-
# Set up
34-
Refer to any existing documentation at https://cortex.io/docs and describe any third party software setup.
33+
# Set up
34+
Refer to any existing documentation at https://cortex.io/docs and describe any third party software setup.
3535
3636
37-
# Related Cortex Academy courses
38-
List any related courses available at academy.cortex.io.
37+
# Related Cortex Academy courses
38+
List any related courses available at academy.cortex.io.
3939
40-
# Task
41-
Describe the steps to complete the task here.
40+
# Task
41+
Describe the steps to complete the task here.
4242
4343
44-
# CQL Rule
45-
Explain what the CQL checks.
44+
# CQL Rule
45+
Explain what the CQL checks.
4646
filter:
4747
kind: GENERIC
48+
types:
49+
include:
50+
- service
4851
groups:
4952
include:
50-
- learn-cortex
53+
- learn-cortex

data/scorecards/learn-bitbucket.yaml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,40 @@ evaluation:
1414
ladder:
1515
name: Default Ladder
1616
levels:
17-
- name: Unwritten
18-
rank: 1
19-
color: "#D7AC58"
20-
- name: Completed
21-
rank: 2
22-
color: "#7CCB92"
17+
- name: Unwritten
18+
rank: 1
19+
color: "#D7AC58"
20+
- name: Completed
21+
rank: 2
22+
color: "#7CCB92"
2323
rules:
24-
- title: Learned
25-
expression: custom("learned") != null
26-
identifier: 921bc595-5a12-3aa1-af45-e17d17e0d649
27-
weight: 1
28-
level: Completed
29-
failureMessage: |
30-
# About
31-
Describe what the scorecard does.
24+
- title: Learned
25+
expression: custom("learned") != null
26+
identifier: 921bc595-5a12-3aa1-af45-e17d17e0d649
27+
weight: 1
28+
level: Completed
29+
failureMessage: |
30+
# About
31+
Describe what the scorecard does.
3232
33-
# Set up
34-
Refer to any existing documentation at https://cortex.io/docs and describe any third party software setup.
33+
# Set up
34+
Refer to any existing documentation at https://cortex.io/docs and describe any third party software setup.
3535
3636
37-
# Related Cortex Academy courses
38-
List any related courses available at academy.cortex.io.
37+
# Related Cortex Academy courses
38+
List any related courses available at academy.cortex.io.
3939
40-
# Task
41-
Describe the steps to complete the task here.
40+
# Task
41+
Describe the steps to complete the task here.
4242
4343
44-
# CQL Rule
45-
Explain what the CQL checks.
44+
# CQL Rule
45+
Explain what the CQL checks.
4646
filter:
4747
kind: GENERIC
48+
types:
49+
include:
50+
- service
4851
groups:
4952
include:
50-
- learn-cortex
53+
- learn-cortex

0 commit comments

Comments
 (0)