diff --git a/.golangci.yaml b/.golangci.yaml index 0c840a3..f93a600 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -11,7 +11,6 @@ linters: - errorlint - forbidigo - forcetypeassert - - funlen - gocognit - goconst - gocyclo @@ -23,13 +22,11 @@ linters: - govet - importas - ineffassign - - lll - makezero - misspell - nakedret - nestif - nilerr - - nlreturn - prealloc - revive - staticcheck @@ -37,7 +34,6 @@ linters: - unconvert - unused - whitespace - - wsl linters-settings: gocognit: diff --git a/Taskfile.yml b/Taskfile.yml index 5feea90..77889ec 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -15,11 +15,11 @@ tasks: cmds: - rm -rf {{.GEN_OUT_DIR}} - GEN_OUT_DIR={{.GEN_OUT_DIR}} go run -tags=generator ./generator/... + - task: fmt-imports generate: cmds: - task: get-openapi-spec - task: go-generate - - task: fmt-imports test: cmds: - go test -v ./... diff --git a/client.go b/client.go index c615016..f69c929 100644 --- a/client.go +++ b/client.go @@ -77,11 +77,9 @@ type aivenClient struct { // OperationIDKey is the key used to store the operation ID in the context. type OperationIDKey struct{} -func (d *aivenClient) Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) { +func (d *aivenClient) Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) { ctx = context.WithValue(ctx, OperationIDKey{}, operationID) - var rsp *http.Response - var err error if d.Debug { @@ -105,7 +103,7 @@ func (d *aivenClient) Do(ctx context.Context, operationID, method, path string, }() } - rsp, err = d.do(ctx, method, path, v) + rsp, err = d.do(ctx, method, path, in, query...) if err != nil { return nil, err } @@ -122,11 +120,11 @@ func (d *aivenClient) Do(ctx context.Context, operationID, method, path string, return b, err } -func (d *aivenClient) do(ctx context.Context, method, path string, v any) (*http.Response, error) { +func (d *aivenClient) do(ctx context.Context, method, path string, in any, query ...[2]string) (*http.Response, error) { var body io.Reader - if !(v == nil || isEmpty(v)) { - b, err := json.Marshal(v) + if !(in == nil || isEmpty(in)) { + b, err := json.Marshal(in) if err != nil { return nil, err } @@ -143,13 +141,19 @@ func (d *aivenClient) do(ctx context.Context, method, path string, v any) (*http req.Header.Set("User-Agent", d.UserAgent) req.Header.Set("Authorization", "aivenv1 "+d.Token) - // TODO: BAD hack to get around pagination in most cases - // we should implement this properly at some point but for now - // that should be its own issue - query := req.URL.Query() - query.Add("limit", "999") - req.URL.RawQuery = query.Encode() + q := req.URL.Query() + for _, v := range query { + q.Set(v[0], v[1]) + } + + if !q.Has("limit") { + // TODO: BAD hack to get around pagination in most cases + // we should implement this properly at some point but for now + // that should be its own issue + q.Set("limit", "999") + } + req.URL.RawQuery = q.Encode() return d.doer.Do(req) } diff --git a/client_generated.go b/client_generated.go index 7a3d7bc..e311dc5 100644 --- a/client_generated.go +++ b/client_generated.go @@ -42,8 +42,9 @@ import ( vpc "github.com/aiven/go-client-codegen/handler/vpc" ) +// doer http client type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } func newClient(doer doer) Client { diff --git a/client_test.go b/client_test.go index 9b6792f..68c02f3 100644 --- a/client_test.go +++ b/client_test.go @@ -8,11 +8,13 @@ import ( "net/http/httptest" "os" "strings" + "sync/atomic" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/aiven/go-client-codegen/handler/clickhouse" "github.com/aiven/go-client-codegen/handler/service" ) @@ -41,24 +43,44 @@ func TestNewClient(t *testing.T) { } func TestServiceCreate(t *testing.T) { + var callCount int64 + // Creates a test server - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Equal(t, "/v1/project/foo/service", r.URL.Path) - - // Validates request - expectIn := new(service.ServiceCreateIn) - err := json.NewDecoder(r.Body).Decode(expectIn) - assert.NoError(t, err) - assert.Equal(t, "foo", expectIn.ServiceName) - assert.Equal(t, "kafka", expectIn.ServiceType) - assert.Regexp(t, `go-client-codegen/[0-9\.]+ unit-test`, r.Header["User-Agent"]) - - // Creates response - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, err = w.Write([]byte(`{"service": {"plan": "wow", "state": "RUNNING"}}`)) - require.NoError(t, err) - })) + mux := http.NewServeMux() + mux.HandleFunc( + "/v1/project/aiven-project/service", + func(w http.ResponseWriter, r *http.Request) { + // Validates request + expectIn := new(service.ServiceCreateIn) + err := json.NewDecoder(r.Body).Decode(expectIn) + assert.NoError(t, err) + assert.Equal(t, "my-clickhouse", expectIn.ServiceName) + assert.Equal(t, "clickhouse", expectIn.ServiceType) + assert.Regexp(t, `go-client-codegen/[0-9\.]+ unit-test`, r.Header["User-Agent"]) + + // Creates response + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, err = w.Write([]byte(`{"service": {"plan": "wow", "state": "RUNNING"}}`)) + require.NoError(t, err) + atomic.AddInt64(&callCount, 1) + }, + ) + mux.HandleFunc( + "/v1/project/aiven-project/service/my-clickhouse/clickhouse/query/stats", + func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, r.URL.RawQuery, "limit=1&order_by=max_time%3Aasc") + + // Creates response + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, err := w.Write([]byte(`{"queries": [{"calls": 1}]}`)) + require.NoError(t, err) + atomic.AddInt64(&callCount, 1) + }, + ) + + server := httptest.NewServer(mux) defer server.Close() // Points a new client to the server url @@ -68,12 +90,27 @@ func TestServiceCreate(t *testing.T) { // Makes create request in := &service.ServiceCreateIn{ - ServiceName: "foo", - ServiceType: "kafka", + ServiceName: "my-clickhouse", + ServiceType: "clickhouse", } - out, err := c.ServiceCreate(context.Background(), "foo", in) + + ctx := context.Background() + project := "aiven-project" + out, err := c.ServiceCreate(ctx, project, in) require.NoError(t, err) require.NotNil(t, out) assert.Equal(t, "wow", out.Plan) assert.Equal(t, service.ServiceStateTypeRunning, out.State) + + // Validates query params + stats, err := c.ServiceClickHouseQueryStats( + ctx, project, in.ServiceName, + clickhouse.ServiceClickHouseQueryStatsLimit(1), + clickhouse.ServiceClickHouseQueryStatsOrderByType(clickhouse.OrderByTypeMaxTimeasc), + ) + require.NoError(t, err) + assert.Len(t, stats, 1) + + // All calls are received + assert.EqualValues(t, 2, callCount) } diff --git a/generator/main.go b/generator/main.go index 43e74e4..6a15982 100644 --- a/generator/main.go +++ b/generator/main.go @@ -12,6 +12,7 @@ import ( "regexp" "sort" "strings" + "sync" "time" "github.com/dave/jennifer/jen" @@ -43,15 +44,30 @@ var ( pathVersioning = regexp.MustCompile(`^/v[0-9]/`) ) +var strFormatters = map[SchemaType]string{ + SchemaTypeInteger: "%d", + SchemaTypeNumber: "%f", + SchemaTypeString: "%s", + SchemaTypeBoolean: "%t", +} + func main() { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}) err := exec() if err != nil { - log.Err(err) + log.Err(err).Send() } } +const ( + doerName = "doer" + handlerTypeName = "Handler" + queryParamName = "query" + queryParamTypeName = "queryParam" + queryParamArraySize = 2 +) + // nolint:funlen,gocognit,gocyclo // It's a generator, it's supposed to be long, and we won't expand it. func exec() error { cfg := new(envConfig) @@ -105,7 +121,6 @@ func exec() error { if pkg == "" { log.Error().Msgf("%q id not found in config!", p.ID) - continue } @@ -121,12 +136,6 @@ func exec() error { return fmt.Errorf("param %q not found", ref.Ref) } - if param.In != ParameterInPath { - log.Printf("%q param %s in %q", p.OperationID, param.Name, param.In) - - continue - } - if param.Name == "version_id" { param.Schema.Type = SchemaTypeInteger } @@ -139,27 +148,28 @@ func exec() error { } } - const doerName = "doer" - ctx := jen.Id("ctx").Qual("context", "Context") - doer := jen.Type().Id(doerName).Interface( + doer := jen.Comment(doerName + " http client").Line().Type().Id(doerName).Interface( jen.Id("Do").Params( ctx, jen.List(jen.Id("operationID"), jen.Id("method"), jen.Id("path")).String(), - jen.Id("v").Any(), + jen.Id("in").Any(), + jen.Id(queryParamName).Op("...").Add(fmtQueryParamType()), ).Parens(jen.List(jen.Index().Byte(), jen.Error())), ).Line() + + // A private type to limit query params to the declared keys/values list + queryParamType := jen.Type().Id(queryParamTypeName).Index(jen.Lit(queryParamArraySize)).String() + clientFields := make([]jen.Code, 0, len(pkgs)) clientValues := jen.Dict{} clientTypeValues := make([]jen.Code, 0, len(pkgs)) for _, pkg := range sortedKeys(pkgs) { - const handlerType = "Handler" - paths := pkgs[pkg] fileName := strings.ToLower(pkg) - handlerName := pkg + handlerType - newHandler := "New" + handlerType + handlerName := pkg + handlerTypeName + newHandler := "New" + handlerTypeName scope := make(map[string]*Schema) for _, p := range paths { @@ -172,35 +182,71 @@ func exec() error { file := jen.NewFile(fileName) file.HeaderComment(generatedHeader) - handler := file.Type().Id(handlerType) + + // Creates the handler's type (interface) + // Reserves the line in the file + handlerType := file.Type().Id(handlerTypeName) + + // Adds private types (interfaces) + privateTypes := file.Add(doer) + + // We want to add the query params type when there is any param + addQueryParams := new(sync.Once) + + // Creates the "new" constructor file.Func().Id(newHandler).Params(jen.Id(doerName).Id(doerName)).Id(handlerName).Block( jen.Return(jen.Id(handlerName).Values(jen.Id(doerName))), ) - file.Add(doer) + + // Creates the handler's implementation file.Type().Id(handlerName).Struct(jen.Id(doerName).Id(doerName)) var typeMethods []jen.Code - for _, path := range paths { // todo: support 204 out := path.Out.OK.Content["application/json"] if out == nil && path.Out.NoContent.Content == nil { log.Printf("%q has no json response. Skipping", path.OperationID) - continue } + // Method's schemas and query params schemas := make([]*Schema, 0) - params := make([]jen.Code, 0, len(path.Parameters)) - params = append(params, ctx) + queryParams := make([]*Schema, 0) + + // Interface and implementation args + funcArgs := []jen.Code{ctx} + // Collects params: in path and in query + // Adds to schemas to render enums for _, p := range path.Parameters { - p.Schema.in = true p.Schema.required = true p.Schema.init(doc, scope, p.Name) - schemas = append(schemas, p.Schema) - param := jen.Id(strcase.ToLowerCamel(p.Schema.CamelName)).Add(getType(p.Schema)) - params = append(params, param) + + if p.In == ParameterInPath { + schemas = append(schemas, p.Schema) + param := jen.Id(p.Schema.lowerCamel()).Add(getType(p.Schema)) + funcArgs = append(funcArgs, param) + continue + } + + // Adds query params type once + addQueryParams.Do(func() { + privateTypes.Add( + jen.Comment(queryParamTypeName+" http query params private type").Line(), + queryParamType.Clone().Line(), + ) + }) + + queryParams = append(queryParams, p.Schema) + + // Adds param function (request modifier) + var code *jen.Statement + code, err = fmtQueryParam(path.FuncName, p) + if err != nil { + return err + } + file.Add(code) } in := path.In.Content["application/json"] @@ -213,14 +259,18 @@ func exec() error { } schemaIn.in = true - schemaIn.init(doc, scope, path.FuncName) schemas = append(schemas, schemaIn) - params = append(params, jen.Id("in").Id("*"+schemaIn.CamelName)) + funcArgs = append(funcArgs, jen.Id("in").Id("*"+schemaIn.CamelName)) + } + + // Adds queryParams options + if len(queryParams) > 0 { + funcArgs = append(funcArgs, jen.Id(queryParamName).Op("...").Id(queryParamTypeName)) } - typeMeth := jen.Id(path.FuncName).Params(params...) - structMeth := jen.Func().Params(jen.Id("h").Id("*" + handlerName)).Id(path.FuncName).Params(params...) + typeMeth := jen.Id(path.FuncName).Params(funcArgs...) + structMeth := jen.Func().Params(jen.Id("h").Id("*" + handlerName)).Id(path.FuncName).Params(funcArgs...) var rsp, schemaOut *Schema if out != nil { @@ -230,7 +280,6 @@ func exec() error { } schemaOut.out = true - schemaOut.init(doc, scope, path.FuncName) rsp = getResponse(schemaOut) } @@ -254,33 +303,36 @@ func exec() error { typeMethods = append(typeMethods, path.Comment(), typeMeth.Line()) + // Crates a go formattable path, i.e.: + // /foo/{foo}/ => /foo/%s/ paramIndex := -1 url := pathClean.ReplaceAllStringFunc(path.Path, func(_ string) string { paramIndex++ - - switch t := path.Parameters[paramIndex].Schema.Type; t { - case SchemaTypeInteger: - return "%d" - case SchemaTypeString: - return "%s" - default: + t, ok := strFormatters[path.Parameters[paramIndex].Schema.Type] + if !ok { panic(fmt.Sprintf("%s unexpected parameter type %s", path.OperationID, t)) } + return t }) - urlParams := make([]jen.Code, 0, len(params)) + + urlParams := make([]jen.Code, 0, len(funcArgs)) urlParams = append(urlParams, jen.Lit(url)) inObj := jen.Nil() - for _, s := range schemas { if s.isObject() { inObj = jen.Id("in") - continue } - v := jen.Id(strcase.ToLowerCamel(s.CamelName)) + v := jen.Id(s.lowerCamel()) + if s.isEnum() { + // Stringifies enums + v = jen.String().Call(v) + } + + // Escapes string values if s.Type == SchemaTypeString { - v = jen.Id("url.PathEscape").Call(v) + v = jen.Qual("net/url", "PathEscape").Call(v) } urlParams = append(urlParams, v) @@ -289,6 +341,7 @@ func exec() error { outObj := jen.Id("_") returnErr := jen.Return(jen.Err()) + // Formats "return" statement if rsp != nil { outObj = jen.Id("b") @@ -308,24 +361,43 @@ func exec() error { } } - block := []jen.Code{ - jen.Id("path").Op(":=").Qual("fmt", "Sprintf").Call(urlParams...), - jen.List(outObj, jen.Err()).Op(":=").Id("h.doer.Do").Call( - jen.Id("ctx"), - jen.Lit(path.OperationID), - jen.Lit(path.Method), - jen.Id("path"), - inObj, - ), + // The Doer call + callOpts := []jen.Code{ + jen.Id("ctx"), + jen.Lit(path.OperationID), + jen.Lit(path.Method), + jen.Id("path"), + inObj, } - ifErr := jen.If(jen.Err().Op("!=").Nil()).Block(returnErr) + var block []jen.Code + + // Adds unpacking for query params + if len(queryParams) > 1 { + q := jen.Id(queryParamName) + p := jen.Id("p") + v := jen.Id("v") + callOpts = append(callOpts, p.Clone().Op("...")) + block = append( + block, + p.Clone().Op(":=").Make(jen.Index().Index(jen.Lit(queryParamArraySize)).String(), jen.Lit(0), jen.Len(q)), + jen.For(jen.List(jen.Id("_"), v.Clone().Op(":=").Range().Add(jen.Id(queryParamName)))). + Block(p.Clone().Op("=").Append(p, v)), + ) + } + // Implementation (method's) body + block = append( + block, + jen.Id("path").Op(":=").Qual("fmt", "Sprintf").Call(urlParams...), + jen.List(outObj, jen.Err()).Op(":=").Id("h.doer.Do").Call(callOpts...), + ) + + ifErr := jen.If(jen.Err().Op("!=").Nil()).Block(returnErr) if rsp == nil { block = append(block, jen.Return(jen.Err())) } else { block = append(block, ifErr) - outReturn := jen.Id("out") if rsp.CamelName != schemaOut.CamelName { @@ -367,7 +439,7 @@ func exec() error { return err } - handler.Interface(typeMethods...) + handlerType.Interface(typeMethods...) err = file.Save(filepath.Join(dirPath, fileName+".go")) if err != nil { @@ -377,7 +449,7 @@ func exec() error { pkgName := filepath.Join(cfg.Module, cfg.HandlerDir, fileName) clientFields = append(clientFields, jen.Qual(pkgName, handlerName)) clientValues[jen.Id(handlerName)] = jen.Qual(pkgName, newHandler).Call(jen.Id(doerName)) - clientTypeValues = append(clientTypeValues, jen.Qual(pkgName, handlerType)) + clientTypeValues = append(clientTypeValues, jen.Qual(pkgName, handlerTypeName)) } client := jen.NewFile(cfg.Package) @@ -543,3 +615,30 @@ var reComment = regexp.MustCompile(`\.?[\r\n]+\s*?`) func fmtComment(c string) string { return reComment.ReplaceAllString(c, ". ") } + +// fmtQueryParam returns a query param +func fmtQueryParam(funcName string, p *Parameter) (*jen.Statement, error) { + keyFuncName := funcName + p.Schema.CamelName + keyVarName := jen.Id(p.Schema.lowerCamel()) + + var value *jen.Statement + format, ok := strFormatters[p.Schema.Type] + if !ok { + return nil, fmt.Errorf("query param with type %q is not supported", p.Schema.Type) + } + value = jen.Qual("fmt", "Sprintf").Call(jen.Lit(format), keyVarName.Clone()) + + param := jen.Comment(fmt.Sprintf("%s %s", keyFuncName, fmtComment(p.Description))) + param.Line() + param.Func().Id(keyFuncName). + Params(keyVarName.Clone().Add(getType(p.Schema))).Params(jen.Id(queryParamTypeName)). + Block( + jen.Return(jen.Id(queryParamTypeName).Values(jen.Lit(p.Schema.name), value)), + ) + return param, nil +} + +// fmtQueryParamType literally returns: [2]string +func fmtQueryParamType() *jen.Statement { + return jen.Index(jen.Lit(queryParamArraySize)).String() +} diff --git a/generator/models.go b/generator/models.go index 50ab71d..c154744 100644 --- a/generator/models.go +++ b/generator/models.go @@ -105,7 +105,6 @@ const ( type Parameter struct { Ref string `json:"$ref"` In ParameterIn `json:"in"` - Required bool `json:"required"` Name string `json:"name"` Description string `json:"description"` Schema *Schema `json:"schema"` @@ -346,6 +345,10 @@ func (s *Schema) isOut() bool { return s.root().out } +func (s *Schema) lowerCamel() string { + return strcase.ToLowerCamel(s.CamelName) +} + func getScalarType(s *Schema) *jen.Statement { switch s.Type { case SchemaTypeString: diff --git a/handler/account/account.go b/handler/account/account.go index 3e55d1b..640cdf2 100644 --- a/handler/account/account.go +++ b/handler/account/account.go @@ -92,12 +92,13 @@ type Handler interface { AccountUsersSearch(ctx context.Context, accountId string, in *AccountUsersSearchIn) ([]UserOut, error) } -func NewHandler(doer doer) AccountHandler { - return AccountHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) AccountHandler { + return AccountHandler{doer} } type AccountHandler struct { diff --git a/handler/accountauthentication/accountauthentication.go b/handler/accountauthentication/accountauthentication.go index 1833bf7..023e259 100644 --- a/handler/accountauthentication/accountauthentication.go +++ b/handler/accountauthentication/accountauthentication.go @@ -37,12 +37,13 @@ type Handler interface { AccountAuthenticationMethodsList(ctx context.Context, accountId string) ([]AuthenticationMethodOut, error) } -func NewHandler(doer doer) AccountAuthenticationHandler { - return AccountAuthenticationHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) AccountAuthenticationHandler { + return AccountAuthenticationHandler{doer} } type AccountAuthenticationHandler struct { diff --git a/handler/accountteam/accountteam.go b/handler/accountteam/accountteam.go index c68e828..2616fba 100644 --- a/handler/accountteam/accountteam.go +++ b/handler/accountteam/accountteam.go @@ -62,12 +62,13 @@ type Handler interface { AccountTeamUpdate(ctx context.Context, accountId string, teamId string, in *AccountTeamUpdateIn) (*AccountTeamUpdateOut, error) } -func NewHandler(doer doer) AccountTeamHandler { - return AccountTeamHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) AccountTeamHandler { + return AccountTeamHandler{doer} } type AccountTeamHandler struct { diff --git a/handler/accountteammember/accountteammember.go b/handler/accountteammember/accountteammember.go index 4ea5cd9..0f6d06a 100644 --- a/handler/accountteammember/accountteammember.go +++ b/handler/accountteammember/accountteammember.go @@ -37,12 +37,13 @@ type Handler interface { AccountTeamMembersList(ctx context.Context, accountId string, teamId string) ([]MemberOut, error) } -func NewHandler(doer doer) AccountTeamMemberHandler { - return AccountTeamMemberHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) AccountTeamMemberHandler { + return AccountTeamMemberHandler{doer} } type AccountTeamMemberHandler struct { diff --git a/handler/applicationuser/applicationuser.go b/handler/applicationuser/applicationuser.go index 74b8774..78dc775 100644 --- a/handler/applicationuser/applicationuser.go +++ b/handler/applicationuser/applicationuser.go @@ -52,12 +52,13 @@ type Handler interface { ApplicationUsersList(ctx context.Context, organizationId string) ([]ApplicationUserOut, error) } -func NewHandler(doer doer) ApplicationUserHandler { - return ApplicationUserHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) ApplicationUserHandler { + return ApplicationUserHandler{doer} } type ApplicationUserHandler struct { diff --git a/handler/billinggroup/billinggroup.go b/handler/billinggroup/billinggroup.go index 68483bc..39ce55f 100644 --- a/handler/billinggroup/billinggroup.go +++ b/handler/billinggroup/billinggroup.go @@ -77,12 +77,13 @@ type Handler interface { BillingGroupUpdate(ctx context.Context, billingGroupId string, in *BillingGroupUpdateIn) (*BillingGroupUpdateOut, error) } -func NewHandler(doer doer) BillingGroupHandler { - return BillingGroupHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) BillingGroupHandler { + return BillingGroupHandler{doer} } type BillingGroupHandler struct { diff --git a/handler/clickhouse/clickhouse.go b/handler/clickhouse/clickhouse.go index f1435de..4c0ac04 100644 --- a/handler/clickhouse/clickhouse.go +++ b/handler/clickhouse/clickhouse.go @@ -38,7 +38,7 @@ type Handler interface { // ServiceClickHouseQueryStats return statistics on recent queries // GET /v1/project/{project}/service/{service_name}/clickhouse/query/stats // https://api.aiven.io/doc/#tag/Service:_ClickHouse/operation/ServiceClickHouseQueryStats - ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string) ([]QueryOutAlt, error) + ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string, query ...queryParam) ([]QueryOutAlt, error) // ServiceClickHouseTieredStorageSummary get the ClickHouse tiered storage summary // GET /v1/project/{project}/service/{service_name}/clickhouse/tiered-storage/summary @@ -46,12 +46,16 @@ type Handler interface { ServiceClickHouseTieredStorageSummary(ctx context.Context, project string, serviceName string) (*ServiceClickHouseTieredStorageSummaryOut, error) } -func NewHandler(doer doer) ClickHouseHandler { - return ClickHouseHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +// queryParam http query params private type +type queryParam [2]string + +func NewHandler(doer doer) ClickHouseHandler { + return ClickHouseHandler{doer} } type ClickHouseHandler struct { @@ -107,9 +111,28 @@ func (h *ClickHouseHandler) ServiceClickHouseQuery(ctx context.Context, project } return out, nil } -func (h *ClickHouseHandler) ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string) ([]QueryOutAlt, error) { + +// ServiceClickHouseQueryStatsLimit Limit for number of results +func ServiceClickHouseQueryStatsLimit(limit int) queryParam { + return queryParam{"limit", fmt.Sprintf("%d", limit)} +} + +// ServiceClickHouseQueryStatsOffset Offset for retrieved results based on sort order +func ServiceClickHouseQueryStatsOffset(offset int) queryParam { + return queryParam{"offset", fmt.Sprintf("%d", offset)} +} + +// ServiceClickHouseQueryStatsOrderByType Order in which to sort retrieved results +func ServiceClickHouseQueryStatsOrderByType(orderByType OrderByType) queryParam { + return queryParam{"order_by", fmt.Sprintf("%s", orderByType)} +} +func (h *ClickHouseHandler) ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string, query ...queryParam) ([]QueryOutAlt, error) { + p := make([][2]string, 0, len(query)) + for _, v := range query { + p = append(p, v) + } path := fmt.Sprintf("/v1/project/%s/service/%s/clickhouse/query/stats", url.PathEscape(project), url.PathEscape(serviceName)) - b, err := h.doer.Do(ctx, "ServiceClickHouseQueryStats", "GET", path, nil) + b, err := h.doer.Do(ctx, "ServiceClickHouseQueryStats", "GET", path, nil, p...) if err != nil { return nil, err } @@ -161,6 +184,29 @@ type MetaOut struct { Name string `json:"name"` // Column name Type string `json:"type"` // Column type } +type OrderByType string + +const ( + OrderByTypeCallsasc OrderByType = "calls:asc" + OrderByTypeCallsdesc OrderByType = "calls:desc" + OrderByTypeMinTimeasc OrderByType = "min_time:asc" + OrderByTypeMinTimedesc OrderByType = "min_time:desc" + OrderByTypeMaxTimeasc OrderByType = "max_time:asc" + OrderByTypeMaxTimedesc OrderByType = "max_time:desc" + OrderByTypeMeanTimeasc OrderByType = "mean_time:asc" + OrderByTypeMeanTimedesc OrderByType = "mean_time:desc" + OrderByTypeP95Timeasc OrderByType = "p95_time:asc" + OrderByTypeP95Timedesc OrderByType = "p95_time:desc" + OrderByTypeStddevTimeasc OrderByType = "stddev_time:asc" + OrderByTypeStddevTimedesc OrderByType = "stddev_time:desc" + OrderByTypeTotalTimeasc OrderByType = "total_time:asc" + OrderByTypeTotalTimedesc OrderByType = "total_time:desc" +) + +func OrderByTypeChoices() []string { + return []string{"calls:asc", "calls:desc", "min_time:asc", "min_time:desc", "max_time:asc", "max_time:desc", "mean_time:asc", "mean_time:desc", "p95_time:asc", "p95_time:desc", "stddev_time:asc", "stddev_time:desc", "total_time:asc", "total_time:desc"} +} + type QueryOut struct { ClientName *string `json:"client_name,omitempty"` // Client name, if set Database *string `json:"database,omitempty"` diff --git a/handler/cloud/cloud.go b/handler/cloud/cloud.go index aa1a487..6866eec 100644 --- a/handler/cloud/cloud.go +++ b/handler/cloud/cloud.go @@ -21,12 +21,13 @@ type Handler interface { ListProjectClouds(ctx context.Context, project string) ([]CloudOut, error) } -func NewHandler(doer doer) CloudHandler { - return CloudHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) CloudHandler { + return CloudHandler{doer} } type CloudHandler struct { diff --git a/handler/domain/domain.go b/handler/domain/domain.go index 58571dc..7a1ea3d 100644 --- a/handler/domain/domain.go +++ b/handler/domain/domain.go @@ -37,12 +37,13 @@ type Handler interface { OrganizationDomainsRemove(ctx context.Context, organizationId string, domainId string) error } -func NewHandler(doer doer) DomainHandler { - return DomainHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) DomainHandler { + return DomainHandler{doer} } type DomainHandler struct { diff --git a/handler/flink/flink.go b/handler/flink/flink.go index b7b4cc9..6a9a9b3 100644 --- a/handler/flink/flink.go +++ b/handler/flink/flink.go @@ -16,12 +16,13 @@ type Handler interface { ServiceFlinkOverview(ctx context.Context, project string, serviceName string) (*ServiceFlinkOverviewOut, error) } -func NewHandler(doer doer) FlinkHandler { - return FlinkHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) FlinkHandler { + return FlinkHandler{doer} } type FlinkHandler struct { diff --git a/handler/flinkapplication/flinkapplication.go b/handler/flinkapplication/flinkapplication.go index 6ceceae..720bac4 100644 --- a/handler/flinkapplication/flinkapplication.go +++ b/handler/flinkapplication/flinkapplication.go @@ -37,12 +37,13 @@ type Handler interface { ServiceFlinkUpdateApplication(ctx context.Context, project string, serviceName string, applicationId string, in *ServiceFlinkUpdateApplicationIn) (*ServiceFlinkUpdateApplicationOut, error) } -func NewHandler(doer doer) FlinkApplicationHandler { - return FlinkApplicationHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) FlinkApplicationHandler { + return FlinkApplicationHandler{doer} } type FlinkApplicationHandler struct { diff --git a/handler/flinkapplicationdeployment/flinkapplicationdeployment.go b/handler/flinkapplicationdeployment/flinkapplicationdeployment.go index dd34dec..f793524 100644 --- a/handler/flinkapplicationdeployment/flinkapplicationdeployment.go +++ b/handler/flinkapplicationdeployment/flinkapplicationdeployment.go @@ -42,12 +42,13 @@ type Handler interface { ServiceFlinkStopApplicationDeployment(ctx context.Context, project string, serviceName string, applicationId string, deploymentId string) (*ServiceFlinkStopApplicationDeploymentOut, error) } -func NewHandler(doer doer) FlinkApplicationDeploymentHandler { - return FlinkApplicationDeploymentHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) FlinkApplicationDeploymentHandler { + return FlinkApplicationDeploymentHandler{doer} } type FlinkApplicationDeploymentHandler struct { diff --git a/handler/flinkapplicationversion/flinkapplicationversion.go b/handler/flinkapplicationversion/flinkapplicationversion.go index 1b9a972..bf8de26 100644 --- a/handler/flinkapplicationversion/flinkapplicationversion.go +++ b/handler/flinkapplicationversion/flinkapplicationversion.go @@ -32,12 +32,13 @@ type Handler interface { ServiceFlinkValidateApplicationVersion(ctx context.Context, project string, serviceName string, applicationId string, in *ServiceFlinkValidateApplicationVersionIn) (*ServiceFlinkValidateApplicationVersionOut, error) } -func NewHandler(doer doer) FlinkApplicationVersionHandler { - return FlinkApplicationVersionHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) FlinkApplicationVersionHandler { + return FlinkApplicationVersionHandler{doer} } type FlinkApplicationVersionHandler struct { diff --git a/handler/flinkjob/flinkjob.go b/handler/flinkjob/flinkjob.go index c78eff3..c08346d 100644 --- a/handler/flinkjob/flinkjob.go +++ b/handler/flinkjob/flinkjob.go @@ -21,12 +21,13 @@ type Handler interface { ServiceFlinkJobsList(ctx context.Context, project string, serviceName string) ([]JobOut, error) } -func NewHandler(doer doer) FlinkJobHandler { - return FlinkJobHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) FlinkJobHandler { + return FlinkJobHandler{doer} } type FlinkJobHandler struct { diff --git a/handler/kafka/kafka.go b/handler/kafka/kafka.go index fc7b874..2fa179e 100644 --- a/handler/kafka/kafka.go +++ b/handler/kafka/kafka.go @@ -61,12 +61,13 @@ type Handler interface { ServiceKafkaTieredStorageSummary(ctx context.Context, project string, serviceName string) (*ServiceKafkaTieredStorageSummaryOut, error) } -func NewHandler(doer doer) KafkaHandler { - return KafkaHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) KafkaHandler { + return KafkaHandler{doer} } type KafkaHandler struct { diff --git a/handler/kafkaconnect/kafkaconnect.go b/handler/kafkaconnect/kafkaconnect.go index 2a1dbb5..be7df02 100644 --- a/handler/kafkaconnect/kafkaconnect.go +++ b/handler/kafkaconnect/kafkaconnect.go @@ -66,12 +66,13 @@ type Handler interface { ServiceKafkaConnectResumeConnector(ctx context.Context, project string, serviceName string, connectorName string) error } -func NewHandler(doer doer) KafkaConnectHandler { - return KafkaConnectHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) KafkaConnectHandler { + return KafkaConnectHandler{doer} } type KafkaConnectHandler struct { diff --git a/handler/kafkamirrormaker/kafkamirrormaker.go b/handler/kafkamirrormaker/kafkamirrormaker.go index 3cbf2d6..9504b46 100644 --- a/handler/kafkamirrormaker/kafkamirrormaker.go +++ b/handler/kafkamirrormaker/kafkamirrormaker.go @@ -36,12 +36,13 @@ type Handler interface { ServiceKafkaMirrorMakerPatchReplicationFlow(ctx context.Context, project string, serviceName string, sourceCluster string, targetCluster string, in *ServiceKafkaMirrorMakerPatchReplicationFlowIn) (*ServiceKafkaMirrorMakerPatchReplicationFlowOut, error) } -func NewHandler(doer doer) KafkaMirrorMakerHandler { - return KafkaMirrorMakerHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) KafkaMirrorMakerHandler { + return KafkaMirrorMakerHandler{doer} } type KafkaMirrorMakerHandler struct { diff --git a/handler/kafkaschemaregistry/kafkaschemaregistry.go b/handler/kafkaschemaregistry/kafkaschemaregistry.go index 6f3b181..09e292b 100644 --- a/handler/kafkaschemaregistry/kafkaschemaregistry.go +++ b/handler/kafkaschemaregistry/kafkaschemaregistry.go @@ -91,12 +91,13 @@ type Handler interface { ServiceSchemaRegistrySubjects(ctx context.Context, project string, serviceName string) ([]string, error) } -func NewHandler(doer doer) KafkaSchemaRegistryHandler { - return KafkaSchemaRegistryHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) KafkaSchemaRegistryHandler { + return KafkaSchemaRegistryHandler{doer} } type KafkaSchemaRegistryHandler struct { diff --git a/handler/kafkatopic/kafkatopic.go b/handler/kafkatopic/kafkatopic.go index fffa115..ed215a1 100644 --- a/handler/kafkatopic/kafkatopic.go +++ b/handler/kafkatopic/kafkatopic.go @@ -46,12 +46,13 @@ type Handler interface { ServiceKafkaTopicUpdate(ctx context.Context, project string, serviceName string, topicName string, in *ServiceKafkaTopicUpdateIn) error } -func NewHandler(doer doer) KafkaTopicHandler { - return KafkaTopicHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) KafkaTopicHandler { + return KafkaTopicHandler{doer} } type KafkaTopicHandler struct { diff --git a/handler/mysql/mysql.go b/handler/mysql/mysql.go index 073c941..fe2848f 100644 --- a/handler/mysql/mysql.go +++ b/handler/mysql/mysql.go @@ -16,12 +16,13 @@ type Handler interface { MySQLServiceQueryStatistics(ctx context.Context, project string, serviceName string, in *MySqlserviceQueryStatisticsIn) ([]QueryOut, error) } -func NewHandler(doer doer) MySQLHandler { - return MySQLHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) MySQLHandler { + return MySQLHandler{doer} } type MySQLHandler struct { diff --git a/handler/opensearch/opensearch.go b/handler/opensearch/opensearch.go index e6fdef0..8c316a1 100644 --- a/handler/opensearch/opensearch.go +++ b/handler/opensearch/opensearch.go @@ -52,12 +52,13 @@ type Handler interface { ServiceOpenSearchSecuritySet(ctx context.Context, project string, serviceName string, in *ServiceOpenSearchSecuritySetIn) (*ServiceOpenSearchSecuritySetOut, error) } -func NewHandler(doer doer) OpenSearchHandler { - return OpenSearchHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) OpenSearchHandler { + return OpenSearchHandler{doer} } type OpenSearchHandler struct { diff --git a/handler/organization/organization.go b/handler/organization/organization.go index 4711d70..dcef3d3 100644 --- a/handler/organization/organization.go +++ b/handler/organization/organization.go @@ -57,12 +57,13 @@ type Handler interface { UserOrganizationsList(ctx context.Context) ([]OrganizationOut, error) } -func NewHandler(doer doer) OrganizationHandler { - return OrganizationHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) OrganizationHandler { + return OrganizationHandler{doer} } type OrganizationHandler struct { diff --git a/handler/organizationuser/organizationuser.go b/handler/organizationuser/organizationuser.go index 7a6a7fc..33c6182 100644 --- a/handler/organizationuser/organizationuser.go +++ b/handler/organizationuser/organizationuser.go @@ -72,12 +72,13 @@ type Handler interface { OrganizationUserUpdate(ctx context.Context, organizationId string, memberUserId string, in *OrganizationUserUpdateIn) (*OrganizationUserUpdateOut, error) } -func NewHandler(doer doer) OrganizationUserHandler { - return OrganizationUserHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) OrganizationUserHandler { + return OrganizationUserHandler{doer} } type OrganizationUserHandler struct { diff --git a/handler/postgresql/postgresql.go b/handler/postgresql/postgresql.go index a1cca12..221a57b 100644 --- a/handler/postgresql/postgresql.go +++ b/handler/postgresql/postgresql.go @@ -41,12 +41,13 @@ type Handler interface { ServicePGBouncerUpdate(ctx context.Context, project string, serviceName string, poolName string, in *ServicePgbouncerUpdateIn) error } -func NewHandler(doer doer) PostgreSQLHandler { - return PostgreSQLHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) PostgreSQLHandler { + return PostgreSQLHandler{doer} } type PostgreSQLHandler struct { diff --git a/handler/privatelink/privatelink.go b/handler/privatelink/privatelink.go index 25a9552..bc15b7e 100644 --- a/handler/privatelink/privatelink.go +++ b/handler/privatelink/privatelink.go @@ -76,12 +76,13 @@ type Handler interface { ServicePrivatelinkAzureUpdate(ctx context.Context, project string, serviceName string, in *ServicePrivatelinkAzureUpdateIn) (*ServicePrivatelinkAzureUpdateOut, error) } -func NewHandler(doer doer) PrivatelinkHandler { - return PrivatelinkHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) PrivatelinkHandler { + return PrivatelinkHandler{doer} } type PrivatelinkHandler struct { diff --git a/handler/project/project.go b/handler/project/project.go index 580a052..5740eb0 100644 --- a/handler/project/project.go +++ b/handler/project/project.go @@ -112,12 +112,13 @@ type Handler interface { ProjectUserUpdate(ctx context.Context, project string, userEmail string, in *ProjectUserUpdateIn) error } -func NewHandler(doer doer) ProjectHandler { - return ProjectHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) ProjectHandler { + return ProjectHandler{doer} } type ProjectHandler struct { diff --git a/handler/projectbilling/projectbilling.go b/handler/projectbilling/projectbilling.go index 248cb5f..dd6761c 100644 --- a/handler/projectbilling/projectbilling.go +++ b/handler/projectbilling/projectbilling.go @@ -32,12 +32,13 @@ type Handler interface { ProjectInvoiceList(ctx context.Context, project string) ([]InvoiceOut, error) } -func NewHandler(doer doer) ProjectBillingHandler { - return ProjectBillingHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) ProjectBillingHandler { + return ProjectBillingHandler{doer} } type ProjectBillingHandler struct { diff --git a/handler/service/service.go b/handler/service/service.go index e0fc9cc..2b2657e 100644 --- a/handler/service/service.go +++ b/handler/service/service.go @@ -159,15 +159,19 @@ type Handler interface { // ServiceUpdate update service configuration // PUT /v1/project/{project}/service/{service_name} // https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate - ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn) (*ServiceUpdateOut, error) + ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn, query ...queryParam) (*ServiceUpdateOut, error) } -func NewHandler(doer doer) ServiceHandler { - return ServiceHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +// queryParam http query params private type +type queryParam [2]string + +func NewHandler(doer doer) ServiceHandler { + return ServiceHandler{doer} } type ServiceHandler struct { @@ -503,7 +507,12 @@ func (h *ServiceHandler) ServiceTaskGet(ctx context.Context, project string, ser } return &out.Task, nil } -func (h *ServiceHandler) ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn) (*ServiceUpdateOut, error) { + +// ServiceUpdateAllowUncleanPoweroff Allows or disallows powering off a service if some WAL segments are not available for a future restoration of the service, which might result in data loss when powering the service back on +func ServiceUpdateAllowUncleanPoweroff(allowUncleanPoweroff bool) queryParam { + return queryParam{"allow_unclean_poweroff", fmt.Sprintf("%t", allowUncleanPoweroff)} +} +func (h *ServiceHandler) ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn, query ...queryParam) (*ServiceUpdateOut, error) { path := fmt.Sprintf("/v1/project/%s/service/%s", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceUpdate", "PUT", path, in) if err != nil { diff --git a/handler/serviceintegration/serviceintegration.go b/handler/serviceintegration/serviceintegration.go index aab501a..e3dcd5c 100644 --- a/handler/serviceintegration/serviceintegration.go +++ b/handler/serviceintegration/serviceintegration.go @@ -71,12 +71,13 @@ type Handler interface { ServiceIntegrationUpdate(ctx context.Context, project string, integrationId string, in *ServiceIntegrationUpdateIn) (*ServiceIntegrationUpdateOut, error) } -func NewHandler(doer doer) ServiceIntegrationHandler { - return ServiceIntegrationHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) ServiceIntegrationHandler { + return ServiceIntegrationHandler{doer} } type ServiceIntegrationHandler struct { diff --git a/handler/serviceuser/serviceuser.go b/handler/serviceuser/serviceuser.go index 7b34bd4..122c6cd 100644 --- a/handler/serviceuser/serviceuser.go +++ b/handler/serviceuser/serviceuser.go @@ -37,12 +37,13 @@ type Handler interface { ServiceUserGet(ctx context.Context, project string, serviceName string, serviceUsername string) (*ServiceUserGetOut, error) } -func NewHandler(doer doer) ServiceUserHandler { - return ServiceUserHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) ServiceUserHandler { + return ServiceUserHandler{doer} } type ServiceUserHandler struct { diff --git a/handler/staticip/staticip.go b/handler/staticip/staticip.go index 7a210fd..c8328c0 100644 --- a/handler/staticip/staticip.go +++ b/handler/staticip/staticip.go @@ -46,12 +46,13 @@ type Handler interface { StaticIPList(ctx context.Context, project string) ([]StaticIpOut, error) } -func NewHandler(doer doer) StaticIPHandler { - return StaticIPHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) StaticIPHandler { + return StaticIPHandler{doer} } type StaticIPHandler struct { diff --git a/handler/thanos/thanos.go b/handler/thanos/thanos.go index 0bf1448..0c0c310 100644 --- a/handler/thanos/thanos.go +++ b/handler/thanos/thanos.go @@ -16,12 +16,13 @@ type Handler interface { ServiceThanosStorageSummary(ctx context.Context, project string, serviceName string) (*ServiceThanosStorageSummaryOut, error) } -func NewHandler(doer doer) ThanosHandler { - return ThanosHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) ThanosHandler { + return ThanosHandler{doer} } type ThanosHandler struct { diff --git a/handler/user/user.go b/handler/user/user.go index a1ca2a5..1975f39 100644 --- a/handler/user/user.go +++ b/handler/user/user.go @@ -147,12 +147,13 @@ type Handler interface { ValidateReferralCode(ctx context.Context, referralCode string) error } -func NewHandler(doer doer) UserHandler { - return UserHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) UserHandler { + return UserHandler{doer} } type UserHandler struct { diff --git a/handler/usergroup/usergroup.go b/handler/usergroup/usergroup.go index 5610643..ba1eabf 100644 --- a/handler/usergroup/usergroup.go +++ b/handler/usergroup/usergroup.go @@ -47,12 +47,13 @@ type Handler interface { UserGroupsList(ctx context.Context, organizationId string) ([]UserGroupOut, error) } -func NewHandler(doer doer) UserGroupHandler { - return UserGroupHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) UserGroupHandler { + return UserGroupHandler{doer} } type UserGroupHandler struct { diff --git a/handler/vpc/vpc.go b/handler/vpc/vpc.go index c630d61..6eb1d39 100644 --- a/handler/vpc/vpc.go +++ b/handler/vpc/vpc.go @@ -57,12 +57,13 @@ type Handler interface { VpcPeeringConnectionWithResourceGroupDelete(ctx context.Context, project string, projectVpcId string, peerCloudAccount string, peerResourceGroup string, peerVpc string) (*VpcPeeringConnectionWithResourceGroupDeleteOut, error) } -func NewHandler(doer doer) VpcHandler { - return VpcHandler{doer} +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) } -type doer interface { - Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +func NewHandler(doer doer) VpcHandler { + return VpcHandler{doer} } type VpcHandler struct {