diff --git a/examples/resourcemanager/go.mod b/examples/resourcemanager/go.mod new file mode 100644 index 00000000..da1b385b --- /dev/null +++ b/examples/resourcemanager/go.mod @@ -0,0 +1,23 @@ +module github.com/stackitcloud/stackit-sdk-go/examples/resourcemanager + +go 1.18 + +require ( + github.com/stackitcloud/stackit-sdk-go/core v0.7.3 + github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.6.0 +) + +require ( + github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect + github.com/go-logr/logr v1.2.4 // indirect + github.com/golang-jwt/jwt/v5 v5.1.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/uuid v1.4.0 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.31.0 // indirect + k8s.io/apimachinery v0.28.4 // indirect + k8s.io/klog/v2 v2.100.1 // indirect + k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect +) diff --git a/examples/resourcemanager/go.sum b/examples/resourcemanager/go.sum new file mode 100644 index 00000000..ce78292d --- /dev/null +++ b/examples/resourcemanager/go.sum @@ -0,0 +1,42 @@ +github.com/MicahParks/keyfunc/v2 v2.1.0 h1:6ZXKb9Rp6qp1bDbJefnG7cTH8yMN1IC/4nf+GVjO99k= +github.com/MicahParks/keyfunc/v2 v2.1.0/go.mod h1:rW42fi+xgLJ2FRRXAfNx9ZA8WpD4OeE/yHVMteCkw9k= +github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/golang-jwt/jwt/v5 v5.1.0 h1:UGKbA/IPjtS6zLcdB7i5TyACMgSbOTiR8qzXgw8HWQU= +github.com/golang-jwt/jwt/v5 v5.1.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/stackitcloud/stackit-sdk-go/core v0.7.3 h1:oxLY44Vuyn7+lcKBZDFGbc2YSjnw43PbuiATBL3aq+I= +github.com/stackitcloud/stackit-sdk-go/core v0.7.3/go.mod h1:5hA/nSktcp/BiFaRyMIV6E/1d/i7cieLNE5XzWPrICo= +github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.6.0 h1:fIwq2GkiRCYeesTa4bQeGQOKE3c8qSZgFPDw7fGFFuU= +github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.6.0/go.mod h1:mGGsvpITagchv9INzoUNesiq1Pm7r+eWX7omnb+ljE0= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8= +k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg= +k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= +k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= +k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= +k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= diff --git a/examples/resourcemanager/resourcemanager.go b/examples/resourcemanager/resourcemanager.go new file mode 100644 index 00000000..d2db20a4 --- /dev/null +++ b/examples/resourcemanager/resourcemanager.go @@ -0,0 +1,48 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/stackitcloud/stackit-sdk-go/core/utils" + "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager" +) + +func main() { + // Specify the parent organization ID + parentOrganizationId := "ORGANIZATION_ID" + + // Create a new API client, that uses default authentication and configuration + client, err := resourcemanager.NewAPIClient() + if err != nil { + fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) + os.Exit(1) + } + + // Get the projects under a specific resource (organization) + getProjectsResp, err := client.GetProjects(context.Background()).ContainerParentId(parentOrganizationId).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `GetProjects`: %v\n", err) + } else { + fmt.Printf("Number of projects: %v\n", len(*getProjectsResp.Items)) + } + + // Create a project + createProjectPayload := resourcemanager.CreateProjectPayload{ + ContainerParentId: utils.Ptr(parentOrganizationId), + Name: utils.Ptr("my-project"), + Members: &[]resourcemanager.ProjectMember{ + { + Role: utils.Ptr("project.owner"), + Subject: utils.Ptr("owner-email@example.com"), + }, + }, + } + createProjectResp, err := client.CreateProject(context.Background()).CreateProjectPayload(createProjectPayload).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `CreateProject`: %v\n", err) + } else { + fmt.Printf("Created project with id \"%s\".\n", *createProjectResp.ProjectId) + } +} diff --git a/go.work b/go.work index 472dff21..c49dcde5 100644 --- a/go.work +++ b/go.work @@ -19,6 +19,7 @@ use ( ./examples/postgresql ./examples/rabbitmq ./examples/redis + ./examples/resourcemanager ./examples/secretsmanager ./examples/serviceaccount ./examples/ske