Skip to content

Commit 4d1ed0f

Browse files
authored
feat: two separate service urls for oasbinder and enduser (#4)
1 parent c6db608 commit 4d1ed0f

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

.goreleaser.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Customization options: https://goreleaser.com/customization/
2+
version: 2
23
project_name: oasbinder
34
before:
45
hooks:
@@ -23,18 +24,21 @@ checksum:
2324
algorithm: sha512
2425
changelog:
2526
sort: asc
26-
dockers:
27-
- goos: linux
28-
goarch: amd64
29-
image_templates:
30-
- "ghcr.io/insightsengineering/{{ .ProjectName }}:{{ .Version }}"
31-
- "ghcr.io/insightsengineering/{{ .ProjectName }}:latest"
32-
skip_push: false
33-
build_flag_templates:
34-
- "--pull"
35-
- "--label=org.opencontainers.image.created={{ .Date }}"
36-
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
37-
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
38-
- "--label=org.opencontainers.image.version={{ .Version }}"
39-
- "--build-arg=PROJECT_NAME={{ .ProjectName }}"
40-
- "--platform=linux/amd64"
27+
kos:
28+
- repositories:
29+
- "ghcr.io/insightsengineering/oasbinder"
30+
tags:
31+
- "v{{.Version}}"
32+
- latest
33+
bare: true
34+
preserve_import_paths: false
35+
platforms:
36+
- linux/amd64
37+
- linux/arm64
38+
- darwin/amd64
39+
- darwin/arm64
40+
labels:
41+
"org.opencontainers.image.created": "{{ .Date }}"
42+
"org.opencontainers.image.title": "{{ .ProjectName }}"
43+
"org.opencontainers.image.revision": "{{ .FullCommit }}"
44+
"org.opencontainers.image.version": "{{ .Version }}"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ devdeps: ## Install development dependencies
2727
@printf "Executing target: [$@] 🎯\n"
2828
@which -a golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH) v1.51.2
2929
@which -a typex > /dev/null || go install github.com/dtgorski/typex@latest
30-
@which -a goreleaser > /dev/null || go install github.com/goreleaser/goreleaser@latest
30+
@which -a goreleaser > /dev/null || go install github.com/goreleaser/goreleaser/v2@latest
3131
@which -a gocover-cobertura > /dev/null || go install github.com/boumenot/gocover-cobertura@latest
3232
@which -a misspell > /dev/null || go install github.com/client9/misspell/cmd/misspell@latest
3333
@which -a gotestdox > /dev/null || go install github.com/bitfield/gotestdox/cmd/gotestdox@latest

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ Let's assume we have the following service in the configuration file and the use
88
```yaml
99
services:
1010
- endpoint: /hogwarts
11-
url: http://localhost:8000/hogwarts/
11+
url: http://host.docker.internal:8000/hogwarts/
12+
swagger_url: http://localhost:8000/hogwarts/
1213
```
1314
14-
User can request the OAS docs for the `hogwarts` microservice by going to <https://oasbinder.example.com/hogwarts> in the browser.
15-
16-
`oasbinder` will request the OAS specification from the service at <http://localhost:8000/hogwarts/openapi.json> and return it to the user for viewing and interacting in the browser.
17-
The location of the OAS specs is configurable.
18-
Multiple services can be configured and user can then select them from a drop-down list.
15+
* User can request the OAS docs for the microservice by going to `proxyAddress + endpoint` in the browser (in this example: <https://oasbinder.example.com/hogwarts>).
16+
* `oasbinder` will request the OAS specification from the service at <http://host.docker.internal:8000/hogwarts/openapi.json> and return it to the user for viewing and interacting in the browser.
17+
* When user interacts with the API in the browser, the requests to the API will be directed to <http://localhost:8000/hogwarts/>.
18+
* In many cases `url` can be equal to `swagger_url`. An example of a situation where they can be different is e.g. a docker-compose setup where both `oasbinder` and the service can communicate via internal Docker network. `oasbinder` can request the OAS specs using the internal Docker hostname, and the user will send the requests using SwaggerUI to the service from the outside of the cluster via `swagger_url`.
19+
* The location of the OAS specs (`openapi.json` by default) is configurable. Multiple services can be configured and user can then select them from a drop-down list.
20+
* The drop-down list will contain the name and decription of the service retrieved from the OAS specs fields: `.info.title` and `.info.summary`.
1921

2022
All the services will need to have CORS configured in a way which allows requests from <https://oasbinder.example.com>.
2123

@@ -52,15 +54,19 @@ Example contents of configuration file:
5254
```yaml
5355
# The address at which the user will access `oasbinder`.
5456
proxyAddress: http://localhost:8080
57+
# The address on which `oasbinder` will listen.
58+
listenAddress: 0.0.0.0
5559
# The port on which `oasbinder` will listen. This can be used in case `oasbinder` is run e.g. in a k8s cluster
5660
# and the user is accessing it from the outside of the cluster.
5761
listenPort: 8080
5862

5963
services:
6064
- endpoint: /gringotts
6165
url: http://localhost:8000/gringotts/
66+
swagger_url: http://localhost:8000/gringotts/
6267
- endpoint: /hogwarts
6368
url: http://localhost:8000/hogwarts/
69+
swagger_url: http://localhost:8000/hogwarts/
6470

6571
# Additional headers to pass to microservices, e.g. for authentication.
6672
headers:

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ in a way which makes interacting with the Swagger UI in the browser easy.`,
8383
fmt.Println(`listenAddress = "` + listenAddress + `"`)
8484
fmt.Println(`apiSpecsPath = "` + apiSpecsPath + `"`)
8585

86+
log.Debug("services = ", services)
87+
8688
serve()
8789
},
8890
}

cmd/server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var swaggerUITemplate string
2020

2121
// Microservice represents configuration for each microservice
2222
type Microservice struct {
23-
Name string `yaml:"name"`
24-
Endpoint string `yaml:"endpoint"`
25-
URL string `yaml:"url"`
23+
Endpoint string `mapstructure:"endpoint"`
24+
URL string `mapstructure:"url"`
25+
SwaggerURL string `mapstructure:"swagger_url"`
2626
}
2727

2828
type MicroserviceList struct {
@@ -138,8 +138,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
138138
for _, service := range services {
139139
// Retrieve name and summary of each microservice to construct a drop-down list.
140140
spec, serviceName, serviceSummary, err = GetOASSpec(service.URL)
141+
log.Debug("serviceEndpoint = ", service.Endpoint)
141142
if service.Endpoint == path {
142-
microserviceURL = service.URL
143+
microserviceURL = service.SwaggerURL
144+
log.Debug("microserviceURL = ", microserviceURL)
143145
// selectedSpec is the one which will be rendered by SwaggerUIBundle
144146
selectedSpec = spec
145147
if err != nil {

0 commit comments

Comments
 (0)