From 0dac3d4904b48e832cbd0efd3633b9faa7526924 Mon Sep 17 00:00:00 2001 From: Emil Georgiev Date: Tue, 20 Feb 2024 13:18:05 +0200 Subject: [PATCH] ODJ-3077 integrate IAAS API (#203) * Introduces Support fo IaaS API of STACKIT to support everything network related and as a basis for the community Terraform provider. --- .gitignore | 1 + examples/iaas/iaas.go | 41 + internal/config/iaas/v1alpha/IaaS-API.json | 848 ++++++++++++ internal/config/iaas/v1alpha/config.yaml | 27 + internal/config/iaas/v1alpha/generate.go | 3 + .../config/iaas/v1alpha/include/service.go | 16 + pkg/services/iaas-api/v1alpha/iaas.go | 1179 +++++++++++++++++ pkg/services/iaas-api/v1alpha/service.go | 15 + pkg/services/iaas-api/v1alpha/wait.go | 34 + pkg/services/services.go | 3 + 10 files changed, 2167 insertions(+) create mode 100644 .gitignore create mode 100644 examples/iaas/iaas.go create mode 100644 internal/config/iaas/v1alpha/IaaS-API.json create mode 100644 internal/config/iaas/v1alpha/config.yaml create mode 100644 internal/config/iaas/v1alpha/generate.go create mode 100644 internal/config/iaas/v1alpha/include/service.go create mode 100644 pkg/services/iaas-api/v1alpha/iaas.go create mode 100644 pkg/services/iaas-api/v1alpha/service.go create mode 100644 pkg/services/iaas-api/v1alpha/wait.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/examples/iaas/iaas.go b/examples/iaas/iaas.go new file mode 100644 index 0000000..d4a29e9 --- /dev/null +++ b/examples/iaas/iaas.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "fmt" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" + "github.com/google/uuid" + + stackit "github.com/SchwarzIT/community-stackit-go-client" + iaas "github.com/SchwarzIT/community-stackit-go-client/pkg/services/iaas-api/v1alpha" +) + +func main() { + ctx := context.Background() + c := stackit.MustNewClientWithKeyAuth(ctx) + + l := 25 + + servers := []iaas.V1IP{ + "8.8.8.8", + } + + req := iaas.V1CreateNetworkJSONBody{ + // Name The name for a General Object. Matches Names and also UUIDs. + Name: "Network", + + // Nameservers List of DNS Servers/Nameservers. + Nameservers: &servers, // + PrefixLengthV4: &l, + } + projectID := uuid.New() + + res, err := c.IAAS.V1CreateNetwork(ctx, projectID, iaas.V1CreateNetworkJSONRequestBody(req)) + if err = validate.Response(res, err, "JSON200.AvailabilityZones"); err != nil { + fmt.Println(err) + return + } + + fmt.Println(res.JSON202.RequestID) +} diff --git a/internal/config/iaas/v1alpha/IaaS-API.json b/internal/config/iaas/v1alpha/IaaS-API.json new file mode 100644 index 0000000..8fdee06 --- /dev/null +++ b/internal/config/iaas/v1alpha/IaaS-API.json @@ -0,0 +1,848 @@ +{ + "components": { + "responses": { + "BadRequest": { + "content": { + "application/json": { + "examples": { + "InvalidAffinityPolicy": { + "value": { + "code": 400, + "msg": "The server group policy is not supported" + } + }, + "InvalidBootDeviceSize": { + "value": { + "code": 400, + "msg": "boot device size is not valid or missing" + } + }, + "InvalidFlavor": { + "value": { + "code": 400, + "msg": "flavor is not valid" + } + }, + "InvalidParameter": { + "value": { + "code": 400, + "msg": "request body has an error: doesn't match schema: Error at \"/name\": value must be a string" + } + }, + "InvalidPublicKey": { + "value": { + "code": 400, + "msg": "invalid pubkey" + } + }, + "InvalidUUID": { + "value": { + "code": 400, + "msg": "invalid uuid" + } + } + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Bad request." + }, + "Forbidden": { + "content": { + "application/json": { + "example": { + "code": 403, + "msg": "Forbidden" + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Forbidden Request." + }, + "InternalServerError": { + "content": { + "application/json": { + "example": { + "code": 500, + "msg": "internal server error" + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Internal Server Error, returns a 500 if something is broken on IaaS API Side." + }, + "InvalidServerAction": { + "content": { + "application/json": { + "example": { + "code": 409, + "msg": "InvalidServerAction" + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Invalid server action." + }, + "NotFound": { + "content": { + "application/json": { + "examples": { + "AreaNotFound": { + "value": { + "code": 404, + "msg": "area not found" + } + }, + "KeyPairNotFound": { + "value": { + "code": 404, + "msg": "keypair not found" + } + }, + "KeypairNotFound": { + "value": { + "code": 404, + "msg": "keypair not found" + } + }, + "NetworkNotFound": { + "value": { + "code": 404, + "msg": "network not found" + } + }, + "NetworkRangeNotFound": { + "value": { + "code": 404, + "msg": "network range not found" + } + }, + "OrganizationNotFound": { + "value": { + "code": 404, + "msg": "organization not found" + } + }, + "ProjectNotFound": { + "value": { + "code": 404, + "msg": "project not found" + } + }, + "RequestNotFound": { + "value": { + "code": 404, + "msg": "request not found" + } + }, + "RouteNotFound": { + "value": { + "code": 404, + "msg": "route not found" + } + } + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Object not found." + }, + "ServerOrPublicIPNotFound": { + "content": { + "application/json": { + "example": { + "code": 404, + "msg": "ServerOrPublicIPNotFound" + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Server or public IP not found." + }, + "Unauthorized": { + "content": { + "application/json": { + "example": { + "code": 401, + "msg": "Unauthorized" + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Unauthorized Request." + } + }, + "schemas": { + "v1CIDR": { + "description": "Classless Inter-Domain Routing (CIDR).", + "example": "10.1.2.0/24", + "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\/(3[0-2]|2[0-9]|1[0-9]|[0-9]))$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(\\/((1(1[0-9]|2[0-8]))|([0-9][0-9])|([0-9])))?$", + "type": "string" + }, + "v1Error": { + "description": "Error with HTTP error code and an error message.", + "properties": { + "code": { + "example": 404, + "type": "integer" + }, + "msg": { + "example": "Project not found", + "type": "string" + } + }, + "required": [ + "code", + "msg" + ], + "type": "object" + }, + "v1GenericName": { + "description": "The name for a General Object. Matches Names and also UUIDs.", + "example": "objectName26", + "maxLength": 63, + "pattern": "^[A-Za-z0-9]+((-|_|\\s|\\.)[A-Za-z0-9]+)*$", + "type": "string" + }, + "v1IP": { + "description": "An IP address.", + "example": "10.1.2.10", + "pattern": "((^\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\s*$)|(^\\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$))", + "type": "string" + }, + "v1Nameserver": { + "description": "List of DNS Servers/Nameservers.", + "example": [ + "10.20.30.40", + "50.60.70.80" + ], + "items": { + "$ref": "#/components/schemas/v1IP" + }, + "maxItems": 3, + "type": "array" + }, + "v1Network": { + "description": "Object represents a network.", + "properties": { + "name": { + "example": "My network", + "type": "string" + }, + "nameservers": { + "$ref": "#/components/schemas/v1Nameserver" + }, + "networkId": { + "$ref": "#/components/schemas/v1UUID" + }, + "prefixes": { + "example": [ + "10.1.2.0/24" + ], + "items": { + "$ref": "#/components/schemas/v1CIDR" + }, + "type": "array" + }, + "publicIp": { + "$ref": "#/components/schemas/v1IP" + } + }, + "required": [ + "networkId", + "prefixes", + "name" + ], + "type": "object" + }, + "v1NetworkList": { + "description": "List of Networks.", + "items": { + "$ref": "#/components/schemas/v1Network" + }, + "type": "array" + }, + "v1NetworkListResponse": { + "description": "Network list response.", + "properties": { + "items": { + "$ref": "#/components/schemas/v1NetworkList" + } + }, + "required": [ + "items" + ], + "type": "object" + }, + "v1OpenStackNetwork": { + "description": "Representation of an OpenStack network.", + "properties": { + "cidr": { + "$ref": "#/components/schemas/v1CIDR" + }, + "openstackNetworkID": { + "$ref": "#/components/schemas/v1UUID" + }, + "openstackRouterID": { + "$ref": "#/components/schemas/v1UUID" + }, + "openstackSubnetID": { + "$ref": "#/components/schemas/v1UUID" + } + }, + "required": [ + "openstackRouterID", + "openstackNetworkID", + "openstackSubnetID", + "cidr" + ], + "type": "object" + }, + "v1ReqID": { + "description": "ID representing a single API request.", + "example": "req-d61a8564c8dd4ffbbc15143e7d0c85ed", + "maxLength": 36, + "minLength": 36, + "pattern": "^req-[0-9a-f]{32}$", + "type": "string" + }, + "v1RequestResponse": { + "description": "Request response.", + "properties": { + "requestId": { + "$ref": "#/components/schemas/v1ReqID" + } + }, + "required": [ + "requestId" + ], + "type": "object" + }, + "v1UUID": { + "description": "Universally Unique Identifier (UUID).", + "example": "d61a8564-c8dd-4ffb-bc15-143e7d0c85ed", + "format": "uuid", + "maxLength": 36, + "minLength": 36, + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + "type": "string" + } + } + }, + "info": { + "contact": { + "email": "stackit-iaas@mail.schwarz", + "name": "STACKIT IaaS Teams", + "url": "https://support.stackit.cloud/servicedesk" + }, + "description": "This API allows you to create and modify IaaS resources.", + "license": { + "name": "KMZ", + "url": "https://ab.fahrt" + }, + "termsOfService": "https://stackit.de/en/imprint", + "title": "IaaS-API", + "version": "1alpha1" + }, + "openapi": "3.0.1", + "paths": { + "/v1alpha1/projects/{projectId}/networks": { + "parameters": [ + { + "schema": { + "description": "Universally Unique Identifier (UUID).", + "example": "d61a8564-c8dd-4ffb-bc15-143e7d0c85ed", + "format": "uuid", + "maxLength": 36, + "minLength": 36, + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + "type": "string" + }, + "name": "projectId", + "in": "path", + "required": true, + "description": "STACKIT Project ID." + } + ], + "get": { + "description": "Get a list of all networks inside a project.", + "operationId": "v1ListNetworksInProject", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1NetworkListResponse" + } + } + }, + "description": "List all networks of a project." + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "summary": "List all networks inside a project.", + "tags": [ + "Network" + ], + "x-stackit-authorization": { + "actions": [ + "project.network.list" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-viewer-permissions": { + "actions": [ + "project.network.list" + ] + } + }, + "post": { + "description": "Create a new network in a project. `nameservers` will be filled from `defaultNameservers` of the respective area if not specified. If the project has `internetAccess` enabled and this is the first network in the project this might incur cost.", + "operationId": "v1CreateNetwork", + "requestBody": { + "content": { + "application/json": { + "example": { + "name": "My Network", + "nameservers": [ + "10.1.2.10" + ], + "prefixLengthV4": 24 + }, + "schema": { + "properties": { + "name": { + "$ref": "#/components/schemas/v1GenericName" + }, + "nameservers": { + "$ref": "#/components/schemas/v1Nameserver" + }, + "prefixLengthV4": { + "default": 25, + "example": 24, + "maximum": 29, + "minimum": 22, + "type": "integer" + } + }, + "required": [ + "name" + ], + "type": "object" + } + } + }, + "description": "Create network request.", + "required": true + }, + "responses": { + "202": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RequestResponse" + } + } + }, + "description": "Create request for network accepted." + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "409": { + "content": { + "application/json": { + "example": { + "code": 409, + "msg": "Can not allocate prefixes for network. Ensure the area has sufficient space in the configured network ranges" + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Can not allocate prefixes for network." + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "summary": "Create new network.", + "tags": [ + "Network" + ], + "x-stackit-authorization": { + "actions": [ + "project.network.create" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-viewer-permissions": { + "actions": [ + "project.network.create" + ] + } + } + }, + "/v1alpha1/projects/{projectId}/networks/{networkId}": { + "parameters": [ + { + "description": "STACKIT Project ID.", + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "description": "Universally Unique Identifier (UUID).", + "example": "d61a8564-c8dd-4ffb-bc15-143e7d0c85ed", + "format": "uuid", + "maxLength": 36, + "minLength": 36, + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + "type": "string" + } + }, + { + "description": "STACKIT Network ID.", + "in": "path", + "name": "networkId", + "required": true, + "schema": { + "description": "Universally Unique Identifier (UUID).", + "example": "d61a8564-c8dd-4ffb-bc15-143e7d0c85ed", + "format": "uuid", + "maxLength": 36, + "minLength": 36, + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + "type": "string" + } + } + ], + "delete": { + "description": "Delete a network.", + "operationId": "v1DeleteNetwork", + "responses": { + "202": { + "description": "Delete request for network accepted." + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "409": { + "content": { + "application/json": { + "example": { + "code": 409, + "msg": "Can not delete network. It is still has systems connected to it." + }, + "schema": { + "$ref": "#/components/schemas/v1Error" + } + } + }, + "description": "Can not delete network that is still in use." + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "summary": "Delete network.", + "tags": [ + "Network" + ], + "x-stackit-authorization": { + "actions": [ + "project.network.delete" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-viewer-permissions": { + "actions": [ + "project.network.delete" + ] + } + }, + "get": { + "description": "Get details about a network.", + "operationId": "v1GetNetwork", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Network" + } + } + }, + "description": "Show network details." + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "summary": "Get network details.", + "tags": [ + "Network" + ], + "x-stackit-authorization": { + "actions": [ + "project.network.get" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-viewer-permissions": { + "actions": [ + "project.network.get" + ] + } + }, + "put": { + "description": "Update the settings of a network.", + "operationId": "v1UpdateNetwork", + "requestBody": { + "content": { + "application/json": { + "example": { + "name": "My Network", + "nameservers": [ + "10.1.2.10" + ] + }, + "schema": { + "properties": { + "name": { + "$ref": "#/components/schemas/v1GenericName" + }, + "nameservers": { + "$ref": "#/components/schemas/v1Nameserver" + } + }, + "type": "object" + } + } + }, + "description": "Update network request.", + "required": true + }, + "responses": { + "202": { + "description": "Update accepted." + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "summary": "Update network settings.", + "tags": [ + "Network" + ], + "x-stackit-authorization": { + "actions": [ + "project.network.update" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-viewer-permissions": { + "actions": [ + "project.network.update" + ] + } + } + }, + "/v1alpha1/projects/{projectId}/openstack-networks/{networkId}": { + "parameters": [ + { + "description": "STACKIT Project ID.", + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "description": "Universally Unique Identifier (UUID).", + "example": "d61a8564-c8dd-4ffb-bc15-143e7d0c85ed", + "format": "uuid", + "maxLength": 36, + "minLength": 36, + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + "type": "string" + } + }, + { + "description": "STACKIT Network ID.", + "in": "path", + "name": "networkId", + "required": true, + "schema": { + "description": "Universally Unique Identifier (UUID).", + "example": "d61a8564-c8dd-4ffb-bc15-143e7d0c85ed", + "format": "uuid", + "maxLength": 36, + "minLength": 36, + "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + "type": "string" + } + } + ], + "get": { + "deprecated": true, + "description": "Get OpenStack details about a network.", + "operationId": "v1GetOpenStackNetworkDetails", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1OpenStackNetwork" + } + } + }, + "description": "Show OpenStack network details." + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "summary": "Get OpenStack network details.", + "tags": [ + "Network" + ], + "x-stackit-authorization": { + "actions": [ + "project.network.get" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-viewer-permissions": { + "actions": [ + "project.network.get" + ] + } + } + } + }, + "servers": [ + { + "description": "This API allows you to create and modify IaaS resources.", + "url": "https://iaas.api.eu01.stackit.cloud" + } + ], + "tags": [ + { + "description": "Generic Tag for Network based Service.", + "name": "Network" + } + ], + "x-stackit-api": { + "type": "stackit" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-stackit-signer": { + "audience": [ + "iaas" + ], + "inject-email": false + } +} \ No newline at end of file diff --git a/internal/config/iaas/v1alpha/config.yaml b/internal/config/iaas/v1alpha/config.yaml new file mode 100644 index 0000000..e506639 --- /dev/null +++ b/internal/config/iaas/v1alpha/config.yaml @@ -0,0 +1,27 @@ +package: iaas +output: ../../../../pkg/services/iaas-api/v1alpha/iaas.go +generate: + models: true + client: true +output-options: + custom-doer: + enabled: true + import: contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + name: "contracts.BaseClientInterface" + split-by-tags: + verbose: false + enabled: true +tidy: + verbose: false + functions: + - replace: Id + with: ID + all: true + params: + - replace: Id + with: ID + all: true + schemas: + - replace: Id + with: ID + all: true diff --git a/internal/config/iaas/v1alpha/generate.go b/internal/config/iaas/v1alpha/generate.go new file mode 100644 index 0000000..55af2e5 --- /dev/null +++ b/internal/config/iaas/v1alpha/generate.go @@ -0,0 +1,3 @@ +package gen + +//go:generate go run github.com/do87/stackit-client-generator/cmd/oapi-codegen@v0.0.2 -config config.yaml IaaS-API.json diff --git a/internal/config/iaas/v1alpha/include/service.go b/internal/config/iaas/v1alpha/include/service.go new file mode 100644 index 0000000..b4a4d64 --- /dev/null +++ b/internal/config/iaas/v1alpha/include/service.go @@ -0,0 +1,16 @@ +package iaas + +import ( + "github.com/SchwarzIT/community-stackit-go-client/pkg/baseurl" + "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + iaas "github.com/SchwarzIT/community-stackit-go-client/pkg/services/iaas-api/v1alpha" +) + +var BaseURLs = baseurl.New( + "iaas", + "https://iaas.api.eu01.stackit.cloud/", +) + +func NewService(c contracts.BaseClientInterface) *iaas.ClientWithResponses { + return iaas.NewClient(BaseURLs.Get(), c) +} diff --git a/pkg/services/iaas-api/v1alpha/iaas.go b/pkg/services/iaas-api/v1alpha/iaas.go new file mode 100644 index 0000000..4760a9e --- /dev/null +++ b/pkg/services/iaas-api/v1alpha/iaas.go @@ -0,0 +1,1179 @@ +// Package iaas provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package iaas + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/runtime" + openapiTypes "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/types" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +// V1CIDR Classless Inter-Domain Routing (CIDR). +type V1CIDR = string + +// V1Error Error with HTTP error code and an error message. +type V1Error struct { + Code int `json:"code"` + Msg string `json:"msg"` +} + +// V1GenericName The name for a General Object. Matches Names and also UUIDs. +type V1GenericName = string + +// V1IP An IP address. +type V1IP = string + +// V1Nameserver List of DNS Servers/Nameservers. +type V1Nameserver = []V1IP + +// V1Network Object represents a network. +type V1Network struct { + Name string `json:"name"` + + // Nameservers List of DNS Servers/Nameservers. + Nameservers *V1Nameserver `json:"nameservers,omitempty"` + + // NetworkId Universally Unique Identifier (UUID). + NetworkID V1UUID `json:"networkId"` + Prefixes []V1CIDR `json:"prefixes"` + + // PublicIp An IP address. + PublicIp *V1IP `json:"publicIp,omitempty"` +} + +// V1NetworkList List of Networks. +type V1NetworkList = []V1Network + +// V1NetworkListResponse Network list response. +type V1NetworkListResponse struct { + // Items List of Networks. + Items V1NetworkList `json:"items"` +} + +// V1OpenStackNetwork Representation of an OpenStack network. +type V1OpenStackNetwork struct { + // Cidr Classless Inter-Domain Routing (CIDR). + Cidr V1CIDR `json:"cidr"` + + // OpenstackNetworkID Universally Unique Identifier (UUID). + OpenstackNetworkID V1UUID `json:"openstackNetworkID"` + + // OpenstackRouterID Universally Unique Identifier (UUID). + OpenstackRouterID V1UUID `json:"openstackRouterID"` + + // OpenstackSubnetID Universally Unique Identifier (UUID). + OpenstackSubnetID V1UUID `json:"openstackSubnetID"` +} + +// V1ReqID ID representing a single API request. +type V1ReqID = string + +// V1RequestResponse Request response. +type V1RequestResponse struct { + // RequestId ID representing a single API request. + RequestID V1ReqID `json:"requestId"` +} + +// V1UUID Universally Unique Identifier (UUID). +type V1UUID = openapiTypes.UUID + +// BadRequest Error with HTTP error code and an error message. +type BadRequest = V1Error + +// Forbidden Error with HTTP error code and an error message. +type Forbidden = V1Error + +// InternalServerError Error with HTTP error code and an error message. +type InternalServerError = V1Error + +// NotFound Error with HTTP error code and an error message. +type NotFound = V1Error + +// Unauthorized Error with HTTP error code and an error message. +type Unauthorized = V1Error + +// V1CreateNetworkJSONBody defines parameters for V1CreateNetwork. +type V1CreateNetworkJSONBody struct { + // Name The name for a General Object. Matches Names and also UUIDs. + Name V1GenericName `json:"name"` + + // Nameservers List of DNS Servers/Nameservers. + Nameservers *V1Nameserver `json:"nameservers,omitempty"` + PrefixLengthV4 *int `json:"prefixLengthV4,omitempty"` +} + +// V1UpdateNetworkJSONBody defines parameters for V1UpdateNetwork. +type V1UpdateNetworkJSONBody struct { + // Name The name for a General Object. Matches Names and also UUIDs. + Name *V1GenericName `json:"name,omitempty"` + + // Nameservers List of DNS Servers/Nameservers. + Nameservers *V1Nameserver `json:"nameservers,omitempty"` +} + +// V1CreateNetworkJSONRequestBody defines body for V1CreateNetwork for application/json ContentType. +type V1CreateNetworkJSONRequestBody V1CreateNetworkJSONBody + +// V1UpdateNetworkJSONRequestBody defines body for V1UpdateNetwork for application/json ContentType. +type V1UpdateNetworkJSONRequestBody V1UpdateNetworkJSONBody + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) 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 contracts.BaseClientInterface +} + +// NewRawClient Creates a new Client, with reasonable defaults +func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client { + // create a client with sane default values + client := Client{ + Server: server, + Client: httpClient, + } + return &client +} + +// The interface specification for the client above. +type rawClientInterface interface { + // V1ListNetworksInProject request + V1ListNetworksInProjectRaw(ctx context.Context, projectId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // V1CreateNetwork request with any body + V1CreateNetworkRawWithBody(ctx context.Context, projectId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + V1CreateNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, body V1CreateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // V1DeleteNetwork request + V1DeleteNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // V1GetNetwork request + V1GetNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // V1UpdateNetwork request with any body + V1UpdateNetworkRawWithBody(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + V1UpdateNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, body V1UpdateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // V1GetOpenStackNetworkDetails request + V1GetOpenStackNetworkDetailsRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) V1ListNetworksInProjectRaw(ctx context.Context, projectId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1ListNetworksInProjectRequest(ctx, c.Server, projectId) + 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) V1CreateNetworkRawWithBody(ctx context.Context, projectId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1CreateNetworkRequestWithBody(ctx, c.Server, projectId, 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) V1CreateNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, body V1CreateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1CreateNetworkRequest(ctx, c.Server, projectId, 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) V1DeleteNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1DeleteNetworkRequest(ctx, c.Server, projectId, networkId) + 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) V1GetNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1GetNetworkRequest(ctx, c.Server, projectId, networkId) + 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) V1UpdateNetworkRawWithBody(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1UpdateNetworkRequestWithBody(ctx, c.Server, projectId, networkId, 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) V1UpdateNetworkRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, body V1UpdateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1UpdateNetworkRequest(ctx, c.Server, projectId, networkId, 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) V1GetOpenStackNetworkDetailsRaw(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewV1GetOpenStackNetworkDetailsRequest(ctx, c.Server, projectId, networkId) + 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) +} + +// NewV1ListNetworksInProjectRequest generates requests for V1ListNetworksInProject +func NewV1ListNetworksInProjectRequest(ctx context.Context, server string, projectId openapiTypes.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectId", runtime.ParamLocationPath, projectId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1alpha1/projects/%s/networks", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewV1CreateNetworkRequest calls the generic V1CreateNetwork builder with application/json body +func NewV1CreateNetworkRequest(ctx context.Context, server string, projectId openapiTypes.UUID, body V1CreateNetworkJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewV1CreateNetworkRequestWithBody(ctx, server, projectId, "application/json", bodyReader) +} + +// NewV1CreateNetworkRequestWithBody generates requests for V1CreateNetwork with any type of body +func NewV1CreateNetworkRequestWithBody(ctx context.Context, server string, projectId openapiTypes.UUID, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectId", runtime.ParamLocationPath, projectId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1alpha1/projects/%s/networks", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewV1DeleteNetworkRequest generates requests for V1DeleteNetwork +func NewV1DeleteNetworkRequest(ctx context.Context, server string, projectId openapiTypes.UUID, networkId openapiTypes.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectId", runtime.ParamLocationPath, projectId) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "networkId", runtime.ParamLocationPath, networkId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1alpha1/projects/%s/networks/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewV1GetNetworkRequest generates requests for V1GetNetwork +func NewV1GetNetworkRequest(ctx context.Context, server string, projectId openapiTypes.UUID, networkId openapiTypes.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectId", runtime.ParamLocationPath, projectId) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "networkId", runtime.ParamLocationPath, networkId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1alpha1/projects/%s/networks/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewV1UpdateNetworkRequest calls the generic V1UpdateNetwork builder with application/json body +func NewV1UpdateNetworkRequest(ctx context.Context, server string, projectId openapiTypes.UUID, networkId openapiTypes.UUID, body V1UpdateNetworkJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewV1UpdateNetworkRequestWithBody(ctx, server, projectId, networkId, "application/json", bodyReader) +} + +// NewV1UpdateNetworkRequestWithBody generates requests for V1UpdateNetwork with any type of body +func NewV1UpdateNetworkRequestWithBody(ctx context.Context, server string, projectId openapiTypes.UUID, networkId openapiTypes.UUID, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectId", runtime.ParamLocationPath, projectId) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "networkId", runtime.ParamLocationPath, networkId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1alpha1/projects/%s/networks/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "PUT", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewV1GetOpenStackNetworkDetailsRequest generates requests for V1GetOpenStackNetworkDetails +func NewV1GetOpenStackNetworkDetailsRequest(ctx context.Context, server string, projectId openapiTypes.UUID, networkId openapiTypes.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectId", runtime.ParamLocationPath, projectId) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "networkId", runtime.ParamLocationPath, networkId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1alpha1/projects/%s/openstack-networks/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "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 additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + rawClientInterface +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses { + return &ClientWithResponses{NewRawClient(server, httpClient)} +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // V1ListNetworksInProject request + V1ListNetworksInProject(ctx context.Context, projectId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1ListNetworksInProjectResponse, error) + + // V1CreateNetwork request with any body + V1CreateNetworkWithBody(ctx context.Context, projectId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*V1CreateNetworkResponse, error) + + V1CreateNetwork(ctx context.Context, projectId openapiTypes.UUID, body V1CreateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*V1CreateNetworkResponse, error) + + // V1DeleteNetwork request + V1DeleteNetwork(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1DeleteNetworkResponse, error) + + // V1GetNetwork request + V1GetNetwork(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1GetNetworkResponse, error) + + // V1UpdateNetwork request with any body + V1UpdateNetworkWithBody(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*V1UpdateNetworkResponse, error) + + V1UpdateNetwork(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, body V1UpdateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*V1UpdateNetworkResponse, error) + + // V1GetOpenStackNetworkDetails request + V1GetOpenStackNetworkDetails(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1GetOpenStackNetworkDetailsResponse, error) +} + +type V1ListNetworksInProjectResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *V1NetworkListResponse + JSON400 *V1Error + JSON401 *V1Error + JSON403 *V1Error + JSON404 *V1Error + JSON500 *V1Error +} + +// Status returns HTTPResponse.Status +func (r V1ListNetworksInProjectResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r V1ListNetworksInProjectResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type V1CreateNetworkResponse struct { + Body []byte + HTTPResponse *http.Response + JSON202 *V1RequestResponse + JSON400 *V1Error + JSON401 *V1Error + JSON403 *V1Error + JSON404 *V1Error + JSON409 *V1Error + JSON500 *V1Error +} + +// Status returns HTTPResponse.Status +func (r V1CreateNetworkResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r V1CreateNetworkResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type V1DeleteNetworkResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *V1Error + JSON401 *V1Error + JSON403 *V1Error + JSON404 *V1Error + JSON409 *V1Error + JSON500 *V1Error +} + +// Status returns HTTPResponse.Status +func (r V1DeleteNetworkResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r V1DeleteNetworkResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type V1GetNetworkResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *V1Network + JSON400 *V1Error + JSON401 *V1Error + JSON403 *V1Error + JSON404 *V1Error + JSON500 *V1Error +} + +// Status returns HTTPResponse.Status +func (r V1GetNetworkResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r V1GetNetworkResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type V1UpdateNetworkResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *V1Error + JSON401 *V1Error + JSON403 *V1Error + JSON404 *V1Error + JSON500 *V1Error +} + +// Status returns HTTPResponse.Status +func (r V1UpdateNetworkResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r V1UpdateNetworkResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type V1GetOpenStackNetworkDetailsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *V1OpenStackNetwork + JSON400 *V1Error + JSON401 *V1Error + JSON403 *V1Error + JSON404 *V1Error + JSON500 *V1Error +} + +// Status returns HTTPResponse.Status +func (r V1GetOpenStackNetworkDetailsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r V1GetOpenStackNetworkDetailsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// V1ListNetworksInProject request returning *V1ListNetworksInProjectResponse +func (c *ClientWithResponses) V1ListNetworksInProject(ctx context.Context, projectId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1ListNetworksInProjectResponse, error) { + rsp, err := c.V1ListNetworksInProjectRaw(ctx, projectId, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1ListNetworksInProjectResponse(rsp) +} + +// V1CreateNetworkWithBody request with arbitrary body returning *V1CreateNetworkResponse +func (c *ClientWithResponses) V1CreateNetworkWithBody(ctx context.Context, projectId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*V1CreateNetworkResponse, error) { + rsp, err := c.V1CreateNetworkRawWithBody(ctx, projectId, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1CreateNetworkResponse(rsp) +} + +func (c *ClientWithResponses) V1CreateNetwork(ctx context.Context, projectId openapiTypes.UUID, body V1CreateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*V1CreateNetworkResponse, error) { + rsp, err := c.V1CreateNetworkRaw(ctx, projectId, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1CreateNetworkResponse(rsp) +} + +// V1DeleteNetwork request returning *V1DeleteNetworkResponse +func (c *ClientWithResponses) V1DeleteNetwork(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1DeleteNetworkResponse, error) { + rsp, err := c.V1DeleteNetworkRaw(ctx, projectId, networkId, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1DeleteNetworkResponse(rsp) +} + +// V1GetNetwork request returning *V1GetNetworkResponse +func (c *ClientWithResponses) V1GetNetwork(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1GetNetworkResponse, error) { + rsp, err := c.V1GetNetworkRaw(ctx, projectId, networkId, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1GetNetworkResponse(rsp) +} + +// V1UpdateNetworkWithBody request with arbitrary body returning *V1UpdateNetworkResponse +func (c *ClientWithResponses) V1UpdateNetworkWithBody(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*V1UpdateNetworkResponse, error) { + rsp, err := c.V1UpdateNetworkRawWithBody(ctx, projectId, networkId, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1UpdateNetworkResponse(rsp) +} + +func (c *ClientWithResponses) V1UpdateNetwork(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, body V1UpdateNetworkJSONRequestBody, reqEditors ...RequestEditorFn) (*V1UpdateNetworkResponse, error) { + rsp, err := c.V1UpdateNetworkRaw(ctx, projectId, networkId, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1UpdateNetworkResponse(rsp) +} + +// V1GetOpenStackNetworkDetails request returning *V1GetOpenStackNetworkDetailsResponse +func (c *ClientWithResponses) V1GetOpenStackNetworkDetails(ctx context.Context, projectId openapiTypes.UUID, networkId openapiTypes.UUID, reqEditors ...RequestEditorFn) (*V1GetOpenStackNetworkDetailsResponse, error) { + rsp, err := c.V1GetOpenStackNetworkDetailsRaw(ctx, projectId, networkId, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseV1GetOpenStackNetworkDetailsResponse(rsp) +} + +// ParseV1ListNetworksInProjectResponse parses an HTTP response from a V1ListNetworksInProject call +func (c *ClientWithResponses) ParseV1ListNetworksInProjectResponse(rsp *http.Response) (*V1ListNetworksInProjectResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &V1ListNetworksInProjectResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest V1NetworkListResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON500 = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseV1CreateNetworkResponse parses an HTTP response from a V1CreateNetwork call +func (c *ClientWithResponses) ParseV1CreateNetworkResponse(rsp *http.Response) (*V1CreateNetworkResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &V1CreateNetworkResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest V1RequestResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 409: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON409 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON500 = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseV1DeleteNetworkResponse parses an HTTP response from a V1DeleteNetwork call +func (c *ClientWithResponses) ParseV1DeleteNetworkResponse(rsp *http.Response) (*V1DeleteNetworkResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &V1DeleteNetworkResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 409: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON409 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON500 = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseV1GetNetworkResponse parses an HTTP response from a V1GetNetwork call +func (c *ClientWithResponses) ParseV1GetNetworkResponse(rsp *http.Response) (*V1GetNetworkResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &V1GetNetworkResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest V1Network + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON500 = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseV1UpdateNetworkResponse parses an HTTP response from a V1UpdateNetwork call +func (c *ClientWithResponses) ParseV1UpdateNetworkResponse(rsp *http.Response) (*V1UpdateNetworkResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &V1UpdateNetworkResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON500 = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseV1GetOpenStackNetworkDetailsResponse parses an HTTP response from a V1GetOpenStackNetworkDetails call +func (c *ClientWithResponses) ParseV1GetOpenStackNetworkDetailsResponse(rsp *http.Response) (*V1GetOpenStackNetworkDetailsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &V1GetOpenStackNetworkDetailsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest V1OpenStackNetwork + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest V1Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON500 = &dest + + } + + return response, validate.ResponseObject(response) +} diff --git a/pkg/services/iaas-api/v1alpha/service.go b/pkg/services/iaas-api/v1alpha/service.go new file mode 100644 index 0000000..d453094 --- /dev/null +++ b/pkg/services/iaas-api/v1alpha/service.go @@ -0,0 +1,15 @@ +package iaas + +import ( + "github.com/SchwarzIT/community-stackit-go-client/pkg/baseurl" + "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" +) + +var BaseURLs = baseurl.New( + "kubernetes", + "https://ske.api.eu01.stackit.cloud/", +) + +func NewService(c contracts.BaseClientInterface) *ClientWithResponses { + return NewClient(BaseURLs.Get(), c) +} diff --git a/pkg/services/iaas-api/v1alpha/wait.go b/pkg/services/iaas-api/v1alpha/wait.go new file mode 100644 index 0000000..e93d49b --- /dev/null +++ b/pkg/services/iaas-api/v1alpha/wait.go @@ -0,0 +1,34 @@ +package iaas + +import ( + "context" + "net/http" + "strings" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/wait" + + openapiTypes "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/types" +) + +func (*V1CreateNetworkResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID, networkID openapiTypes.UUID) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.V1GetNetwork(ctx, projectID, networkID) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusForbidden)) { + return nil, false, nil + } + return nil, false, err + } + if resp.StatusCode() == http.StatusForbidden { + return nil, false, nil + } + if resp.StatusCode() == http.StatusInternalServerError { + return nil, false, nil + } + if resp.JSON200 == nil { + return nil, false, nil + } + + return resp, true, nil + }) +} diff --git a/pkg/services/services.go b/pkg/services/services.go index 3a9812a..ceb6097 100644 --- a/pkg/services/services.go +++ b/pkg/services/services.go @@ -2,6 +2,7 @@ package services import ( "errors" + iaas "github.com/SchwarzIT/community-stackit-go-client/pkg/services/iaas-api/v1alpha" "github.com/SchwarzIT/community-stackit-go-client/pkg/clients" "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" @@ -23,6 +24,7 @@ type Services struct { Client contracts.BaseClientInterface Argus *argus.ClientWithResponses Costs *costs.ClientWithResponses + IAAS *iaas.ClientWithResponses Kubernetes *kubernetes.ClientWithResponses LoadBalancer *loadbalancer.ClientWithResponses Membership *membership.ClientWithResponses @@ -56,6 +58,7 @@ func Init(c contracts.BaseClientInterface) (*Services, error) { // Services Argus: argus.NewService(nc), Costs: costs.NewService(newClient(c)), + IAAS: iaas.NewService(newClient(c)), Kubernetes: kubernetes.NewService(newClient(c)), LoadBalancer: loadbalancer.NewService(newClient(c)), Membership: membership.NewService(newClient(c)),