2015-08-18 05:57:27 +05:30
|
|
|
#!/bin/bash -eu
|
|
|
|
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
SCHEMA='worker'
|
|
|
|
else
|
|
|
|
SCHEMA=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $SCHEMA = "worker" ]; then
|
|
|
|
IN="schema/workerschema/v1.json"
|
|
|
|
OUT="schema/workerschema/v1-json.go"
|
|
|
|
GEN="schema/workerschema/v1-gen.go"
|
2016-02-02 05:39:39 +05:30
|
|
|
DOC="schema/workerschema/README.md"
|
2015-08-18 05:57:27 +05:30
|
|
|
GOPKG="workerschema"
|
|
|
|
elif [ $SCHEMA = 'admin' ]; then
|
|
|
|
IN="schema/adminschema/v1.json"
|
|
|
|
OUT="schema/adminschema/v1-json.go"
|
|
|
|
GEN="schema/adminschema/v1-gen.go"
|
2016-02-02 05:39:39 +05:30
|
|
|
DOC="schema/adminschema/README.md"
|
2015-08-18 05:57:27 +05:30
|
|
|
GOPKG="adminschema"
|
|
|
|
else
|
|
|
|
echo "Usage: generator [worker|admin]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-02 05:39:39 +05:30
|
|
|
GENDOC=bin/gendoc
|
|
|
|
|
|
|
|
if [ ! -f $GENDOC ]; then
|
|
|
|
echo "gendoc command line tool not found. please run build script at the top level of this repo"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-05-26 23:11:16 +05:30
|
|
|
go run schema/jsonfmt.go $IN
|
|
|
|
|
2016-02-02 05:39:39 +05:30
|
|
|
$GENDOC --f $IN --o $DOC
|
|
|
|
|
2016-04-06 23:56:29 +05:30
|
|
|
# Though google-api-go-generator is a main, dex vendors the app using the same
|
|
|
|
# tool it uses to vendor third party packages. Hence, it can be found in the
|
|
|
|
# "vendor" directory.
|
|
|
|
#
|
|
|
|
# This vendoring is currently done with godep, but may change if/when we move to
|
|
|
|
# another tool.
|
|
|
|
#
|
|
|
|
# See schema/generator_import.go for instructions on updating the dependency.
|
|
|
|
PKG="github.com/coreos/dex/vendor/google.golang.org/api/google-api-go-generator"
|
2015-08-18 05:57:27 +05:30
|
|
|
|
|
|
|
# First, write the discovery document into a go file so it can be served statically by the API
|
|
|
|
cat << EOF > "${OUT}"
|
|
|
|
package $GOPKG
|
|
|
|
//
|
|
|
|
// This file is automatically generated by schema/generator
|
|
|
|
//
|
|
|
|
// **** DO NOT EDIT ****
|
|
|
|
//
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo -n 'const DiscoveryJSON = `' >> ${OUT}
|
|
|
|
cat ${IN} >> "${OUT}"
|
|
|
|
echo -n '`' >> "${OUT}"
|
|
|
|
|
|
|
|
# Now build google-api-go-generator - we vendor so this is consistently reproducible
|
|
|
|
GEN_PATH="bin/google-api-go-generator"
|
|
|
|
if [ ! -f ${GEN_PATH} ]; then
|
2016-04-06 23:56:29 +05:30
|
|
|
go build -o ${GEN_PATH} ${PKG}
|
2015-08-18 05:57:27 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
# Build the bindings
|
|
|
|
GOPATH=${PWD}/gopath ./bin/google-api-go-generator \
|
|
|
|
-googleapi_pkg "google.golang.org/api/googleapi" \
|
|
|
|
-api_json_file "${IN}" \
|
|
|
|
-output "${GEN}"
|
|
|
|
|
|
|
|
# Finally, fix the import in the bindings to refer to the vendored google-api package
|
|
|
|
goimports -w ${GEN}
|
2016-06-16 00:11:26 +05:30
|
|
|
|
|
|
|
gofmt -w schema/${GOPKG}
|