forked from RedHatInsights/export-service-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (76 loc) · 4.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
OS := $(shell uname)
UNAME_S := $(shell uname -s)
OS_SED :=
ifeq ($(UNAME_S),Darwin)
OS_SED += ""
endif
OCI_TOOL=$(shell command -v podman || command -v docker)
DOCKER_COMPOSE = $(OCI_TOOL)-compose
CONTAINER_TAG="quay.io/cloudservices/export-service-go"
help:
@echo "Please use \`make <target>' where <target> is one of:"
@echo ""
@echo "--- General Commands ---"
@echo "help show this message"
@echo "lint runs go lint on the project"
@echo "vet runs go vet on the project"
@echo "build builds the container image"
@echo "spec convert the openapi spec yaml to json"
@echo "docker-up-db start the export-service postgres db"
@echo ""
vet:
go vet
lint:
golint
build:
$(OCI_TOOL) build . -t $(CONTAINER_TAG)
build-local:
go build -o export-service cmd/export-service/*.go
spec:
ifeq (, $(shell which yq))
echo "yq is not installed"
else
@yq -o=json eval static/spec/openapi.yaml > static/spec/openapi.json
@yq -o=json eval static/spec/private.yaml > static/spec/private.json
endif
docker-down:
$(DOCKER_COMPOSE) down --remove-orphans
docker-up-db:
$(DOCKER_COMPOSE) up -d db
@until pg_isready -h $${POSTGRES_SQL_SERVICE_HOST:-localhost} -p $${POSTGRES_SQL_SERVICE_PORT:-5432} >/dev/null ; do \
printf '.'; \
sleep 0.5 ; \
done
docker-up-no-server: docker-up-db
$(DOCKER_COMPOSE) up -d kafka s3 s3-createbucket
monitor-topic:
$(OCI_TOOL) exec -ti kafka /usr/bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic platform.export.requests
run-api: build-local migrate_db
KAFKA_BROKERS=localhost:9092 DEBUG=true MINIO_PORT=9099 AWS_ACCESS_KEY=minio AWS_SECRET_ACCESS_KEY=minioadmin PSKS=testing-a-psk PUBLIC_PORT=8000 METRICS_PORT=9090 PRIVATE_PORT=10010 PGSQL_PORT=5432 ./export-service api_server
migrate_db: build-local
PGSQL_PORT=5432 ./export-service migrate_db upgrade
run: docker-up-no-server run-api
sample-request-create-export:
@curl -sS -X POST http://localhost:8000/api/export/v1/exports -H "x-rh-identity: eyJpZGVudGl0eSI6IHsiYWNjb3VudF9udW1iZXIiOiJhY2NvdW50MTIzIiwib3JnX2lkIjoib3JnMTIzIiwidHlwZSI6IlVzZXIiLCJ1c2VyIjp7ImlzX29yZ19hZG1pbiI6dHJ1ZX0sImludGVybmFsIjp7Im9yZ19pZCI6Im9yZzEyMyJ9fX0K" -H "Content-Type: application/json" -d @example_export_request.json > response.json
@cat response.json | jq
@cat response.json | jq -r '.id' | xargs -I {} echo "EXPORT_ID: {}"
@cat response.json | jq -r '.sources[] | "EXPORT_APPLICATION: \(.application)\nEXPORT_RESOURCE: \(.id)\n---"'
@rm response.json
sample-request-get-exports:
curl -X GET http://localhost:8000/api/export/v1/exports -H "x-rh-identity: eyJpZGVudGl0eSI6IHsiYWNjb3VudF9udW1iZXIiOiJhY2NvdW50MTIzIiwib3JnX2lkIjoib3JnMTIzIiwidHlwZSI6IlVzZXIiLCJ1c2VyIjp7ImlzX29yZ19hZG1pbiI6dHJ1ZX0sImludGVybmFsIjp7Im9yZ19pZCI6Im9yZzEyMyJ9fX0K" | jq
# set the variables below based your info from the request above
EXPORT_ID=5a252691-b241-4ef5-a0c4-4b64b96faf61
EXPORT_APPLICATION=exampleApplication
EXPORT_RESOURCE=ee3453cb-eb84-4258-b5f4-228c0fc73719
sample-request-export-status:
curl -X GET http://localhost:8000/api/export/v1/exports/$(EXPORT_ID)/status -H "x-rh-identity: eyJpZGVudGl0eSI6IHsiYWNjb3VudF9udW1iZXIiOiJhY2NvdW50MTIzIiwib3JnX2lkIjoib3JnMTIzIiwidHlwZSI6IlVzZXIiLCJ1c2VyIjp7ImlzX29yZ19hZG1pbiI6dHJ1ZX0sImludGVybmFsIjp7Im9yZ19pZCI6Im9yZzEyMyJ9fX0K" | jq
sample-request-export-download:
curl -X GET http://localhost:8000/api/export/v1/exports/$(EXPORT_ID) -H "x-rh-identity: eyJpZGVudGl0eSI6IHsiYWNjb3VudF9udW1iZXIiOiJhY2NvdW50MTIzIiwib3JnX2lkIjoib3JnMTIzIiwidHlwZSI6IlVzZXIiLCJ1c2VyIjp7ImlzX29yZ19hZG1pbiI6dHJ1ZX0sImludGVybmFsIjp7Im9yZ19pZCI6Im9yZzEyMyJ9fX0K" -f --output ./export_download.zip
sample-request-internal-upload:
curl -X POST http://localhost:10010/app/export/v1/${EXPORT_ID}/${EXPORT_APPLICATION}/${EXPORT_RESOURCE}/upload -H "x-rh-exports-psk: testing-a-psk" -H "Content-Type: application/json" -d @example_export_upload.json
sample-request-internal-error:
curl -X POST http://localhost:10010/app/export/v1/${EXPORT_ID}/${EXPORT_APPLICATION}/${EXPORT_RESOURCE}/error -H "x-rh-exports-psk: testing-a-psk" -H "Content-Type: application/json" -d @example_export_error.json
make test:
ginkgo -r --race --randomize-all --randomize-suites
test-sql:
go test ./... -tags=sql -count=1