Skip to content

Commit c0201cd

Browse files
Merge pull request #184 from cyberark/rework-utility-scripts
Rework utility scripts
2 parents 6c99ddb + 8a040c2 commit c0201cd

File tree

18 files changed

+464
-350
lines changed

18 files changed

+464
-350
lines changed

.github/workflows/api_contract.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
uses: actions/checkout@v2
1717

1818
- name: run api contract test script
19-
run: ./bin/api_test
19+
run: ./bin/test_api_contract

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
uses: actions/checkout@v2
1717

1818
- name: run integration test script
19-
run: ./bin/integration_tests --python
19+
run: ./bin/test_integration -l python
2020

2121
dot-net:
2222
runs-on: ubuntu-latest
@@ -26,7 +26,7 @@ jobs:
2626
uses: actions/checkout@v2
2727

2828
- name: run integration test script
29-
run: ./bin/integration_tests --csharp
29+
run: ./bin/test_integration -l csharp-netcore
3030

3131
java:
3232
runs-on: ubuntu-latest
@@ -36,4 +36,4 @@ jobs:
3636
uses: actions/checkout@v2
3737

3838
- name: run integration test script
39-
run: ./bin/integration_tests --java
39+
run: ./bin/test_integration -l java

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
allowing for proper binary secrets in clients (`format: binary` is broken in some clients).
1212
[cyberark/conjur-openapi-spec#187](https://github.com/cyberark/conjur-openapi-spec/pull/187)
1313

14+
### Changed
15+
- Consolidate `bin/integration_test` and `bin/test_enterprise` into `bin/test_integration`.
16+
Renamed `bin/api_test` to `bin/test_api_contract` and `bin/start` to `bin/dev` to maintain
17+
repository- and company-wide script convention.
18+
[cyberark/conjur-openapi-spec#166](https://github.com/cyberark/conjur-openapi-spec/issues/166)
19+
1420
## [5.1.1] - 2021-04-28
1521
### Added
1622
- DAP endpoints and scripts to run tests against a DAP instance.

CONTRIBUTING.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,30 @@ To ensure your changes work as expected, you can run the [automated tests](#auto
129129

130130
#### Automated tests
131131

132-
`bin/api_test [-e <endpoint>]`
132+
`bin/test_api_contract [-e <endpoint>]`
133133
* Uses Schemathesis to generate test cases for API endpoints, which test the
134134
conformance between Conjur OSS and the OpenAPI specification.
135135
* Runs containerized contract testing on all endpoints specified in [`openapi.yml`](openapi.yml)
136136
* Specifying an endpoint with the `-e|--endpoint` flag runs contract tests on that endpoint alone.
137137

138-
`bin/integration_tests`
139-
* Used to run the suite of integration tests.
140-
* Stands up a new Conjur `docker-compose` environment, generates a Python client
138+
`bin/test_integration`
139+
* Used to run the suite of integration tests against Conjur OSS or Enterprise.
140+
* Stands up a new Conjur environment, generates a client
141141
library, and runs the integration test suite.
142-
* Run tests for only one client by specifying a client flag (currently only Python
143-
is supported):
142+
* User must specify a client language to test with `-l`:
144143
```shell
145-
$ ./bin/integration_tests --python
144+
$ ./bin/test_integration -l python
146145
```
147146
* Run a subset of a clients tests by including an argument with the full package
148147
path of the tests to run:
149148
```shell
150-
$ ./bin/integration_tests --python test_authn_api.TestAuthnApi.test_authenticate_200
149+
$ ./bin/test_integration -l python --test test_authn_api.TestAuthnApi.test_authenticate_200
150+
```
151+
* Tests can be run against Conjur Enterprise.
152+
* This requires access to the CyberArk Docker registry in order to pull Conjur Enterprise images
153+
```shell
154+
$ ./bin/test_integration --enterprise -l python
151155
```
152-
153-
`bin/test_enterprise`
154-
* Used to run the integration tests against a Conjur Enterprise instance
155-
* You will need to have access to the Cyberark Docker registry in order to pull the Conjur Enterprise images
156156

157157
#### Linters
158158

@@ -182,14 +182,17 @@ To ensure your changes work as expected, you can run the [automated tests](#auto
182182
* Runs the `bin/bundle_spec` script before starting and points the UI at the bundled spec.
183183
* Editor available at http://localhost:9090 once the container is up.
184184

185-
`bin/start`
185+
`bin/dev`
186186
* Used to set up a new development environment.
187187
* Calls both `start_editor` and `start_conjur` to bring up both Conjur and Editor containers.
188188

189189
`bin/start_conjur`
190190
* Used to start a new local Conjur instance based on the project's `docker-compose`.
191191
* Both the http & https ports are exposed so requests can be made to Conjur from outside the docker network.
192192

193+
`bin/start_enterprise`
194+
* Used to start a new local Conjur Enterprise instance based on [`dap-intro`](https://github.com/conjurdemos/dap-intro)
195+
193196
`bin/stop`
194197
* Used to deconstruct the development environment.
195198
* Stops and removes the `docker-compose` environment and Swagger Editor.

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pipeline {
1212
stage('Enterprise Integration Tests') {
1313
steps {
1414
script {
15-
sh "./bin/test_enterprise"
15+
sh "./bin/test_integration -e -l python"
1616
}
1717
}
1818
}
@@ -21,7 +21,7 @@ pipeline {
2121
steps {
2222
script {
2323
ccCoverage.dockerPrep()
24-
sh './bin/integration_tests --python'
24+
sh './bin/test_integration -l python'
2525
}
2626
}
2727

bin/start renamed to bin/dev

File renamed without changes.

bin/generate_client

Lines changed: 100 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,137 @@
11
#!/usr/bin/env bash
2-
2+
source bin/util
33
set -euo pipefail
44

55
print_help(){
6-
echo -e "./bin/generate_client [-o <output-directory>] [-l <client-language> ] [-n] [--enterprise]"
7-
echo -e "\tUses the OpenApi generator to create a client for the API spec"
8-
echo -e "\tDefault output goes in the 'out' directory under the generated client language"
9-
echo -e "\tIf no language is specified the Python client will be generated"
10-
echo
11-
echo -e "\tThe -n option will prevent the creation of a client language directory"
12-
echo -e "\t\tso the output would go to 'out/' instead of 'out/python' for the python client"
13-
echo
14-
echo -e "\tThe --enterprise option will generate the spec with included Conjur Enterprise-only endpoints"
6+
announce "CONJUR OPENAPI DESCRIPTION :: CLIENT GENERATION"
7+
cat << EOF
8+
Uses the OpenAPI Generator to create a client for the API spec.
9+
Can generate clients for Conjur OSS (default) or Enterprise.
10+
Clients are output to ./out/<oss|enterprise>/<language> by default.
11+
12+
USAGE
13+
./bin/generate_client -l <language> [options]
14+
15+
MANDATORY
16+
-l|--language <language> Specify a client language
17+
18+
OPTIONS
19+
-e|--enterprise Generate client for Conjur Enterprise
20+
-h|--help Print help message
21+
-n|--no-sub-dir Generated clients output directly to ./out
22+
-o|--output <dir> Specify an output directory
23+
EOF
1524
}
1625

1726
generator_version="v4.3.1"
1827
GENERATOR_IMAGE="openapitools/openapi-generator-cli:$generator_version"
1928

20-
client_lang="python"
29+
client_lang=""
30+
appliance="oss"
31+
output_volume=""
32+
enterprise=0
33+
given_out_dir=0
2134
make_client_dir=1
22-
output_volume="out/"
23-
output_dir='/out/oss'
24-
input_dir='out/oss/spec'
25-
dap_spec=0
26-
27-
mkdir -p out/enterprise
28-
mkdir -p out/oss
2935

3036
while test $# -gt 0
3137
do
32-
param=$1
33-
shift
34-
case "$param" in
35-
-o)
36-
output_volume=$1
37-
shift
38-
;;
39-
-l)
40-
client_lang=$1
41-
shift
42-
;;
43-
-n)
44-
make_client_dir=0
45-
;;
46-
-h)
47-
print_help
48-
exit 0
49-
;;
50-
--enterprise)
51-
dap_spec=1
52-
input_dir='out/enterprise/spec'
53-
output_dir='/out/enterprise'
54-
;;
55-
*)
56-
break
57-
;;
58-
esac
38+
param=$1
39+
shift
40+
case "$param" in
41+
-e|--enterprise)
42+
enterprise=1
43+
appliance="enterprise"
44+
input_dir='out/enterprise/spec'
45+
output_dir='/out/enterprise'
46+
;;
47+
-h|--help)
48+
print_help
49+
exit 0
50+
;;
51+
-l|--language)
52+
client_lang=$1
53+
54+
if [[ ${client_lang:0:1} == "-" ]]; then
55+
echo "Option --language requires specifying argument"
56+
echo "Usage: ./bin/generate_client -l <language> [options]"
57+
exit 1
58+
fi
59+
60+
shift
61+
;;
62+
-n|--no-sub-dir)
63+
make_client_dir=0
64+
;;
65+
-o|--output)
66+
output_volume=$1
67+
68+
if [[ ${output_volume:0:1} == "-" ]]; then
69+
echo "Option --output requires specifying argument"
70+
echo "Usage: ./bin/generate_client -l <language> -o <dir>"
71+
exit 1
72+
fi
73+
74+
given_out_dir=1
75+
if [ ${output_volume:0:2} == "./" ]; then
76+
ouput_volume=${PWD}/${output_volume#*./}
77+
elif [ ${output_volume:0:1} != "/" ]; then
78+
output_volume=${PWD}/${output_volume}
79+
fi
80+
shift
81+
;;
82+
*)
83+
break
84+
;;
85+
esac
5986
done
6087

61-
if [ ! -e "$output_volume" ]; then
62-
mkdir -p "$output_volume"
88+
if [[ -z $client_lang ]]; then
89+
echo "Missing required --language option"
90+
echo "Usage: ./bin/generate_client -l <language> [options]"
91+
exit 1
6392
fi
64-
output_volume="$(pushd $output_volume > /dev/null && echo ${PWD} && popd > /dev/null)"
6593

66-
if [ $make_client_dir -eq 1 ]; then
67-
output_dir="$output_dir/$client_lang"
94+
input_dir="out/$appliance/spec"
95+
if [ $given_out_dir -eq 0 ]; then
96+
output_volume="${PWD}/out/$appliance/$client_lang/"
6897
fi
98+
if [ $make_client_dir -eq 0 ]; then
99+
output_volume="${PWD}/out/"
100+
fi
101+
102+
echo "Removing old client dir..."
103+
rm -rf $output_volume
104+
mkdir -p $output_volume
69105

70106
# if templates for a language exist we use them for generation
71107
template_dir="templates/$client_lang"
72108
if [ -e $template_dir ]; then
73-
template_arg="-t /local/$template_dir"
109+
template_arg="-t /local/$template_dir"
74110
else
75-
template_arg=""
111+
template_arg=""
76112
fi
77113

78-
echo "Pulling latest release $GENERATOR_IMAGE..."
79-
docker pull "$GENERATOR_IMAGE"
80-
81-
echo "Removing old client dir..."
82-
rm -rf "$(pwd)/out/$client_lang"
83-
84114
# Check if there is a configuration file available for this language
85115
if [ -e "./spec/config/$client_lang.yml" ]; then
86-
client_config="-c /local/spec/config/$client_lang.yml"
116+
client_config="-c /local/spec/config/$client_lang.yml"
87117
else
88-
client_config=""
118+
client_config=""
89119
fi
90120

91-
if [ $dap_spec -eq 1 ]; then
92-
./bin/transform --enterprise
93-
else
94-
./bin/transform --oss
95-
fi
121+
bin/transform --$appliance
122+
123+
echo "Pulling latest release $GENERATOR_IMAGE..."
124+
docker pull "$GENERATOR_IMAGE"
96125

97126
echo "Generating $client_lang client..."
98-
docker run --rm -v ${PWD}:/local -v $output_volume:/out "$GENERATOR_IMAGE" generate \
127+
docker run --rm \
128+
-v ${PWD}:/local \
129+
-v $output_volume:/out \
130+
"$GENERATOR_IMAGE" generate \
99131
-i "/local/$input_dir/openapi.yml" \
100132
-g "$client_lang" \
101-
-o "$output_dir" \
133+
-o "/out/" \
102134
$client_config \
103135
$template_arg
104136

105-
echo "Done! Client is in $output_dir folder!"
137+
echo "Done! Client is in $output_volume folder!"

0 commit comments

Comments
 (0)