Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ $ gwa apply --input gw-config.yaml
},
}

applyCmd.Flags().StringVarP(&opts.input, "input", "i", "gw-config.yml", "YAML file containing your configuration")
applyCmd.Flags().StringVarP(&opts.input, "input", "i", "", "YAML file containing your configuration")
applyCmd.MarkFlagRequired("input")

return applyCmd
Expand Down
7 changes: 4 additions & 3 deletions cmd/generateConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (o *GenerateConfigOptions) IsEmpty() bool {
}

func (o *GenerateConfigOptions) ValidateTemplate() error {
if o.Template == "kong-httpbin" || o.Template == "client-credentials-shared-idp" {
if o.Template == "kong-httpbin" || o.Template == "client-credentials-shared-idp" || o.Template == "quick-start" {
return nil
}
return fmt.Errorf("%s is not a valid template", o.Template)
Expand Down Expand Up @@ -90,7 +90,7 @@ func NewGenerateConfigCmd(ctx *pkg.AppContext) *cobra.Command {
Short: "Generate gateway resources based on pre-defined templates",
Args: cobra.OnlyValidArgs,
Example: heredoc.Doc(`
$ gwa generate-config --template kong-httpbin \
$ gwa generate-config --template quick-start \
--service my-service \
--upstream https://httpbin.org

Expand Down Expand Up @@ -144,7 +144,7 @@ $ gwa generate-config --template client-credentials-shared-idp \
}),
}

generateConfigCmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Name of a pre-defined template (kong-httpbin, client-credentials-shared-idp)")
generateConfigCmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Name of a pre-defined template (quick-start, client-credentials-shared-idp, kong-httpbin)")
generateConfigCmd.Flags().StringVarP(&opts.Service, "service", "s", "", "A unique service subdomain for your vanity url: https://<service>.api.gov.bc.ca")
generateConfigCmd.Flags().StringVarP(&opts.Upstream, "upstream", "u", "", "The upstream implementation of the API")
generateConfigCmd.Flags().StringVar(&opts.Organization, "org", "ministry-of-citizens-services", "Set the organization")
Expand Down Expand Up @@ -203,6 +203,7 @@ func initGenerateModel(ctx *pkg.AppContext, opts *GenerateConfigOptions) pkg.Gen
prompts[template] = pkg.NewList("Template", []string{
"client-credentials-shared-idp",
"kong-httpbin",
"quick-start",
})

prompts[upstream] = pkg.NewTextInput("Upstream (URL)", "", true)
Expand Down
35 changes: 35 additions & 0 deletions cmd/generateConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,38 @@ func TestClientCredentialsGenerator(t *testing.T) {
assert.Contains(t, compare, "paths: [/post]")
assert.Contains(t, compare, "allowed_aud: ap-cc-sampler-default-dev")
}

func TestQuickStartGenerator(t *testing.T) {
dir := t.TempDir()
ctx := &pkg.AppContext{
Cwd: dir,
}
opts := &GenerateConfigOptions{
Gateway: "cc-sampler",
Template: "quick-start",
Service: "my-service",
UpstreamPort: "443",
UpstreamUrl: &url.URL{
Host: "httpbin.org",
Path: "/post",
Scheme: "https",
},
Organization: "ministry-of-citizens-services",
OrganizationUnit: "databc",
Out: "gw-config.yaml",
}
err := GenerateConfig(ctx, opts)
if err != nil {
t.Fatal(err)
}
file, err := os.ReadFile(path.Join(ctx.Cwd, opts.Out))
if err != nil {
t.Fatal(err)
}
compare := string(file)
assert.Contains(t, compare, "name: my-service-dev")
assert.Contains(t, compare, "tags: [ns.cc-sampler]")
assert.Contains(t, compare, "url: https://httpbin.org/post")
assert.Contains(t, compare, "- my-service.dev.api.gov.bc.ca")
assert.Contains(t, compare, "paths: [/post]")
}
2 changes: 1 addition & 1 deletion cmd/templates/client-credentials-shared-idp.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ notes: Some information about the {{ .Service }} service
tags: [{{ kebabCase .Service }}, openapi]
license_title: Access Only
view_audience: Government
security_class: LOW-PUBLIC
security_class: Public
record_publish_date: '2021-05-27'
---
kind: Product
Expand Down
44 changes: 44 additions & 0 deletions cmd/templates/quick-start.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
kind: GatewayService
name: {{ kebabCase .Service }}-dev
tags: [ns.{{ .Gateway }}]
url: {{ .UpstreamUrl }}
protocol: {{ .UpstreamUrl.Scheme }}
routes:
- name: {{ kebabCase .Service }}-dev
tags: [ns.{{ .Gateway }}]
hosts:
- {{ kebabCase .Service }}.dev.api.gov.bc.ca
{{- if .UpstreamUrl.Path }}
paths: [{{ .UpstreamUrl.Path }}]
{{- end }}
---
kind: DraftDataset
name: {{ kebabCase .Service }}-dataset
title: {{ .Service }}
organization: {{ .Organization }}
organizationUnit: {{ .OrganizationUnit }}
notes: |
The {{ .Service }} API is a versatile toolset for developers.
{{ .Service }} API offers a variety of endpoints to streamline application development.

The endpoints in this API are accessible without authentication.

To learn more about the API, visit the {{ .Service }} API [developer site](https://your-api-developer-site.com)
or view the [API specification](https://openapi.apps.gov.bc.ca/?url=https://your-api-developer-site.com/openapi.yaml).

Use the following URLs to access this API:
- Development environment: https://{{ kebabCase .Service }}.dev.api.gov.bc.ca{{- if .UpstreamUrl.Path }}{{ .UpstreamUrl.Path }}{{- end }}
tags: [{{ kebabCase .Service }}, openapi]
license_title: Access Only
security_class: PUBLIC
record_publish_date: '2024-01-01'
---
kind: Product
name: {{ .Service }} API
dataset: {{ kebabCase .Service }}-dataset
environments:
- name: dev
active: false
approval: false
flow: public
services: [{{ kebabCase .Service }}-dev]