Bumping k8s dependencies to 1.13
This commit is contained in:
90
vendor/github.com/googleapis/gnostic/gnostic.go
generated
vendored
90
vendor/github.com/googleapis/gnostic/gnostic.go
generated
vendored
@@ -41,6 +41,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/googleapis/gnostic/OpenAPIv2"
|
||||
@@ -92,7 +93,7 @@ type pluginCall struct {
|
||||
}
|
||||
|
||||
// Invokes a plugin.
|
||||
func (p *pluginCall) perform(document proto.Message, sourceFormat int, sourceName string) error {
|
||||
func (p *pluginCall) perform(document proto.Message, sourceFormat int, sourceName string, timePlugins bool) ([]*plugins.Message, error) {
|
||||
if p.Name != "" {
|
||||
request := &plugins.Request{}
|
||||
|
||||
@@ -112,7 +113,7 @@ func (p *pluginCall) perform(document proto.Message, sourceFormat int, sourceNam
|
||||
//
|
||||
invocationRegex := regexp.MustCompile(`^([\w-_\/\.]+=[\w-_\/\.]+(,[\w-_\/\.]+=[\w-_\/\.]+)*:)?[^,:=]+$`)
|
||||
if !invocationRegex.Match([]byte(p.Invocation)) {
|
||||
return fmt.Errorf("Invalid invocation of %s: %s", executableName, invocation)
|
||||
return nil, fmt.Errorf("Invalid invocation of %s: %s", executableName, invocation)
|
||||
}
|
||||
|
||||
invocationParts := strings.Split(p.Invocation, ":")
|
||||
@@ -145,11 +146,21 @@ func (p *pluginCall) perform(document proto.Message, sourceFormat int, sourceNam
|
||||
request.SourceName = sourceName
|
||||
switch sourceFormat {
|
||||
case SourceFormatOpenAPI2:
|
||||
request.Openapi2 = document.(*openapi_v2.Document)
|
||||
request.Surface, _ = surface.NewModelFromOpenAPI2(request.Openapi2)
|
||||
request.AddModel("openapi.v2.Document", document)
|
||||
// include experimental API surface model
|
||||
surfaceModel, err := surface.NewModelFromOpenAPI2(document.(*openapi_v2.Document))
|
||||
if err == nil {
|
||||
request.AddModel("surface.v1.Model", surfaceModel)
|
||||
}
|
||||
case SourceFormatOpenAPI3:
|
||||
request.Openapi3 = document.(*openapi_v3.Document)
|
||||
request.Surface, _ = surface.NewModelFromOpenAPI3(request.Openapi3)
|
||||
request.AddModel("openapi.v3.Document", document)
|
||||
// include experimental API surface model
|
||||
surfaceModel, err := surface.NewModelFromOpenAPI3(document.(*openapi_v3.Document))
|
||||
if err == nil {
|
||||
request.AddModel("surface.v1.Model", surfaceModel)
|
||||
}
|
||||
case SourceFormatDiscovery:
|
||||
request.AddModel("discovery.v1.Document", document)
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -158,19 +169,27 @@ func (p *pluginCall) perform(document proto.Message, sourceFormat int, sourceNam
|
||||
cmd := exec.Command(executableName, "-plugin")
|
||||
cmd.Stdin = bytes.NewReader(requestBytes)
|
||||
cmd.Stderr = os.Stderr
|
||||
pluginStartTime := time.Now()
|
||||
output, err := cmd.Output()
|
||||
pluginElapsedTime := time.Since(pluginStartTime)
|
||||
if timePlugins {
|
||||
fmt.Printf("> %s (%s)\n", executableName, pluginElapsedTime)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
response := &plugins.Response{}
|
||||
err = proto.Unmarshal(output, response)
|
||||
if err != nil {
|
||||
return err
|
||||
// Gnostic expects plugins to only write the
|
||||
// response message to stdout. Be sure that
|
||||
// any logging messages are written to stderr only.
|
||||
return nil, errors.New("Invalid plugin response (plugins must write log messages to stderr, not stdout).")
|
||||
}
|
||||
|
||||
plugins.HandleResponse(response, outputLocation)
|
||||
return response.Messages, nil
|
||||
}
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func isFile(path string) bool {
|
||||
@@ -233,10 +252,12 @@ type Gnostic struct {
|
||||
yamlOutputPath string
|
||||
jsonOutputPath string
|
||||
errorOutputPath string
|
||||
messageOutputPath string
|
||||
resolveReferences bool
|
||||
pluginCalls []*pluginCall
|
||||
extensionHandlers []compiler.ExtensionHandler
|
||||
sourceFormat int
|
||||
timePlugins bool
|
||||
}
|
||||
|
||||
// Initialize a structure to store global application state.
|
||||
@@ -244,20 +265,27 @@ func newGnostic() *Gnostic {
|
||||
g := &Gnostic{}
|
||||
// Option fields initialize to their default values.
|
||||
g.usage = `
|
||||
Usage: gnostic OPENAPI_SOURCE [OPTIONS]
|
||||
OPENAPI_SOURCE is the filename or URL of an OpenAPI description to read.
|
||||
Usage: gnostic SOURCE [OPTIONS]
|
||||
SOURCE is the filename or URL of an API description.
|
||||
Options:
|
||||
--pb-out=PATH Write a binary proto to the specified location.
|
||||
--text-out=PATH Write a text proto to the specified location.
|
||||
--json-out=PATH Write a json API description to the specified location.
|
||||
--yaml-out=PATH Write a yaml API description to the specified location.
|
||||
--errors-out=PATH Write compilation errors to the specified location.
|
||||
--PLUGIN-out=PATH Run the plugin named gnostic_PLUGIN and write results
|
||||
--messages-out=PATH Write messages generated by plugins to the specified
|
||||
location. Messages from all plugin invocations are
|
||||
written to a single common file.
|
||||
--PLUGIN-out=PATH Run the plugin named gnostic-PLUGIN and write results
|
||||
to the specified location.
|
||||
--PLUGIN Run the plugin named gnostic-PLUGIN but don't write any
|
||||
results. Used for plugins that return messages only.
|
||||
PLUGIN must not match any other gnostic option.
|
||||
--x-EXTENSION Use the extension named gnostic-x-EXTENSION
|
||||
to process OpenAPI specification extensions.
|
||||
--resolve-refs Explicitly resolve $ref references.
|
||||
This could have problems with recursive definitions.
|
||||
--time-plugins Report plugin runtimes.
|
||||
`
|
||||
// Initialize internal structures.
|
||||
g.pluginCalls = make([]*pluginCall, 0)
|
||||
@@ -292,6 +320,8 @@ func (g *Gnostic) readOptions() {
|
||||
g.yamlOutputPath = invocation
|
||||
case "errors":
|
||||
g.errorOutputPath = invocation
|
||||
case "messages":
|
||||
g.messageOutputPath = invocation
|
||||
default:
|
||||
p := &pluginCall{Name: pluginName, Invocation: invocation}
|
||||
g.pluginCalls = append(g.pluginCalls, p)
|
||||
@@ -302,6 +332,13 @@ func (g *Gnostic) readOptions() {
|
||||
g.extensionHandlers = append(g.extensionHandlers, extensionHandler)
|
||||
} else if arg == "--resolve-refs" {
|
||||
g.resolveReferences = true
|
||||
} else if arg == "--time-plugins" {
|
||||
g.timePlugins = true
|
||||
} else if arg[0] == '-' && arg[1] == '-' {
|
||||
// try letting the option specify a plugin with no output files (or unwanted output files)
|
||||
// this is useful for calling plugins like linters that only return messages
|
||||
p := &pluginCall{Name: arg[2:len(arg)], Invocation: "!"}
|
||||
g.pluginCalls = append(g.pluginCalls, p)
|
||||
} else if arg[0] == '-' {
|
||||
fmt.Fprintf(os.Stderr, "Unknown option: %s.\n%s\n", arg, g.usage)
|
||||
os.Exit(-1)
|
||||
@@ -467,6 +504,17 @@ func (g *Gnostic) writeJSONYAMLOutput(message proto.Message) {
|
||||
}
|
||||
}
|
||||
|
||||
// Write messages.
|
||||
func (g *Gnostic) writeMessagesOutput(message proto.Message) {
|
||||
protoBytes, err := proto.Marshal(message)
|
||||
if err != nil {
|
||||
writeFile(g.messageOutputPath, g.errorBytes(err), g.sourceName, "errors")
|
||||
defer os.Exit(-1)
|
||||
} else {
|
||||
writeFile(g.messageOutputPath, protoBytes, g.sourceName, "messages.pb")
|
||||
}
|
||||
}
|
||||
|
||||
// Perform all actions specified in the command-line options.
|
||||
func (g *Gnostic) performActions(message proto.Message) (err error) {
|
||||
// Optionally resolve internal references.
|
||||
@@ -490,17 +538,29 @@ func (g *Gnostic) performActions(message proto.Message) (err error) {
|
||||
if g.textOutputPath != "" {
|
||||
g.writeTextOutput(message)
|
||||
}
|
||||
// Optionaly write document in yaml and/or json formats.
|
||||
// Optionally write document in yaml and/or json formats.
|
||||
if g.yamlOutputPath != "" || g.jsonOutputPath != "" {
|
||||
g.writeJSONYAMLOutput(message)
|
||||
}
|
||||
// Call all specified plugins.
|
||||
messages := make([]*plugins.Message, 0)
|
||||
for _, p := range g.pluginCalls {
|
||||
err := p.perform(message, g.sourceFormat, g.sourceName)
|
||||
pluginMessages, err := p.perform(message, g.sourceFormat, g.sourceName, g.timePlugins)
|
||||
if err != nil {
|
||||
writeFile(g.errorOutputPath, g.errorBytes(err), g.sourceName, "errors")
|
||||
defer os.Exit(-1) // run all plugins, even when some have errors
|
||||
}
|
||||
messages = append(messages, pluginMessages...)
|
||||
}
|
||||
if g.messageOutputPath != "" {
|
||||
g.writeMessagesOutput(&plugins.Messages{Messages: messages})
|
||||
} else {
|
||||
// Print any messages from the plugins
|
||||
if len(messages) > 0 {
|
||||
for _, message := range messages {
|
||||
fmt.Printf("%+v\n", message)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user