diff --git a/client/console_client.go b/client/console_client.go index d7c89b7..78e4593 100644 --- a/client/console_client.go +++ b/client/console_client.go @@ -254,12 +254,15 @@ func (client *Client) Apply(resource *resource.Resource, dryMode bool) (string, if !ok { return "", fmt.Errorf("kind %s not found", resource.Kind) } - applyPath, err := kind.ApplyPath(resource) + applyQueryInfo, err := kind.ApplyPath(resource) if err != nil { return "", err } - url := client.baseUrl + applyPath + url := client.baseUrl + applyQueryInfo.Path builder := client.client.R().SetBody(resource.Json) + for _, param := range applyQueryInfo.QueryParams { + builder.SetQueryParam(param.Name, param.Value) + } if dryMode { builder = builder.SetQueryParam("dryMode", "true") } diff --git a/client/gateway_client.go b/client/gateway_client.go index 8499afb..4c4ad97 100644 --- a/client/gateway_client.go +++ b/client/gateway_client.go @@ -275,12 +275,15 @@ func (client *GatewayClient) Apply(resource *resource.Resource, dryMode bool) (s if !ok { return "", fmt.Errorf("kind %s not found", resource.Kind) } - applyPath, err := kind.ApplyPath(resource) + applyQueryInfo, err := kind.ApplyPath(resource) if err != nil { return "", err } - url := client.baseUrl + applyPath + url := client.baseUrl + applyQueryInfo.Path builder := client.client.R().SetBody(resource.Json) + for _, param := range applyQueryInfo.QueryParams { + builder.SetQueryParam(param.Name, param.Value) + } if dryMode { builder = builder.SetQueryParam("dryMode", "true") } diff --git a/schema/kind.go b/schema/kind.go index a7c6c10..178325e 100644 --- a/schema/kind.go +++ b/schema/kind.go @@ -17,6 +17,7 @@ type KindVersion interface { GetListPath() string GetName() string GetParentPathParam() []string + GetParentQueryParam() []string GetOrder() int GetListQueryParamter() map[string]QueryParameterOption GetApplyExample() string @@ -38,6 +39,7 @@ type ConsoleKindVersion struct { ListPath string Name string ParentPathParam []string + ParentQueryParam []string ListQueryParamter map[string]QueryParameterOption ApplyExample string Order int `json:1000` //same value DefaultPriority @@ -59,6 +61,10 @@ func (c *ConsoleKindVersion) GetParentPathParam() []string { return c.ParentPathParam } +func (c *ConsoleKindVersion) GetParentQueryParam() []string { + return c.ParentQueryParam +} + func (c *ConsoleKindVersion) GetOrder() int { return c.Order } @@ -76,6 +82,7 @@ type GatewayKindVersion struct { ListPath string Name string ParentPathParam []string + ParentQueryParam []string ListQueryParameter map[string]QueryParameterOption GetAvailable bool ApplyExample string @@ -94,6 +101,10 @@ func (g *GatewayKindVersion) GetParentPathParam() []string { return g.ParentPathParam } +func (g *GatewayKindVersion) GetParentQueryParam() []string { + return g.ParentQueryParam +} + func (g *GatewayKindVersion) GetApplyExample() string { return g.ApplyExample } @@ -222,6 +233,16 @@ func (Kind *Kind) GetName() string { panic("No kindVersion in kind") //should never happen } +type QueryInfo struct { + Path string + QueryParams []QueryParam +} + +type QueryParam struct { + Name string + Value string +} + func (kind *Kind) ListPath(parentPathValues []string) string { kindVersion := kind.GetLatestKindVersion() if len(parentPathValues) != len(kindVersion.GetParentPathParam()) { @@ -238,20 +259,34 @@ func (kind *Kind) DescribePath(parentPathValues []string, name string) string { return kind.ListPath(parentPathValues) + "/" + name } -func (kind *Kind) ApplyPath(resource *resource.Resource) (string, error) { +func (kind *Kind) ApplyPath(resource *resource.Resource) (QueryInfo, error) { kindVersion, ok := kind.Versions[extractVersionFromApiVersion(resource.Version)] if !ok { - return "", fmt.Errorf("Could not find version %s for kind %s", resource.Version, resource.Kind) + return QueryInfo{}, fmt.Errorf("Could not find version %s for kind %s", resource.Version, resource.Kind) } parentPathValues := make([]string, len(kindVersion.GetParentPathParam())) + var parentQueryValues []QueryParam var err error for i, param := range kindVersion.GetParentPathParam() { parentPathValues[i], err = resource.StringFromMetadata(param) if err != nil { - return "", err + return QueryInfo{}, err + } + } + for _, param := range kindVersion.GetParentQueryParam() { + var value string + value, err = resource.StringFromMetadata(param) + if err == nil { + parentQueryValues = append(parentQueryValues, QueryParam{ + Name: param, + Value: value, + }) } } - return kind.ListPath(parentPathValues), nil + return QueryInfo{ + Path: kind.ListPath(parentPathValues), + QueryParams: parentQueryValues, + }, nil } func (kind *Kind) DeletePath(resource *resource.Resource) (string, error) { @@ -260,5 +295,5 @@ func (kind *Kind) DeletePath(resource *resource.Resource) (string, error) { return "", err } - return applyPath + "/" + resource.Name, nil + return applyPath.Path + "/" + resource.Name, nil } diff --git a/schema/schema.go b/schema/schema.go index e335ed7..f0d7429 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -82,9 +82,10 @@ func buildConsoleKindVersion(s *Schema, path, kind string, order int, put *v3hig for _, putParameter := range put.Parameters { if putParameter.In == "path" && *putParameter.Required { newKind.ParentPathParam = append(newKind.ParentPathParam, putParameter.Name) - } - + if putParameter.In == "query" && putParameter.Name != "dryMode" { + newKind.ParentQueryParam = append(newKind.ParentQueryParam, putParameter.Name) + } } for _, getParameter := range get.Parameters { if getParameter.In == "query" {