Skip to content

Commit

Permalink
Ambassador - Provide possibility to disable everything at root level …
Browse files Browse the repository at this point in the history
…- with corresponding possibility to enable at path/method level (#163)

* enable operation override when path is disabled. This allows for a blanket disable on all operations on path and then can expose operations when they are deemed ready by overriding the disabled field at the operation level

* Add global level disable option to enable blanket disable on all paths
and operations. Paths and Operations can then be enabled when they are
deemed to be ready by overriding the disabled field at the path and
field levels.

Change disabled field in SubOptions from boolean to pointer to a boolean
to implement the following semantics:
- If nil, not explicitely set, then check for value at level above -
 if at operation, check path level. If at path level, check global
level
- If has a value be it True or False, disregard the disabled setting at
  the level above as it has been explicitely set

Implement useful helper methods IsOperationDisabled and IsPathDisabled
with the Option struct reciever which implement the semantics listed
above

* Update generator to reflect the fact that the disabled field is now a
boolean pointer. Use Options helper methods for determining whether a
path or operation is disabled

* Update tests to reflect the fact that disabled is now a boolean pointer
for SubOptions

* Update traefik to use option helper methods for checking if path/operation is disabled
  • Loading branch information
Kyle Hodgetts committed Sep 15, 2021
1 parent ffc9022 commit d4b366f
Show file tree
Hide file tree
Showing 8 changed files with 597 additions and 396 deletions.
22 changes: 8 additions & 14 deletions generators/ambassador/ambassador.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,18 @@ func (g *Generator) Generate(opts *options.Options, spec *openapi3.T) (string, e
host := opts.Host

for path, pathItem := range spec.Paths {
pathSubOptions, ok := opts.PathSubOptions[path]
if ok {
if pathSubOptions.Disabled {
continue
}
}
pathSubOptions, _ := opts.PathSubOptions[path]

if pathSubOptions.Host != "" && pathSubOptions.Host != host {
host = pathSubOptions.Host
}

for method, operation := range pathItem.Operations() {
opSubOptions, ok := opts.OperationSubOptions[method+path]
if ok {
if opSubOptions.Disabled {
continue
}
if opts.IsOperationDisabled(path, method) {
continue
}

opSubOptions := opts.OperationSubOptions[method+path]
if opSubOptions.Host != "" && opSubOptions.Host != host {
host = opSubOptions.Host
}
Expand Down Expand Up @@ -265,7 +258,7 @@ func (g *Generator) Generate(opts *options.Options, spec *openapi3.T) (string, e
mappings = append(mappings, op)
}
}
} else {
} else if !opts.Disabled {
op := mappingTemplateData{
MappingName: opts.Service.Name,
MappingNamespace: opts.Namespace,
Expand Down Expand Up @@ -423,9 +416,10 @@ func (g *Generator) shouldSplit(opts *options.Options, spec *openapi3.T) bool {
}

for path, pathItem := range spec.Paths {

if pathSubOptions, ok := opts.PathSubOptions[path]; ok {
// a path is disabled
if pathSubOptions.Disabled {
if opts.IsPathDisabled(path) {
return true
}

Expand All @@ -451,7 +445,7 @@ func (g *Generator) shouldSplit(opts *options.Options, spec *openapi3.T) bool {
for method := range pathItem.Operations() {
if opSubOptions, ok := opts.OperationSubOptions[method+path]; ok {
// an operation is disabled
if opSubOptions.Disabled {
if opts.IsOperationDisabled(path, method) {
return true
}

Expand Down
Loading

0 comments on commit d4b366f

Please sign in to comment.