diff --git a/.github/workflows/e2e_targeted.yaml b/.github/workflows/e2e_targeted.yaml index 66437047f0..e841e1c335 100644 --- a/.github/workflows/e2e_targeted.yaml +++ b/.github/workflows/e2e_targeted.yaml @@ -158,6 +158,7 @@ jobs: E2E_TEST_RUN: ${{ matrix.test }} TEST_KONG_CONTROLLER_IMAGE_LOAD: ${{ github.event.inputs.controller-image }} TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: ${{ github.event.inputs.controller-image }} + TEST_KONG_KONNECT_ACCESS_TOKEN: ${{ secrets.K8S_TEAM_KONNECT_ACCESS_TOKEN }} KONG_LICENSE_DATA: ${{ steps.license.outputs.license }} KONG_CLUSTER_VERSION: ${{ github.event.inputs.kubernetes-version }} ISTIO_VERSION: ${{ github.event.inputs.istio-version }} diff --git a/go.mod b/go.mod index dacf7de45a..85c1b5411c 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/avast/retry-go/v4 v4.3.3 github.com/blang/semver/v4 v4.0.0 github.com/bombsimon/logrusr/v2 v2.0.1 + github.com/deepmap/oapi-codegen v1.12.4 github.com/go-logr/logr v1.2.3 github.com/google/go-cmp v0.5.9 github.com/google/uuid v1.3.0 @@ -45,6 +46,7 @@ require ( ) require ( + github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/cockroachdb/errors v1.9.0 // indirect github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect github.com/cockroachdb/redact v1.1.3 // indirect @@ -88,7 +90,7 @@ require ( github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect - github.com/go-openapi/swag v0.19.15 // indirect + github.com/go-openapi/swag v0.21.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -159,14 +161,14 @@ require ( go.uber.org/multierr v1.9.0 golang.org/x/crypto v0.3.0 // indirect golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4 - golang.org/x/mod v0.6.0 // indirect + golang.org/x/mod v0.7.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect golang.org/x/sync v0.1.0 golang.org/x/sys v0.5.0 // indirect golang.org/x/term v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.2.0 // indirect + golang.org/x/tools v0.3.0 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect diff --git a/go.sum b/go.sum index 94f442dfc0..a175bea036 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,7 @@ github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMo github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs= @@ -112,6 +113,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= +github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= @@ -133,6 +136,7 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc= +github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b/go.mod h1:ac9efd0D1fsDb3EJvhqgXRbFx7bs2wqZ10HQPeU8U/Q= github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM= github.com/bombsimon/logrusr/v2 v2.0.1/go.mod h1:ByVAX+vHdLGAfdroiMg6q0zgq2FODY2lc5YJvzmOJio= @@ -197,6 +201,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deepmap/oapi-codegen v1.12.4 h1:pPmn6qI9MuOtCz82WY2Xaw46EQjgvxednXXrP7g5Q2s= +github.com/deepmap/oapi-codegen v1.12.4/go.mod h1:3lgHGMu6myQ2vqbbTXH2H1o4eXFTGnFiDaOaKKl5yas= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= @@ -305,8 +311,9 @@ github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZ github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= +github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gobuffalo/flect v0.2.4/go.mod h1:1ZyCLIbg0YD7sDkzvFdPoOydPtD8y9JQnrOROolUcM8= @@ -540,6 +547,7 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= +github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -828,6 +836,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/ssgelm/cookiejarparser v1.0.1 h1:cRdXauUbOTFzTPJFaeiWbHnQ+tRGlpKKzvIK9PUekE4= github.com/ssgelm/cookiejarparser v1.0.1/go.mod h1:DUfC0mpjIzlDN7DzKjXpHj0qMI5m9VrZuz3wSlI+OEI= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= @@ -1011,8 +1020,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= -golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= +golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1295,8 +1304,8 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= -golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= +golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM= +golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/adminapi/konnect.go b/internal/adminapi/konnect.go index 2931bcab9a..17204bddc2 100644 --- a/internal/adminapi/konnect.go +++ b/internal/adminapi/konnect.go @@ -2,13 +2,15 @@ package adminapi import ( "context" + "crypto/tls" "errors" "fmt" + "net/http" "time" "github.com/avast/retry-go/v4" - deckutils "github.com/kong/deck/utils" "github.com/kong/go-kong/kong" + "github.com/samber/lo" tlsutil "github.com/kong/kubernetes-ingress-controller/v2/internal/util/tls" ) @@ -22,20 +24,31 @@ type KonnectConfig struct { } func NewKongClientForKonnectRuntimeGroup(ctx context.Context, c KonnectConfig) (*Client, error) { - tlsClientCert, err := tlsutil.ValueFromVariableOrFile([]byte(c.TLSClient.Cert), c.TLSClient.CertFile) + clientCertificate, err := tlsutil.ExtractClientCertificates( + []byte(c.TLSClient.Cert), + c.TLSClient.CertFile, + []byte(c.TLSClient.Key), + c.TLSClient.KeyFile, + ) if err != nil { - return nil, fmt.Errorf("could not extract TLS client cert: %w", err) + return nil, fmt.Errorf("failed to extract client certificates: %w", err) } - tlsClientKey, err := tlsutil.ValueFromVariableOrFile([]byte(c.TLSClient.Key), c.TLSClient.KeyFile) - if err != nil { - return nil, fmt.Errorf("could not extract TLS client key: %w", err) + if clientCertificate == nil { + return nil, fmt.Errorf("client ceritficate is missing") } - client, err := deckutils.GetKongClient(deckutils.KongClientConfig{ - Address: fmt.Sprintf("%s/%s/%s", c.Address, "kic/api/runtime_groups", c.RuntimeGroupID), - TLSClientCert: string(tlsClientCert), - TLSClientKey: string(tlsClientKey), - }) + tlsConfig := tls.Config{ + Certificates: []tls.Certificate{*clientCertificate}, + MinVersion: tls.VersionTLS12, + } + transport := http.DefaultTransport.(*http.Transport).Clone() + transport.TLSClientConfig = &tlsConfig + client, err := kong.NewClient( + lo.ToPtr(fmt.Sprintf("%s/%s/%s", c.Address, "kic/api/runtime_groups", c.RuntimeGroupID)), + &http.Client{ + Transport: transport, + }, + ) if err != nil { return nil, err } @@ -66,6 +79,7 @@ func ensureKonnectConnection(ctx context.Context, client *kong.Client) error { return nil }, retry.Attempts(retries), + retry.Context(ctx), retry.Delay(delay), retry.DelayType(retry.FixedDelay), retry.LastErrorOnly(true), diff --git a/internal/konnect/runtimegroups/client.gen.go b/internal/konnect/runtimegroups/client.gen.go new file mode 100644 index 0000000000..dffb61916f --- /dev/null +++ b/internal/konnect/runtimegroups/client.gen.go @@ -0,0 +1,2020 @@ +// Package runtimegroups provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. +package runtimegroups + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" + + "github.com/deepmap/oapi-codegen/pkg/runtime" + openapi_types "github.com/deepmap/oapi-codegen/pkg/types" +) + +const ( + AccessTokenScopes = "accessToken.Scopes" + PersonalAccessTokenScopes = "personalAccessToken.Scopes" +) + +// Defines values for Status400. +const ( + N400 Status400 = 400 +) + +// Defines values for Status401. +const ( + N401 Status401 = 401 +) + +// Defines values for Status403. +const ( + N403 Status403 = 403 +) + +// Defines values for Status404. +const ( + N404 Status404 = 404 +) + +// Defines values for Status409. +const ( + N409 Status409 = 409 +) + +// Defines values for Status500. +const ( + N500 Status500 = 500 +) + +// Defines values for Status503. +const ( + N503 Status503 = 503 +) + +// AdditionalErrorInformation An array of objects that contains information related to the error response. +type AdditionalErrorInformation = []AdditionalErrorInformation_Item + +// AdditionalErrorInformation_Item defines model for AdditionalErrorInformation.Item. +type AdditionalErrorInformation_Item struct { + Field *string `json:"field,omitempty"` + Reason *string `json:"reason,omitempty"` + Rule *string `json:"rule,omitempty"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// CreateRuntimeGroupRequest The request schema for the create runtime group request. +type CreateRuntimeGroupRequest struct { + // Description The description of the runtime group in Konnect. + Description *string `json:"description,omitempty"` + + // Labels Labels to facilitate tagged search on runtime groups. Keys must be of length 1-63 characters, and cannot start with 'kong', 'konnect', 'mesh', 'kic', or '_'. + Labels *Labels `json:"labels,omitempty"` + + // Name The name of the runtime group. + Name string `json:"name"` +} + +// Labels Labels to facilitate tagged search on runtime groups. Keys must be of length 1-63 characters, and cannot start with 'kong', 'konnect', 'mesh', 'kic', or '_'. +type Labels map[string]string + +// PaginatedMeta Returns pagination information +type PaginatedMeta struct { + // Page Contains pagination query parameters and the total number of objects returned. + Page *struct { + // Number Specifies the number of objects returned per page. + Number *int `json:"number,omitempty"` + + // Size Specifies the size of the page. + Size *int `json:"size,omitempty"` + + // Total Integer representation of the amount of items returned. + Total *int `json:"total,omitempty"` + } `json:"page,omitempty"` +} + +// RuntimeGroup The runtime group object contains information about a Kong control plane. +type RuntimeGroup struct { + // Config CP configuration object for related access endpoints. + Config *struct { + // ControlPlaneEndpoint Control Plane Endpoint. + ControlPlaneEndpoint *string `json:"control_plane_endpoint,omitempty"` + + // TelemetryEndpoint Telemetry Endpoint. + TelemetryEndpoint *string `json:"telemetry_endpoint,omitempty"` + } `json:"config,omitempty"` + + // CreatedAt An ISO-8604 timestamp representation of runtime group creation date. + CreatedAt *time.Time `json:"created_at,omitempty"` + + // Description The description of the runtime group in Konnect. + Description *string `json:"description,omitempty"` + + // Id The runtime group ID. + Id *openapi_types.UUID `json:"id,omitempty"` + + // Labels Labels to facilitate tagged search on runtime groups. Keys must be of length 1-63 characters, and cannot start with 'kong', 'konnect', 'mesh', 'kic', or '_'. + Labels *Labels `json:"labels,omitempty"` + + // Name The name of the runtime group. + Name *string `json:"name,omitempty"` + + // UpdatedAt An ISO-8604 timestamp representation of runtime group update date. + UpdatedAt *time.Time `json:"updated_at,omitempty"` +} + +// Status400 The HTTP response code +type Status400 int + +// Status401 The HTTP status code. +type Status401 int + +// Status403 The HTTP status code. +type Status403 int + +// Status404 The HTTP status code. +type Status404 int + +// Status409 The HTTP status code. +type Status409 int + +// Status500 The HTTP status code. +type Status500 int + +// Status503 The HTTP status code. +type Status503 int + +// UpdateRuntimeGroupRequest The request schema for the update runtime group request. +type UpdateRuntimeGroupRequest struct { + // Description The description of the runtime group in Konnect. + Description *string `json:"description,omitempty"` + + // Labels Labels to facilitate tagged search on runtime groups. Keys must be of length 1-63 characters, and cannot start with 'kong', 'konnect', 'mesh', 'kic', or '_'. + Labels *Labels `json:"labels,omitempty"` + + // Name The name of the runtime group. + Name *string `json:"name,omitempty"` +} + +// FilterByNameContains defines model for FilterByNameContains. +type FilterByNameContains = string + +// FilterByNameEquality defines model for FilterByNameEquality. +type FilterByNameEquality = string + +// FilterByNameEqualityShort defines model for FilterByNameEqualityShort. +type FilterByNameEqualityShort = string + +// PageNumber defines model for PageNumber. +type PageNumber = int + +// PageSize defines model for PageSize. +type PageSize = int + +// CreateRuntimeGroupResponse The runtime group object contains information about a Kong control plane. +type CreateRuntimeGroupResponse = RuntimeGroup + +// ListRuntimeGroupsResponse defines model for ListRuntimeGroupsResponse. +type ListRuntimeGroupsResponse struct { + Data *[]RuntimeGroup `json:"data,omitempty"` + + // Meta Returns pagination information + Meta *PaginatedMeta `json:"meta,omitempty"` +} + +// RetrieveRuntimeGroupResponse The runtime group object contains information about a Kong control plane. +type RetrieveRuntimeGroupResponse = RuntimeGroup + +// UpdateRuntimeGroupResponse The runtime group object contains information about a Kong control plane. +type UpdateRuntimeGroupResponse = RuntimeGroup + +// ListRuntimeGroupsParams defines parameters for ListRuntimeGroups. +type ListRuntimeGroupsParams struct { + // PageSize How many items to include in a page. + PageSize *PageSize `form:"page[size],omitempty" json:"page[size],omitempty"` + + // PageNumber The specific page number in the collection results. + PageNumber *PageNumber `form:"page[number],omitempty" json:"page[number],omitempty"` + + // FilterNameEq Filter by direct equality comparison of the name property with a supplied value. + FilterNameEq *FilterByNameEquality `form:"filter[name][eq],omitempty" json:"filter[name][eq],omitempty"` + + // FilterName Filter by direct equality comparison (short-hand) of the name property with a supplied value. + FilterName *FilterByNameEqualityShort `form:"filter[name],omitempty" json:"filter[name],omitempty"` + + // FilterNameContains Filter by contains comparison of the name property with a supplied substring + FilterNameContains *FilterByNameContains `form:"filter[name][contains],omitempty" json:"filter[name][contains],omitempty"` +} + +// CreateRuntimeGroupJSONRequestBody defines body for CreateRuntimeGroup for application/json ContentType. +type CreateRuntimeGroupJSONRequestBody = CreateRuntimeGroupRequest + +// UpdateRuntimeGroupJSONRequestBody defines body for UpdateRuntimeGroup for application/json ContentType. +type UpdateRuntimeGroupJSONRequestBody = UpdateRuntimeGroupRequest + +// Getter for additional properties for AdditionalErrorInformation_Item. Returns the specified +// element and whether it was found +func (a AdditionalErrorInformation_Item) Get(fieldName string) (value interface{}, found bool) { + if a.AdditionalProperties != nil { + value, found = a.AdditionalProperties[fieldName] + } + return +} + +// Setter for additional properties for AdditionalErrorInformation_Item +func (a *AdditionalErrorInformation_Item) Set(fieldName string, value interface{}) { + if a.AdditionalProperties == nil { + a.AdditionalProperties = make(map[string]interface{}) + } + a.AdditionalProperties[fieldName] = value +} + +// Override default JSON handling for AdditionalErrorInformation_Item to handle AdditionalProperties +func (a *AdditionalErrorInformation_Item) UnmarshalJSON(b []byte) error { + object := make(map[string]json.RawMessage) + err := json.Unmarshal(b, &object) + if err != nil { + return err + } + + if raw, found := object["field"]; found { + err = json.Unmarshal(raw, &a.Field) + if err != nil { + return fmt.Errorf("error reading 'field': %w", err) + } + delete(object, "field") + } + + if raw, found := object["reason"]; found { + err = json.Unmarshal(raw, &a.Reason) + if err != nil { + return fmt.Errorf("error reading 'reason': %w", err) + } + delete(object, "reason") + } + + if raw, found := object["rule"]; found { + err = json.Unmarshal(raw, &a.Rule) + if err != nil { + return fmt.Errorf("error reading 'rule': %w", err) + } + delete(object, "rule") + } + + if len(object) != 0 { + a.AdditionalProperties = make(map[string]interface{}) + for fieldName, fieldBuf := range object { + var fieldVal interface{} + err := json.Unmarshal(fieldBuf, &fieldVal) + if err != nil { + return fmt.Errorf("error unmarshalling field %s: %w", fieldName, err) + } + a.AdditionalProperties[fieldName] = fieldVal + } + } + return nil +} + +// Override default JSON handling for AdditionalErrorInformation_Item to handle AdditionalProperties +func (a AdditionalErrorInformation_Item) MarshalJSON() ([]byte, error) { + var err error + object := make(map[string]json.RawMessage) + + if a.Field != nil { + object["field"], err = json.Marshal(a.Field) + if err != nil { + return nil, fmt.Errorf("error marshaling 'field': %w", err) + } + } + + if a.Reason != nil { + object["reason"], err = json.Marshal(a.Reason) + if err != nil { + return nil, fmt.Errorf("error marshaling 'reason': %w", err) + } + } + + if a.Rule != nil { + object["rule"], err = json.Marshal(a.Rule) + if err != nil { + return nil, fmt.Errorf("error marshaling 'rule': %w", err) + } + } + + for fieldName, field := range a.AdditionalProperties { + object[fieldName], err = json.Marshal(field) + if err != nil { + return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err) + } + } + return json.Marshal(object) +} + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // ListRuntimeGroups request + ListRuntimeGroups(ctx context.Context, params *ListRuntimeGroupsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateRuntimeGroup request with any body + CreateRuntimeGroupWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateRuntimeGroup(ctx context.Context, body CreateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteRuntimeGroup request + DeleteRuntimeGroup(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetRuntimeGroup request + GetRuntimeGroup(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // UpdateRuntimeGroup request with any body + UpdateRuntimeGroupWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + UpdateRuntimeGroup(ctx context.Context, id openapi_types.UUID, body UpdateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) ListRuntimeGroups(ctx context.Context, params *ListRuntimeGroupsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListRuntimeGroupsRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateRuntimeGroupWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateRuntimeGroupRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateRuntimeGroup(ctx context.Context, body CreateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateRuntimeGroupRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteRuntimeGroup(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteRuntimeGroupRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetRuntimeGroup(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetRuntimeGroupRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) UpdateRuntimeGroupWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateRuntimeGroupRequestWithBody(c.Server, id, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) UpdateRuntimeGroup(ctx context.Context, id openapi_types.UUID, body UpdateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateRuntimeGroupRequest(c.Server, id, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewListRuntimeGroupsRequest generates requests for ListRuntimeGroups +func NewListRuntimeGroupsRequest(server string, params *ListRuntimeGroupsParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/runtime-groups") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + queryValues := queryURL.Query() + + if params.PageSize != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "page[size]", runtime.ParamLocationQuery, *params.PageSize); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.PageNumber != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "page[number]", runtime.ParamLocationQuery, *params.PageNumber); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.FilterNameEq != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "filter[name][eq]", runtime.ParamLocationQuery, *params.FilterNameEq); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.FilterName != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "filter[name]", runtime.ParamLocationQuery, *params.FilterName); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.FilterNameContains != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "filter[name][contains]", runtime.ParamLocationQuery, *params.FilterNameContains); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateRuntimeGroupRequest calls the generic CreateRuntimeGroup builder with application/json body +func NewCreateRuntimeGroupRequest(server string, body CreateRuntimeGroupJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateRuntimeGroupRequestWithBody(server, "application/json", bodyReader) +} + +// NewCreateRuntimeGroupRequestWithBody generates requests for CreateRuntimeGroup with any type of body +func NewCreateRuntimeGroupRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/runtime-groups") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewDeleteRuntimeGroupRequest generates requests for DeleteRuntimeGroup +func NewDeleteRuntimeGroupRequest(server string, id openapi_types.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/runtime-groups/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetRuntimeGroupRequest generates requests for GetRuntimeGroup +func NewGetRuntimeGroupRequest(server string, id openapi_types.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/runtime-groups/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewUpdateRuntimeGroupRequest calls the generic UpdateRuntimeGroup builder with application/json body +func NewUpdateRuntimeGroupRequest(server string, id openapi_types.UUID, body UpdateRuntimeGroupJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewUpdateRuntimeGroupRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewUpdateRuntimeGroupRequestWithBody generates requests for UpdateRuntimeGroup with any type of body +func NewUpdateRuntimeGroupRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/runtime-groups/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PATCH", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // ListRuntimeGroups request + ListRuntimeGroupsWithResponse(ctx context.Context, params *ListRuntimeGroupsParams, reqEditors ...RequestEditorFn) (*ListRuntimeGroupsHTTPResponse, error) + + // CreateRuntimeGroup request with any body + CreateRuntimeGroupWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateRuntimeGroupHTTPResponse, error) + + CreateRuntimeGroupWithResponse(ctx context.Context, body CreateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateRuntimeGroupHTTPResponse, error) + + // DeleteRuntimeGroup request + DeleteRuntimeGroupWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*DeleteRuntimeGroupHTTPResponse, error) + + // GetRuntimeGroup request + GetRuntimeGroupWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetRuntimeGroupHTTPResponse, error) + + // UpdateRuntimeGroup request with any body + UpdateRuntimeGroupWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateRuntimeGroupHTTPResponse, error) + + UpdateRuntimeGroupWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateRuntimeGroupHTTPResponse, error) +} + +type ListRuntimeGroupsHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Data *[]RuntimeGroup `json:"data,omitempty"` + + // Meta Returns pagination information + Meta *PaginatedMeta `json:"meta,omitempty"` + } + JSON400 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + JSON401 *struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + JSON403 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + JSON503 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } +} + +// Status returns HTTPResponse.Status +func (r ListRuntimeGroupsHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListRuntimeGroupsHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateRuntimeGroupHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *RuntimeGroup + JSON400 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + JSON401 *struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + JSON403 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + JSON409 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status409 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON500 *struct { + // Details Details about the error. + Details *string `json:"details,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status500 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON503 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } +} + +// Status returns HTTPResponse.Status +func (r CreateRuntimeGroupHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateRuntimeGroupHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteRuntimeGroupHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + JSON401 *struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + JSON403 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + JSON404 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status404 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON500 *struct { + // Details Details about the error. + Details *string `json:"details,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status500 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON503 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } +} + +// Status returns HTTPResponse.Status +func (r DeleteRuntimeGroupHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteRuntimeGroupHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetRuntimeGroupHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *RuntimeGroup + JSON400 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + JSON401 *struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + JSON403 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + JSON404 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status404 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON503 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } +} + +// Status returns HTTPResponse.Status +func (r GetRuntimeGroupHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetRuntimeGroupHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type UpdateRuntimeGroupHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *RuntimeGroup + JSON400 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + JSON401 *struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + JSON403 *struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + JSON404 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status404 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON500 *struct { + // Details Details about the error. + Details *string `json:"details,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status500 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + JSON503 *struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } +} + +// Status returns HTTPResponse.Status +func (r UpdateRuntimeGroupHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UpdateRuntimeGroupHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ListRuntimeGroupsWithResponse request returning *ListRuntimeGroupsHTTPResponse +func (c *ClientWithResponses) ListRuntimeGroupsWithResponse(ctx context.Context, params *ListRuntimeGroupsParams, reqEditors ...RequestEditorFn) (*ListRuntimeGroupsHTTPResponse, error) { + rsp, err := c.ListRuntimeGroups(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListRuntimeGroupsHTTPResponse(rsp) +} + +// CreateRuntimeGroupWithBodyWithResponse request with arbitrary body returning *CreateRuntimeGroupHTTPResponse +func (c *ClientWithResponses) CreateRuntimeGroupWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateRuntimeGroupHTTPResponse, error) { + rsp, err := c.CreateRuntimeGroupWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateRuntimeGroupHTTPResponse(rsp) +} + +func (c *ClientWithResponses) CreateRuntimeGroupWithResponse(ctx context.Context, body CreateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateRuntimeGroupHTTPResponse, error) { + rsp, err := c.CreateRuntimeGroup(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateRuntimeGroupHTTPResponse(rsp) +} + +// DeleteRuntimeGroupWithResponse request returning *DeleteRuntimeGroupHTTPResponse +func (c *ClientWithResponses) DeleteRuntimeGroupWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*DeleteRuntimeGroupHTTPResponse, error) { + rsp, err := c.DeleteRuntimeGroup(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteRuntimeGroupHTTPResponse(rsp) +} + +// GetRuntimeGroupWithResponse request returning *GetRuntimeGroupHTTPResponse +func (c *ClientWithResponses) GetRuntimeGroupWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetRuntimeGroupHTTPResponse, error) { + rsp, err := c.GetRuntimeGroup(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetRuntimeGroupHTTPResponse(rsp) +} + +// UpdateRuntimeGroupWithBodyWithResponse request with arbitrary body returning *UpdateRuntimeGroupHTTPResponse +func (c *ClientWithResponses) UpdateRuntimeGroupWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateRuntimeGroupHTTPResponse, error) { + rsp, err := c.UpdateRuntimeGroupWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateRuntimeGroupHTTPResponse(rsp) +} + +func (c *ClientWithResponses) UpdateRuntimeGroupWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateRuntimeGroupJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateRuntimeGroupHTTPResponse, error) { + rsp, err := c.UpdateRuntimeGroup(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateRuntimeGroupHTTPResponse(rsp) +} + +// ParseListRuntimeGroupsHTTPResponse parses an HTTP response from a ListRuntimeGroupsWithResponse call +func ParseListRuntimeGroupsHTTPResponse(rsp *http.Response) (*ListRuntimeGroupsHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListRuntimeGroupsHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Data *[]RuntimeGroup `json:"data,omitempty"` + + // Meta Returns pagination information + Meta *PaginatedMeta `json:"meta,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON503 = &dest + + } + + return response, nil +} + +// ParseCreateRuntimeGroupHTTPResponse parses an HTTP response from a CreateRuntimeGroupWithResponse call +func ParseCreateRuntimeGroupHTTPResponse(rsp *http.Response) (*CreateRuntimeGroupHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateRuntimeGroupHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest RuntimeGroup + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 409: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status409 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON409 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest struct { + // Details Details about the error. + Details *string `json:"details,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status500 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON503 = &dest + + } + + return response, nil +} + +// ParseDeleteRuntimeGroupHTTPResponse parses an HTTP response from a DeleteRuntimeGroupWithResponse call +func ParseDeleteRuntimeGroupHTTPResponse(rsp *http.Response) (*DeleteRuntimeGroupHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteRuntimeGroupHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status404 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest struct { + // Details Details about the error. + Details *string `json:"details,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status500 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON503 = &dest + + } + + return response, nil +} + +// ParseGetRuntimeGroupHTTPResponse parses an HTTP response from a GetRuntimeGroupWithResponse call +func ParseGetRuntimeGroupHTTPResponse(rsp *http.Response) (*GetRuntimeGroupHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetRuntimeGroupHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest RuntimeGroup + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status404 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON503 = &dest + + } + + return response, nil +} + +// ParseUpdateRuntimeGroupHTTPResponse parses an HTTP response from a UpdateRuntimeGroupWithResponse call +func ParseUpdateRuntimeGroupHTTPResponse(rsp *http.Response) (*UpdateRuntimeGroupHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &UpdateRuntimeGroupHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest RuntimeGroup + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback ID. + Instance *string `json:"instance,omitempty"` + + // InvalidParameters An array of objects that contains information related to the error response. + InvalidParameters *AdditionalErrorInformation `json:"invalid_parameters,omitempty"` + + // Status The HTTP response code + Status Status400 `json:"status"` + + // Title The Error response + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + // Detail Details about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status401 `json:"status"` + + // Title The Error Response. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest struct { + // Detail Information about the error response. + Detail *string `json:"detail,omitempty"` + + // Instance Konnect traceback error code. + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status403 `json:"status"` + + // Title HTTP status code + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status404 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest struct { + // Details Details about the error. + Details *string `json:"details,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status500 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: + var dest struct { + // Detail Details about the error. + Detail *string `json:"detail,omitempty"` + + // Instance The Konnect traceback code + Instance *string `json:"instance,omitempty"` + + // Status The HTTP status code. + Status Status503 `json:"status"` + + // Title The error response code. + Title string `json:"title"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON503 = &dest + + } + + return response, nil +} diff --git a/internal/konnect/runtimegroupsconfig/client.gen.go b/internal/konnect/runtimegroupsconfig/client.gen.go new file mode 100644 index 0000000000..dd43a5b9b7 --- /dev/null +++ b/internal/konnect/runtimegroupsconfig/client.gen.go @@ -0,0 +1,1753 @@ +// Package runtimegroupsconfig provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. +package runtimegroupsconfig + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/deepmap/oapi-codegen/pkg/runtime" +) + +// PageNumber defines model for page_number. +type PageNumber = int + +// PageSize defines model for page_size. +type PageSize = int + +// GetDpClientCert defines model for get-dp-client-cert. +type GetDpClientCert struct { + Item *struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"item,omitempty"` +} + +// GetExpectedConfigHash defines model for get-expected-config-hash. +type GetExpectedConfigHash struct { + // CreatedAt Date the runtime group configuration was created. + CreatedAt *int `json:"created_at,omitempty"` + + // ExpectedHash The expected configuration hash. + ExpectedHash *string `json:"expected_hash,omitempty"` + + // UpdatedAt Date the runtime group configuration was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` +} + +// GetNode defines model for get-node. +type GetNode struct { + Item *struct { + CompatibilityStatus *struct { + State *string `json:"state,omitempty"` + } `json:"compatibility_status,omitempty"` + ConfigHash *string `json:"config_hash,omitempty"` + CreatedAt *int `json:"created_at,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Id *string `json:"id,omitempty"` + LastPing *int `json:"last_ping,omitempty"` + Type *string `json:"type,omitempty"` + UpdatedAt *int `json:"updated_at,omitempty"` + Version *string `json:"version,omitempty"` + } `json:"item,omitempty"` +} + +// ListDpClientCerts defines model for list-dp-client-certs. +type ListDpClientCerts struct { + Items *[]struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"items,omitempty"` + Page *struct { + TotalCount *int `json:"total_count,omitempty"` + } `json:"page,omitempty"` +} + +// ListNodes defines model for list-nodes. +type ListNodes struct { + Items *[]struct { + CompatibilityStatus *struct { + State *string `json:"state,omitempty"` + } `json:"compatibility_status,omitempty"` + ConfigHash *string `json:"config_hash,omitempty"` + CreatedAt *int `json:"created_at,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Id *string `json:"id,omitempty"` + LastPing *int `json:"last_ping,omitempty"` + Type *string `json:"type,omitempty"` + UpdatedAt *int `json:"updated_at,omitempty"` + Version *string `json:"version,omitempty"` + } `json:"items,omitempty"` + Page *struct { + TotalCount *int `json:"total_count,omitempty"` + } `json:"page,omitempty"` +} + +// CreateDpClientCert defines model for create-dp-client-cert. +type CreateDpClientCert struct { + // Cert JSON escaped string of the certificate. + Cert string `json:"cert"` +} + +// GetDpClientCertificatesParams defines parameters for GetDpClientCertificates. +type GetDpClientCertificatesParams struct { + // PageSize The number of items to include in a page. + PageSize *PageSize `form:"page_size,omitempty" json:"page_size,omitempty"` + + // PageNumber The specific page number in the collection results. + PageNumber *PageNumber `form:"page_number,omitempty" json:"page_number,omitempty"` +} + +// PostDpClientCertificatesJSONBody defines parameters for PostDpClientCertificates. +type PostDpClientCertificatesJSONBody struct { + // Cert JSON escaped string of the certificate. + Cert string `json:"cert"` +} + +// GetNodesParams defines parameters for GetNodes. +type GetNodesParams struct { + // PageSize The number of items to include in a page. + PageSize *PageSize `form:"page_size,omitempty" json:"page_size,omitempty"` + + // PageNumber The specific page number in the collection results. + PageNumber *PageNumber `form:"page_number,omitempty" json:"page_number,omitempty"` +} + +// PostDpClientCertificatesJSONRequestBody defines body for PostDpClientCertificates for application/json ContentType. +type PostDpClientCertificatesJSONRequestBody PostDpClientCertificatesJSONBody + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // DeleteCoreEntities request + DeleteCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetCoreEntities request + GetCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PostCoreEntities request + PostCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PutCoreEntities request + PutCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetDpClientCertificates request + GetDpClientCertificates(ctx context.Context, params *GetDpClientCertificatesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PostDpClientCertificates request with any body + PostDpClientCertificatesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostDpClientCertificates(ctx context.Context, body PostDpClientCertificatesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteDpClientCertificatesCertId request + DeleteDpClientCertificatesCertId(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetDpClientCertificatesCertId request + GetDpClientCertificatesCertId(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetExpectedConfigHash request + GetExpectedConfigHash(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetNodes request + GetNodes(ctx context.Context, params *GetNodesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteNodesNodeId request + DeleteNodesNodeId(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetNodesNodeId request + GetNodesNodeId(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) DeleteCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteCoreEntitiesRequest(c.Server, entityEndpoint) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetCoreEntitiesRequest(c.Server, entityEndpoint) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostCoreEntitiesRequest(c.Server, entityEndpoint) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PutCoreEntities(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPutCoreEntitiesRequest(c.Server, entityEndpoint) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetDpClientCertificates(ctx context.Context, params *GetDpClientCertificatesParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDpClientCertificatesRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostDpClientCertificatesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostDpClientCertificatesRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostDpClientCertificates(ctx context.Context, body PostDpClientCertificatesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostDpClientCertificatesRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteDpClientCertificatesCertId(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteDpClientCertificatesCertIdRequest(c.Server, certificateId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetDpClientCertificatesCertId(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDpClientCertificatesCertIdRequest(c.Server, certificateId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetExpectedConfigHash(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetExpectedConfigHashRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetNodes(ctx context.Context, params *GetNodesParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetNodesRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteNodesNodeId(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteNodesNodeIdRequest(c.Server, nodeId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetNodesNodeId(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetNodesNodeIdRequest(c.Server, nodeId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewDeleteCoreEntitiesRequest generates requests for DeleteCoreEntities +func NewDeleteCoreEntitiesRequest(server string, entityEndpoint string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "entityEndpoint", runtime.ParamLocationPath, entityEndpoint) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/core-entities/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetCoreEntitiesRequest generates requests for GetCoreEntities +func NewGetCoreEntitiesRequest(server string, entityEndpoint string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "entityEndpoint", runtime.ParamLocationPath, entityEndpoint) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/core-entities/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPostCoreEntitiesRequest generates requests for PostCoreEntities +func NewPostCoreEntitiesRequest(server string, entityEndpoint string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "entityEndpoint", runtime.ParamLocationPath, entityEndpoint) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/core-entities/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPutCoreEntitiesRequest generates requests for PutCoreEntities +func NewPutCoreEntitiesRequest(server string, entityEndpoint string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "entityEndpoint", runtime.ParamLocationPath, entityEndpoint) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/core-entities/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PUT", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetDpClientCertificatesRequest generates requests for GetDpClientCertificates +func NewGetDpClientCertificatesRequest(server string, params *GetDpClientCertificatesParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/dp-client-certificates") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + queryValues := queryURL.Query() + + if params.PageSize != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "page_size", runtime.ParamLocationQuery, *params.PageSize); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.PageNumber != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "page_number", runtime.ParamLocationQuery, *params.PageNumber); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPostDpClientCertificatesRequest calls the generic PostDpClientCertificates builder with application/json body +func NewPostDpClientCertificatesRequest(server string, body PostDpClientCertificatesJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostDpClientCertificatesRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostDpClientCertificatesRequestWithBody generates requests for PostDpClientCertificates with any type of body +func NewPostDpClientCertificatesRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/dp-client-certificates") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewDeleteDpClientCertificatesCertIdRequest generates requests for DeleteDpClientCertificatesCertId +func NewDeleteDpClientCertificatesCertIdRequest(server string, certificateId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "certificateId", runtime.ParamLocationPath, certificateId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/dp-client-certificates/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetDpClientCertificatesCertIdRequest generates requests for GetDpClientCertificatesCertId +func NewGetDpClientCertificatesCertIdRequest(server string, certificateId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "certificateId", runtime.ParamLocationPath, certificateId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/dp-client-certificates/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetExpectedConfigHashRequest generates requests for GetExpectedConfigHash +func NewGetExpectedConfigHashRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/expected-config-hash") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetNodesRequest generates requests for GetNodes +func NewGetNodesRequest(server string, params *GetNodesParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/nodes") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + queryValues := queryURL.Query() + + if params.PageSize != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "page_size", runtime.ParamLocationQuery, *params.PageSize); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.PageNumber != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "page_number", runtime.ParamLocationQuery, *params.PageNumber); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewDeleteNodesNodeIdRequest generates requests for DeleteNodesNodeId +func NewDeleteNodesNodeIdRequest(server string, nodeId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "nodeId", runtime.ParamLocationPath, nodeId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/nodes/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetNodesNodeIdRequest generates requests for GetNodesNodeId +func NewGetNodesNodeIdRequest(server string, nodeId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "nodeId", runtime.ParamLocationPath, nodeId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/nodes/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // DeleteCoreEntities request + DeleteCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*DeleteCoreEntitiesHTTPResponse, error) + + // GetCoreEntities request + GetCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*GetCoreEntitiesHTTPResponse, error) + + // PostCoreEntities request + PostCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*PostCoreEntitiesHTTPResponse, error) + + // PutCoreEntities request + PutCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*PutCoreEntitiesHTTPResponse, error) + + // GetDpClientCertificates request + GetDpClientCertificatesWithResponse(ctx context.Context, params *GetDpClientCertificatesParams, reqEditors ...RequestEditorFn) (*GetDpClientCertificatesHTTPResponse, error) + + // PostDpClientCertificates request with any body + PostDpClientCertificatesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostDpClientCertificatesHTTPResponse, error) + + PostDpClientCertificatesWithResponse(ctx context.Context, body PostDpClientCertificatesJSONRequestBody, reqEditors ...RequestEditorFn) (*PostDpClientCertificatesHTTPResponse, error) + + // DeleteDpClientCertificatesCertId request + DeleteDpClientCertificatesCertIdWithResponse(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*DeleteDpClientCertificatesCertIdHTTPResponse, error) + + // GetDpClientCertificatesCertId request + GetDpClientCertificatesCertIdWithResponse(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*GetDpClientCertificatesCertIdHTTPResponse, error) + + // GetExpectedConfigHash request + GetExpectedConfigHashWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetExpectedConfigHashHTTPResponse, error) + + // GetNodes request + GetNodesWithResponse(ctx context.Context, params *GetNodesParams, reqEditors ...RequestEditorFn) (*GetNodesHTTPResponse, error) + + // DeleteNodesNodeId request + DeleteNodesNodeIdWithResponse(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*DeleteNodesNodeIdHTTPResponse, error) + + // GetNodesNodeId request + GetNodesNodeIdWithResponse(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*GetNodesNodeIdHTTPResponse, error) +} + +type DeleteCoreEntitiesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r DeleteCoreEntitiesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteCoreEntitiesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetCoreEntitiesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r GetCoreEntitiesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetCoreEntitiesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PostCoreEntitiesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r PostCoreEntitiesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostCoreEntitiesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PutCoreEntitiesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r PutCoreEntitiesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PutCoreEntitiesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetDpClientCertificatesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Items *[]struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"items,omitempty"` + Page *struct { + TotalCount *int `json:"total_count,omitempty"` + } `json:"page,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r GetDpClientCertificatesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDpClientCertificatesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PostDpClientCertificatesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *struct { + Item *struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"item,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r PostDpClientCertificatesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostDpClientCertificatesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteDpClientCertificatesCertIdHTTPResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r DeleteDpClientCertificatesCertIdHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteDpClientCertificatesCertIdHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetDpClientCertificatesCertIdHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Item *struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"item,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r GetDpClientCertificatesCertIdHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDpClientCertificatesCertIdHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetExpectedConfigHashHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + // CreatedAt Date the runtime group configuration was created. + CreatedAt *int `json:"created_at,omitempty"` + + // ExpectedHash The expected configuration hash. + ExpectedHash *string `json:"expected_hash,omitempty"` + + // UpdatedAt Date the runtime group configuration was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r GetExpectedConfigHashHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetExpectedConfigHashHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetNodesHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Items *[]struct { + CompatibilityStatus *struct { + State *string `json:"state,omitempty"` + } `json:"compatibility_status,omitempty"` + ConfigHash *string `json:"config_hash,omitempty"` + CreatedAt *int `json:"created_at,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Id *string `json:"id,omitempty"` + LastPing *int `json:"last_ping,omitempty"` + Type *string `json:"type,omitempty"` + UpdatedAt *int `json:"updated_at,omitempty"` + Version *string `json:"version,omitempty"` + } `json:"items,omitempty"` + Page *struct { + TotalCount *int `json:"total_count,omitempty"` + } `json:"page,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r GetNodesHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetNodesHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteNodesNodeIdHTTPResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r DeleteNodesNodeIdHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteNodesNodeIdHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetNodesNodeIdHTTPResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Item *struct { + CompatibilityStatus *struct { + State *string `json:"state,omitempty"` + } `json:"compatibility_status,omitempty"` + ConfigHash *string `json:"config_hash,omitempty"` + CreatedAt *int `json:"created_at,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Id *string `json:"id,omitempty"` + LastPing *int `json:"last_ping,omitempty"` + Type *string `json:"type,omitempty"` + UpdatedAt *int `json:"updated_at,omitempty"` + Version *string `json:"version,omitempty"` + } `json:"item,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r GetNodesNodeIdHTTPResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetNodesNodeIdHTTPResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// DeleteCoreEntitiesWithResponse request returning *DeleteCoreEntitiesHTTPResponse +func (c *ClientWithResponses) DeleteCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*DeleteCoreEntitiesHTTPResponse, error) { + rsp, err := c.DeleteCoreEntities(ctx, entityEndpoint, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteCoreEntitiesHTTPResponse(rsp) +} + +// GetCoreEntitiesWithResponse request returning *GetCoreEntitiesHTTPResponse +func (c *ClientWithResponses) GetCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*GetCoreEntitiesHTTPResponse, error) { + rsp, err := c.GetCoreEntities(ctx, entityEndpoint, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetCoreEntitiesHTTPResponse(rsp) +} + +// PostCoreEntitiesWithResponse request returning *PostCoreEntitiesHTTPResponse +func (c *ClientWithResponses) PostCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*PostCoreEntitiesHTTPResponse, error) { + rsp, err := c.PostCoreEntities(ctx, entityEndpoint, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostCoreEntitiesHTTPResponse(rsp) +} + +// PutCoreEntitiesWithResponse request returning *PutCoreEntitiesHTTPResponse +func (c *ClientWithResponses) PutCoreEntitiesWithResponse(ctx context.Context, entityEndpoint string, reqEditors ...RequestEditorFn) (*PutCoreEntitiesHTTPResponse, error) { + rsp, err := c.PutCoreEntities(ctx, entityEndpoint, reqEditors...) + if err != nil { + return nil, err + } + return ParsePutCoreEntitiesHTTPResponse(rsp) +} + +// GetDpClientCertificatesWithResponse request returning *GetDpClientCertificatesHTTPResponse +func (c *ClientWithResponses) GetDpClientCertificatesWithResponse(ctx context.Context, params *GetDpClientCertificatesParams, reqEditors ...RequestEditorFn) (*GetDpClientCertificatesHTTPResponse, error) { + rsp, err := c.GetDpClientCertificates(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDpClientCertificatesHTTPResponse(rsp) +} + +// PostDpClientCertificatesWithBodyWithResponse request with arbitrary body returning *PostDpClientCertificatesHTTPResponse +func (c *ClientWithResponses) PostDpClientCertificatesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostDpClientCertificatesHTTPResponse, error) { + rsp, err := c.PostDpClientCertificatesWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostDpClientCertificatesHTTPResponse(rsp) +} + +func (c *ClientWithResponses) PostDpClientCertificatesWithResponse(ctx context.Context, body PostDpClientCertificatesJSONRequestBody, reqEditors ...RequestEditorFn) (*PostDpClientCertificatesHTTPResponse, error) { + rsp, err := c.PostDpClientCertificates(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostDpClientCertificatesHTTPResponse(rsp) +} + +// DeleteDpClientCertificatesCertIdWithResponse request returning *DeleteDpClientCertificatesCertIdHTTPResponse +func (c *ClientWithResponses) DeleteDpClientCertificatesCertIdWithResponse(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*DeleteDpClientCertificatesCertIdHTTPResponse, error) { + rsp, err := c.DeleteDpClientCertificatesCertId(ctx, certificateId, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteDpClientCertificatesCertIdHTTPResponse(rsp) +} + +// GetDpClientCertificatesCertIdWithResponse request returning *GetDpClientCertificatesCertIdHTTPResponse +func (c *ClientWithResponses) GetDpClientCertificatesCertIdWithResponse(ctx context.Context, certificateId string, reqEditors ...RequestEditorFn) (*GetDpClientCertificatesCertIdHTTPResponse, error) { + rsp, err := c.GetDpClientCertificatesCertId(ctx, certificateId, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDpClientCertificatesCertIdHTTPResponse(rsp) +} + +// GetExpectedConfigHashWithResponse request returning *GetExpectedConfigHashHTTPResponse +func (c *ClientWithResponses) GetExpectedConfigHashWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetExpectedConfigHashHTTPResponse, error) { + rsp, err := c.GetExpectedConfigHash(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetExpectedConfigHashHTTPResponse(rsp) +} + +// GetNodesWithResponse request returning *GetNodesHTTPResponse +func (c *ClientWithResponses) GetNodesWithResponse(ctx context.Context, params *GetNodesParams, reqEditors ...RequestEditorFn) (*GetNodesHTTPResponse, error) { + rsp, err := c.GetNodes(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetNodesHTTPResponse(rsp) +} + +// DeleteNodesNodeIdWithResponse request returning *DeleteNodesNodeIdHTTPResponse +func (c *ClientWithResponses) DeleteNodesNodeIdWithResponse(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*DeleteNodesNodeIdHTTPResponse, error) { + rsp, err := c.DeleteNodesNodeId(ctx, nodeId, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteNodesNodeIdHTTPResponse(rsp) +} + +// GetNodesNodeIdWithResponse request returning *GetNodesNodeIdHTTPResponse +func (c *ClientWithResponses) GetNodesNodeIdWithResponse(ctx context.Context, nodeId string, reqEditors ...RequestEditorFn) (*GetNodesNodeIdHTTPResponse, error) { + rsp, err := c.GetNodesNodeId(ctx, nodeId, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetNodesNodeIdHTTPResponse(rsp) +} + +// ParseDeleteCoreEntitiesHTTPResponse parses an HTTP response from a DeleteCoreEntitiesWithResponse call +func ParseDeleteCoreEntitiesHTTPResponse(rsp *http.Response) (*DeleteCoreEntitiesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteCoreEntitiesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParseGetCoreEntitiesHTTPResponse parses an HTTP response from a GetCoreEntitiesWithResponse call +func ParseGetCoreEntitiesHTTPResponse(rsp *http.Response) (*GetCoreEntitiesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetCoreEntitiesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParsePostCoreEntitiesHTTPResponse parses an HTTP response from a PostCoreEntitiesWithResponse call +func ParsePostCoreEntitiesHTTPResponse(rsp *http.Response) (*PostCoreEntitiesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostCoreEntitiesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParsePutCoreEntitiesHTTPResponse parses an HTTP response from a PutCoreEntitiesWithResponse call +func ParsePutCoreEntitiesHTTPResponse(rsp *http.Response) (*PutCoreEntitiesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PutCoreEntitiesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParseGetDpClientCertificatesHTTPResponse parses an HTTP response from a GetDpClientCertificatesWithResponse call +func ParseGetDpClientCertificatesHTTPResponse(rsp *http.Response) (*GetDpClientCertificatesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDpClientCertificatesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Items *[]struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"items,omitempty"` + Page *struct { + TotalCount *int `json:"total_count,omitempty"` + } `json:"page,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePostDpClientCertificatesHTTPResponse parses an HTTP response from a PostDpClientCertificatesWithResponse call +func ParsePostDpClientCertificatesHTTPResponse(rsp *http.Response) (*PostDpClientCertificatesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostDpClientCertificatesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest struct { + Item *struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"item,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + +// ParseDeleteDpClientCertificatesCertIdHTTPResponse parses an HTTP response from a DeleteDpClientCertificatesCertIdWithResponse call +func ParseDeleteDpClientCertificatesCertIdHTTPResponse(rsp *http.Response) (*DeleteDpClientCertificatesCertIdHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteDpClientCertificatesCertIdHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParseGetDpClientCertificatesCertIdHTTPResponse parses an HTTP response from a GetDpClientCertificatesCertIdWithResponse call +func ParseGetDpClientCertificatesCertIdHTTPResponse(rsp *http.Response) (*GetDpClientCertificatesCertIdHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDpClientCertificatesCertIdHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Item *struct { + // Cert JSON escaped string of the certificate. + Cert *string `json:"cert,omitempty"` + + // CreatedAt Date certificate was created. + CreatedAt *int `json:"created_at,omitempty"` + + // Id Unique ID of the certificate entity. + Id *string `json:"id,omitempty"` + + // UpdatedAt Date certificate was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } `json:"item,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParseGetExpectedConfigHashHTTPResponse parses an HTTP response from a GetExpectedConfigHashWithResponse call +func ParseGetExpectedConfigHashHTTPResponse(rsp *http.Response) (*GetExpectedConfigHashHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetExpectedConfigHashHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + // CreatedAt Date the runtime group configuration was created. + CreatedAt *int `json:"created_at,omitempty"` + + // ExpectedHash The expected configuration hash. + ExpectedHash *string `json:"expected_hash,omitempty"` + + // UpdatedAt Date the runtime group configuration was last updated. + UpdatedAt *int `json:"updated_at,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParseGetNodesHTTPResponse parses an HTTP response from a GetNodesWithResponse call +func ParseGetNodesHTTPResponse(rsp *http.Response) (*GetNodesHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetNodesHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Items *[]struct { + CompatibilityStatus *struct { + State *string `json:"state,omitempty"` + } `json:"compatibility_status,omitempty"` + ConfigHash *string `json:"config_hash,omitempty"` + CreatedAt *int `json:"created_at,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Id *string `json:"id,omitempty"` + LastPing *int `json:"last_ping,omitempty"` + Type *string `json:"type,omitempty"` + UpdatedAt *int `json:"updated_at,omitempty"` + Version *string `json:"version,omitempty"` + } `json:"items,omitempty"` + Page *struct { + TotalCount *int `json:"total_count,omitempty"` + } `json:"page,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParseDeleteNodesNodeIdHTTPResponse parses an HTTP response from a DeleteNodesNodeIdWithResponse call +func ParseDeleteNodesNodeIdHTTPResponse(rsp *http.Response) (*DeleteNodesNodeIdHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteNodesNodeIdHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParseGetNodesNodeIdHTTPResponse parses an HTTP response from a GetNodesNodeIdWithResponse call +func ParseGetNodesNodeIdHTTPResponse(rsp *http.Response) (*GetNodesNodeIdHTTPResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetNodesNodeIdHTTPResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Item *struct { + CompatibilityStatus *struct { + State *string `json:"state,omitempty"` + } `json:"compatibility_status,omitempty"` + ConfigHash *string `json:"config_hash,omitempty"` + CreatedAt *int `json:"created_at,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Id *string `json:"id,omitempty"` + LastPing *int `json:"last_ping,omitempty"` + Type *string `json:"type,omitempty"` + UpdatedAt *int `json:"updated_at,omitempty"` + Version *string `json:"version,omitempty"` + } `json:"item,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} diff --git a/test/e2e/all_in_one_test.go b/test/e2e/all_in_one_test.go index ecd64c56d9..64fa49c758 100644 --- a/test/e2e/all_in_one_test.go +++ b/test/e2e/all_in_one_test.go @@ -13,7 +13,6 @@ import ( "testing" "time" - "github.com/kong/deck/dump" gokong "github.com/kong/go-kong/kong" "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong" "github.com/samber/lo" @@ -378,48 +377,7 @@ func TestDeployAllInOneDBLESSMultiGW(t *testing.T) { kongClient, err := gokong.NewClient(lo.ToPtr(address), client) require.NoError(t, err) - requireGatewayConfiguredEventually(ctx, t, kongClient, pod) + requireIngressConfiguredInAdminAPIEventually(ctx, t, kongClient) t.Logf("proxy pod %s/%s: got the config", pod.Namespace, pod.Name) } } - -func requireGatewayConfiguredEventually( - ctx context.Context, - t *testing.T, - kongClient *gokong.Client, - gatewayPod corev1.Pod, -) { - require.Eventually(t, func() bool { - d, err := dump.Get(ctx, kongClient, dump.Config{}) - if err != nil { - return false - } - if len(d.Services) != 1 { - t.Log("still not service found...") - return false - } - if len(d.Routes) != 1 { - t.Log("still no route found...") - return false - } - - if d.Services[0].ID == nil || - d.Routes[0].Service.ID == nil || - *d.Services[0].ID != *d.Routes[0].Service.ID { - t.Log("still no matching service found...") - return false - } - - if len(d.Targets) != 1 { - t.Log("still no target found...") - return false - } - - if len(d.Upstreams) != 1 { - t.Log("still no upstream found...") - return false - } - - return true - }, time.Minute*3, time.Second, "pod: %s/%s didn't get the config", gatewayPod.Namespace, gatewayPod.Name) -} diff --git a/test/e2e/helpers_test.go b/test/e2e/helpers_test.go index 397694555d..45b2b97886 100644 --- a/test/e2e/helpers_test.go +++ b/test/e2e/helpers_test.go @@ -19,6 +19,8 @@ import ( "github.com/blang/semver/v4" "github.com/google/uuid" + "github.com/kong/deck/dump" + gokong "github.com/kong/go-kong/kong" "github.com/kong/kubernetes-testing-framework/pkg/clusters" "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/loadimage" "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb" @@ -315,6 +317,47 @@ func verifyIngress(ctx context.Context, t *testing.T, env environments.Environme }, ingressWait, 100*time.Millisecond) } +// requireIngressConfiguredInAdminAPIEventually ensures all expected Kong Admin API resources are created for the Ingress +// deployed with deployIngress helper function. +func requireIngressConfiguredInAdminAPIEventually( + ctx context.Context, + t *testing.T, + kongClient *gokong.Client, +) { + t.Helper() + + require.Eventually(t, func() bool { + d, err := dump.Get(ctx, kongClient, dump.Config{}) + if err != nil { + t.Logf("failed dumping config: %s", err) + return false + } + if len(d.Services) != 1 { + t.Log("still no service found...") + return false + } + if len(d.Routes) != 1 { + t.Log("still no route found...") + return false + } + if d.Services[0].ID == nil || + d.Routes[0].Service.ID == nil || + *d.Services[0].ID != *d.Routes[0].Service.ID { + t.Log("still no matching service found...") + return false + } + if len(d.Targets) != 1 { + t.Log("still no target found...") + return false + } + if len(d.Upstreams) != 1 { + t.Log("still no upstream found...") + return false + } + return true + }, time.Minute*3, time.Second, "%q didn't get the config", kongClient.BaseRootURL()) +} + // verifyEnterprise performs some basic tests of the Kong Admin API in the provided // environment to ensure that the Admin API that responds is in fact the enterprise // version of Kong. diff --git a/test/e2e/konnect_test.go b/test/e2e/konnect_test.go new file mode 100644 index 0000000000..76d383024c --- /dev/null +++ b/test/e2e/konnect_test.go @@ -0,0 +1,229 @@ +//go:build e2e_tests + +package e2e + +import ( + "bytes" + "context" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "fmt" + "io" + "math/big" + "net/http" + "os" + "testing" + "time" + + "github.com/google/uuid" + environment "github.com/kong/kubernetes-testing-framework/pkg/environments" + "github.com/samber/lo" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/kong/kubernetes-ingress-controller/v2/internal/adminapi" + rg "github.com/kong/kubernetes-ingress-controller/v2/internal/konnect/runtimegroups" + rgc "github.com/kong/kubernetes-ingress-controller/v2/internal/konnect/runtimegroupsconfig" +) + +const ( + konnectRuntimeGroupsBaseURL = "https://us.kic.api.konghq.tech/v2" + konnectRuntimeGroupsConfigBaseURLFmt = "https://us.api.konghq.tech/konnect-api/api/runtime_groups/%s/v1" + konnectRuntimeGroupAdminAPIBaseURL = "https://us.kic.api.konghq.tech" +) + +var konnectAccessToken = os.Getenv("TEST_KONG_KONNECT_ACCESS_TOKEN") + +func TestKonnectConfigPush(t *testing.T) { + t.Parallel() + skipIfMissingRequiredKonnectEnvVariables(t) + + ctx, env := setupE2ETest(t) + + rgID := createTestRuntimeGroup(ctx, t) + cert, key := createClientCertificate(ctx, t, rgID) + createKonnectClientSecretAndConfigMap(ctx, t, env, cert, key, rgID) + + deployAllInOneKonnectManifest(ctx, t, env) + + t.Log("running ingress tests to verify all-in-one deployed ingress controller and proxy are functional") + deployIngress(ctx, t, env) + verifyIngress(ctx, t, env) + + t.Log("ensuring ingress resources are correctly populated in Konnect Runtime Group's Admin API") + konnectAdminAPIClient := createKonnectAdminAPIClient(ctx, t, rgID, cert, key) + requireIngressConfiguredInAdminAPIEventually(ctx, t, konnectAdminAPIClient.AdminAPIClient()) +} + +func skipIfMissingRequiredKonnectEnvVariables(t *testing.T) { + if konnectAccessToken == "" { + t.Skip("missing TEST_KONG_KONNECT_ACCESS_TOKEN") + } +} + +// deployAllInOneKonnectManifest deploys all-in-one-dbless-konnect.yaml manifest, replacing the controller image +// if specified by environment variables. +func deployAllInOneKonnectManifest(ctx context.Context, t *testing.T, env environment.Environment) { + const manifestFile = "../../deploy/single/all-in-one-dbless-konnect.yaml" + t.Logf("deploying %s manifest file", manifestFile) + f, err := os.Open(manifestFile) + require.NoError(t, err) + defer f.Close() + var manifest io.Reader = f + + manifest, err = patchControllerImageFromEnv(f, manifestFile) + require.NoError(t, err) + _ = deployKong(ctx, t, env, manifest) +} + +// createTestRuntimeGroup creates a runtime group to be used in tests. It returns the created runtime group's ID. +// It also sets up a cleanup function for it to be deleted. +func createTestRuntimeGroup(ctx context.Context, t *testing.T) string { + t.Helper() + + rgClient, err := rg.NewClientWithResponses(konnectRuntimeGroupsBaseURL, rg.WithRequestEditorFn( + func(ctx context.Context, req *http.Request) error { + req.Header.Set("Authorization", "Bearer "+konnectAccessToken) + return nil + }), + ) + require.NoError(t, err) + + createRgResp, err := rgClient.CreateRuntimeGroupWithResponse(ctx, rg.CreateRuntimeGroupRequest{ + Description: lo.ToPtr("This is a description"), + Labels: &rg.Labels{"created_in_tests": "true"}, + Name: uuid.NewString(), + }) + require.NoError(t, err, "failed to create runtime group") + require.Equal(t, http.StatusCreated, createRgResp.StatusCode()) + require.NotNil(t, createRgResp.JSON201) + require.NotNil(t, createRgResp.JSON201.Id) + id := *createRgResp.JSON201.Id + t.Cleanup(func() { + _, err := rgClient.DeleteRuntimeGroupWithResponse(ctx, id) + assert.NoErrorf(t, err, "failed to cleanup a runtime group: %q", id) + }) + + t.Logf("created test Konnect Runtime Group: %q", id.String()) + return id.String() +} + +// createClientCertificate creates a TLS client certificate and POSTs it to Konnect Runtime Group configuration API +// so that KIC can use the certificates to authenticate against Konnect Admin API. +func createClientCertificate(ctx context.Context, t *testing.T, rgID string) (certPEM string, keyPEM string) { + t.Helper() + + rgConfigClient, err := rgc.NewClientWithResponses(fmt.Sprintf(konnectRuntimeGroupsConfigBaseURLFmt, rgID), rgc.WithRequestEditorFn( + func(ctx context.Context, req *http.Request) error { + req.Header.Set("Authorization", "Bearer "+konnectAccessToken) + return nil + }), + ) + require.NoError(t, err) + + priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) + require.NoError(t, err) + template := x509.Certificate{ + SerialNumber: big.NewInt(1), + Subject: pkix.Name{ + Organization: []string{"Kong Inc."}, + }, + NotBefore: time.Now(), + NotAfter: time.Now().Add(time.Hour * 24 * 180), + KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + BasicConstraintsValid: true, + } + + derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) + require.NoError(t, err) + + out := &bytes.Buffer{} + err = pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) + require.NoError(t, err) + cert := out.String() + + out.Reset() + err = pem.Encode(out, pemBlockForKey(t, priv)) + require.NoError(t, err) + key := out.String() + + t.Log("creating client certificate in Konnect") + resp, err := rgConfigClient.PostDpClientCertificatesWithResponse(ctx, rgc.PostDpClientCertificatesJSONRequestBody{ + Cert: cert, + }) + require.NoError(t, err) + require.Equal(t, http.StatusCreated, resp.StatusCode()) + + return cert, key +} + +func pemBlockForKey(t *testing.T, k *ecdsa.PrivateKey) *pem.Block { + b, err := x509.MarshalECPrivateKey(k) + require.NoError(t, err) + return &pem.Block{Type: "EC PRIVATE KEY", Bytes: b} +} + +// createKonnectClientSecretAndConfigMap creates a Secret with client TLS certificate that is used by KIC to communicate +// with Konnect Admin API. It also creates a ConfigMap that specifies a Runtime Group ID and Konnect Admin API URL. +// Both Secret and ConfigMap are used by all-in-one-dbless-konnect.yaml manifest and need to be populated before +// deploying it. +func createKonnectClientSecretAndConfigMap(ctx context.Context, t *testing.T, env environment.Environment, tlsCert, tlsKey, rgID string) { + t.Helper() + + // create a namespace in case it doesn't exist yet + t.Log("creating kong namespace") + ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}} + _, err := env.Cluster().Client().CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}) + if !apierrors.IsAlreadyExists(err) { + require.NoError(t, err) + } + + t.Log("creating konnect client tls secret") + _, err = env.Cluster().Client().CoreV1().Secrets(namespace).Create(ctx, &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "konnect-client-tls", + }, + Data: map[string][]byte{ + "tls.crt": []byte(tlsCert), + "tls.key": []byte(tlsKey), + }, + Type: corev1.SecretTypeTLS, + }, metav1.CreateOptions{}) + require.NoError(t, err) + + t.Log("creating konnect config map") + _, err = env.Cluster().Client().CoreV1().ConfigMaps(namespace).Create(ctx, &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "konnect-config", + }, + Data: map[string]string{ + "CONTROLLER_KONNECT_RUNTIME_GROUP_ID": rgID, + "CONTROLLER_KONNECT_ADDRESS": konnectRuntimeGroupAdminAPIBaseURL, + }, + }, metav1.CreateOptions{}) + require.NoError(t, err) +} + +// createKonnectAdminAPIClient creates an *kong.Client that will communicate with Konnect Runtime Group's Admin API. +func createKonnectAdminAPIClient(ctx context.Context, t *testing.T, rgID, cert, key string) *adminapi.Client { + t.Helper() + + c, err := adminapi.NewKongClientForKonnectRuntimeGroup(ctx, adminapi.KonnectConfig{ + RuntimeGroupID: rgID, + Address: konnectRuntimeGroupAdminAPIBaseURL, + TLSClient: adminapi.TLSClientConfig{ + Cert: cert, + Key: key, + }, + }) + require.NoError(t, err) + return c +}