|
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" |
14 | 22 |
|
15 | 23 | # 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 |
102 | 25 |
|
103 | 26 | _success: |
104 | 27 | @echo "SUCCESS!" |
105 | 28 | @echo "Login to your tenant and navigate to your Learn Cortex entity to starting learning Cortex." |
106 | 29 |
|
107 | 30 | # Install a single Cortex Scorecard file |
108 | | -scorecard file: _check |
| 31 | +scorecard file: |
109 | 32 | {{cortex_cli}} scorecard create -f {{file}} |
110 | 33 |
|
111 | 34 | # Load data from 'data' directory into Cortex |
112 | | -load-data: _check |
| 35 | +load-data: _github |
113 | 36 | @echo "Adding data to tenant" |
114 | | - @{{cortex_cli}} backup import -d data > /dev/null 2>&1 |
| 37 | + {{cortex_cli}} backup import -d data |
115 | 38 |
|
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 |
117 | 40 |
|
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 | | - |
142 | 41 | # Add secrets needed for the Learn Cortex entity |
143 | | -_github: _check-pat |
| 42 | +_github: |
144 | 43 | #!/bin/bash |
145 | 44 |
|
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 |
147 | 46 | 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} |
149 | 48 | fi |
0 commit comments