From c990cb0fe0b8128b3362a20abb49105f44003c7b Mon Sep 17 00:00:00 2001 From: Myroslav Vivcharyk Date: Mon, 22 Dec 2025 16:06:56 +0100 Subject: [PATCH] feat: added config property to kafkaconnect --- .golangci.yaml | 76 ++++++++++++++-------------- .mockery.yaml | 1 + .trunk/trunk.yaml | 2 +- Taskfile.yml | 1 + client.go | 2 +- client_mock.go | 3 +- client_test.go | 12 ++--- error_test.go | 2 +- handler/kafkaconnect/kafkaconnect.go | 30 +++++------ openapi_patch.yaml | 23 +++++++++ 10 files changed, 85 insertions(+), 67 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 64e3065..71193f1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,54 +1,52 @@ -run: - build-tags: - - generator - +version: "2" linters: - disable-all: true + default: none enable: - - durationcheck + - copyloopvar - errcheck - - errname - errorlint - - forbidigo - - forcetypeassert - - gocognit - - goconst - - gocyclo - - gofmt - - goimports - - mnd - - gosec - - gosimple + - gocritic - govet - - importas - ineffassign - makezero - misspell + - mnd - nakedret - - nestif - nilerr - - nolintlint - prealloc - revive - staticcheck - - typecheck - unconvert - unused - - whitespace - -linters-settings: - gocognit: - min-complexity: 25 - goconst: - min-len: 2 - min-occurrences: 2 - govet: - enable-all: true - disable: - - fieldalignment - lll: - line-length: 120 - tab-width: 4 - -issues: - exclude-use-default: false + - testifylint + settings: + govet: + disable: + - fieldalignment + - shadow + enable-all: true + staticcheck: + checks: ["all", "-QF1008"] + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - dupl + - goconst + - golint + - gosec + path: _test\.go + text: underscore + - linters: + - staticcheck + text: "QF1001: (.*)" +formatters: + enable: + - gofmt + - gofumpt + - goimports diff --git a/.mockery.yaml b/.mockery.yaml index 2cbd988..069ff66 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -1,6 +1,7 @@ template: testify filename: "{{ .InterfaceName | lower }}_mock.go" formatter: goimports +include-auto-generated: true packages: github.com/aiven/go-client-codegen: interfaces: diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 8937308..c5ed5af 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -22,7 +22,7 @@ lint: - checkov@3.2.495 - git-diff-check - gofmt@1.20.4 - - golangci-lint@2.7.2 + - golangci-lint2@2.7.2 - markdownlint@0.47.0 - osv-scanner@2.3.1 - prettier@3.7.4 diff --git a/Taskfile.yml b/Taskfile.yml index 9ecaf1c..541f6de 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -37,6 +37,7 @@ tasks: - task: get-openapi-spec - task: go-generate - task: generate-mocks + - task: fmt-imports test: cmds: - go test -v diff --git a/client.go b/client.go index 75bc3b0..01ab72b 100644 --- a/client.go +++ b/client.go @@ -210,7 +210,7 @@ func fmtQuery(operationID string, query ...[2]string) string { // shouldAddDefaultLimit determines if default limit should be added func shouldAddDefaultLimit(operationID string, q url.Values) bool { - var operationsWithoutLimit = []string{ + operationsWithoutLimit := []string{ "ServiceKafkaQuotaDescribe", "ServiceKafkaQuotaDelete", } diff --git a/client_mock.go b/client_mock.go index 2eaf078..6f4ad77 100644 --- a/client_mock.go +++ b/client_mock.go @@ -7,6 +7,8 @@ package aiven import ( "context" + mock "github.com/stretchr/testify/mock" + "github.com/aiven/go-client-codegen/handler/account" "github.com/aiven/go-client-codegen/handler/accountauthentication" "github.com/aiven/go-client-codegen/handler/accountteam" @@ -49,7 +51,6 @@ import ( "github.com/aiven/go-client-codegen/handler/user" "github.com/aiven/go-client-codegen/handler/usergroup" "github.com/aiven/go-client-codegen/handler/vpc" - mock "github.com/stretchr/testify/mock" ) // NewMockClient creates a new instance of MockClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. diff --git a/client_test.go b/client_test.go index 11285be..326426e 100644 --- a/client_test.go +++ b/client_test.go @@ -63,20 +63,20 @@ func TestServiceCreate(t *testing.T) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) _, err = w.Write([]byte(`{"service": {"plan": "wow", "state": "RUNNING"}}`)) - require.NoError(t, err) + assert.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") + assert.Equal(t, "limit=1&order_by=max_time%3Aasc", r.URL.RawQuery) // Creates response w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) _, err := w.Write([]byte(`{"queries": [{"calls": 1}]}`)) - require.NoError(t, err) + assert.NoError(t, err) atomic.AddInt64(&callCount, 1) }, ) @@ -160,7 +160,7 @@ func TestServiceCreateErrorsRetries(t *testing.T) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusInternalServerError) _, err := w.Write([]byte(tt.ResponseBody)) - require.NoError(t, err) + assert.NoError(t, err) atomic.AddInt64(&callsActual, 1) }, ) @@ -270,13 +270,13 @@ func TestServiceIntegrationEndpointGet(t *testing.T) { "/v1/project/{project}/integration_endpoint/{integration_endpoint_id}", func(w http.ResponseWriter, r *http.Request) { assert.Regexp(t, `go-client-codegen/[0-9\.]+ unit-test`, r.Header["User-Agent"]) - assert.Equal(t, r.RequestURI, "/v1/project/aiven-endpoint-project/integration_endpoint/foo?include_secrets=true&limit=999") + assert.Equal(t, "/v1/project/aiven-endpoint-project/integration_endpoint/foo?include_secrets=true&limit=999", r.RequestURI) // Creates response w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) _, err := w.Write([]byte(`{"service_integration_endpoint": {"endpoint_name": "wow"}}`)) - require.NoError(t, err) + assert.NoError(t, err) atomic.AddInt64(&callCount, 1) }, ) diff --git a/error_test.go b/error_test.go index 502f848..42d424c 100644 --- a/error_test.go +++ b/error_test.go @@ -61,7 +61,7 @@ func TestIsNotFoundIntegration(t *testing.T) { ctx := context.Background() out, err := c.AccountGet(ctx, "does_not_exist") assert.Nil(t, out) - assert.NotNil(t, err) + require.Error(t, err) assert.True(t, IsNotFound(err)) } diff --git a/handler/kafkaconnect/kafkaconnect.go b/handler/kafkaconnect/kafkaconnect.go index b851c66..39af202 100644 --- a/handler/kafkaconnect/kafkaconnect.go +++ b/handler/kafkaconnect/kafkaconnect.go @@ -188,12 +188,6 @@ type AvailableVersionOut struct { NeedsMaintenance *bool `json:"needs_maintenance,omitempty"` // Using this version requires a maintenance update. Version *string `json:"version,omitempty"` // Connector version number } - -// ConfigOut Connector configuration parameters -type ConfigOut struct { - ConnectorClass string `json:"connector.class"` // The Java class for the connector - Name string `json:"name"` // Unique name for the connector -} type ConfigurationSchemaOut struct { DefaultValue string `json:"default_value"` // Default value to be set if field omitted in configuration DisplayName string `json:"display_name"` // Human friendly name of the field @@ -225,10 +219,10 @@ func ConfigurationSchemaTypeChoices() []string { } type ConnectorOut struct { - Config ConfigOut `json:"config"` // Connector configuration parameters - Name string `json:"name"` // Connector name - Plugin PluginOut `json:"plugin"` // Kafka Connector plugin information - Tasks []TaskOut `json:"tasks"` // List of tasks of a connector + Config map[string]string `json:"config"` // Connector configuration parameters + Name string `json:"name"` // Connector name + Plugin PluginOut `json:"plugin"` // Kafka Connector plugin information + Tasks []TaskOut `json:"tasks"` // List of tasks of a connector } type ImportanceType string @@ -283,18 +277,18 @@ func ServiceKafkaConnectConnectorStateTypeChoices() []string { // ServiceKafkaConnectCreateConnectorOut Kafka connector information type ServiceKafkaConnectCreateConnectorOut struct { - Config ConfigOut `json:"config"` // Connector configuration parameters - Name string `json:"name"` // Connector name - Plugin PluginOut `json:"plugin"` // Kafka Connector plugin information - Tasks []TaskOut `json:"tasks"` // List of tasks of a connector + Config map[string]string `json:"config"` // Connector configuration parameters + Name string `json:"name"` // Connector name + Plugin PluginOut `json:"plugin"` // Kafka Connector plugin information + Tasks []TaskOut `json:"tasks"` // List of tasks of a connector } // ServiceKafkaConnectEditConnectorOut Kafka connector information type ServiceKafkaConnectEditConnectorOut struct { - Config ConfigOut `json:"config"` // Connector configuration parameters - Name string `json:"name"` // Connector name - Plugin PluginOut `json:"plugin"` // Kafka Connector plugin information - Tasks []TaskOut `json:"tasks"` // List of tasks of a connector + Config map[string]string `json:"config"` // Connector configuration parameters + Name string `json:"name"` // Connector name + Plugin PluginOut `json:"plugin"` // Kafka Connector plugin information + Tasks []TaskOut `json:"tasks"` // List of tasks of a connector } type ServiceKafkaConnectGetAvailableConnectorsOut struct { Author string `json:"author"` // Connector author name diff --git a/openapi_patch.yaml b/openapi_patch.yaml index 5113044..0592616 100644 --- a/openapi_patch.yaml +++ b/openapi_patch.yaml @@ -39,6 +39,29 @@ components: additionalProperties: true ServiceKafkaConnectEditConnectorRequestBody: additionalProperties: true + ServiceKafkaConnectListResponse: + properties: + connectors: + items: + properties: + # config has dynamic keys, with more fields than documented in a spec + config: + additionalProperties: + type: string + ServiceKafkaConnectCreateConnectorResponse: + properties: + connector: + properties: + config: + additionalProperties: + type: string + ServiceKafkaConnectEditConnectorResponse: + properties: + connector: + properties: + config: + additionalProperties: + type: string ServiceClickHousePasswordResetRequestBody: properties: password: