Skip to content

Commit a2331fc

Browse files
committed
Update client gen script
Fixes bug where the old client was never removed due to the change to output dir location from out/<lang> to out/<appliance>/<lang>. Updates script to require a language argument.
1 parent 8a33b3e commit a2331fc

File tree

3 files changed

+102
-70
lines changed

3 files changed

+102
-70
lines changed

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!"

bin/lint_tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
echo "Linting Python integration tests:"
44

5-
./bin/generate_client --enterprise
5+
./bin/generate_client --enterprise -l python
66

77
docker run --rm \
88
-v ${PWD}/test/python:/code/test \

test/python/k8s/start

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fi
8787

8888
if [ $no_regen_client -eq 0 ]; then
8989
announce "Generating Python Client"
90-
./bin/generate_client python
90+
./bin/generate_client -l python
9191
fi
9292

9393
# Set up Conjur K8s cluster and local Docker Registry

0 commit comments

Comments
 (0)