@@ -7,15 +7,21 @@ import (
77
88 "github.com/stackitcloud/stackit-sdk-go/core/utils"
99 dremio "github.com/stackitcloud/stackit-sdk-go/services/dremio/v1alphaapi"
10+ "github.com/stackitcloud/stackit-sdk-go/services/dremio/v1alphaapi/wait/wait"
1011)
1112
1213func main () {
1314 region := "eu01" // Region where the resources will be created
1415 projectId := "PROJECT_ID" // Your STACKIT project ID
16+ serviceAccountKeyPath := "sa-key-path.json" // Path to your STACKIT service account json
17+
1518
1619 ctx := context .Background ()
1720
18- dremioClient , err := dremio .NewAPIClient ()
21+ dremioClient , err := dremio .NewAPIClient (
22+ config .WithRegion (region ),
23+ config .WithServiceAccountKeyPath (serviceAccountKeyPath ),
24+ )
1925 if err != nil {
2026 fmt .Fprintf (os .Stderr , "[Dremio] Creating API client: %v\n " , err )
2127 os .Exit (1 )
@@ -34,6 +40,39 @@ func main() {
3440 dremioId := createDremioInstanceResponse .Id
3541 fmt .Printf ("[Dremio] Triggered creation of Dremio with ID: %s. Waiting for it to become active... \n " , dremioId )
3642
43+ _ , err = wait .CreateDremioWaitHandler (ctx , dremioClient .DefaultAPI , projectId , region , dremioId ).WaitWithContext (ctx )
44+ if err != nil {
45+ fmt .Fprintf (os .Stderr , "[Dremio] Error when waiting for creation: %v\n " , err )
46+ os .Exit (1 )
47+ }
48+
49+ // Update a Dremio instance
50+ _ , err = dremioClient .DefaultAPI .UpdateDremioInstance (ctx , projectId , region , dremioId ).UpdateDremioInstancePayload (dremio.UpdateDremioInstancePayload {
51+ DisplayName : utils .Ptr ("myExampleDremioInstanceUpdated" ),
52+ }).Execute ()
53+ if err != nil {
54+ fmt .Fprintf (os .Stderr , "[Dremio] Error when updating Dremio instance: %v\n " , err )
55+ os .Exit (1 )
56+ }
57+ _ , err = wait .UpdateDremioWaitHandler (ctx , dremioClient .DefaultAPI , projectId , region , dremioId ).WaitWithContext (ctx )
58+ if err != nil {
59+ fmt .Fprintf (os .Stderr , "[Dremio] Error when waiting for update: %v\n " , err )
60+ os .Exit (1 )
61+ }
62+
63+ // Listing Dremio instances
64+ listResp , err := dremioClient .DefaultAPI .ListDremioInstances (ctx , projectId , region ).Execute ()
65+ if err != nil {
66+ fmt .Fprintf (os .Stderr , "[Dremio] Error when listing Dremio instances: %v\n " , err )
67+ os .Exit (1 )
68+ }
69+ fmt .Println ("Dremio instances:" )
70+ for _ , instance := range listResp .Dremios {
71+ fmt .Printf ("%s - %s\n " , instance .Id , instance .DisplayName )
72+ }
73+ fmt .Println ()
74+
75+
3776 // Creating a Dremio user
3877 createDremioUserPayload := dremio.CreateDremioUserPayload {
3978 Description : utils .Ptr ("This is a new user." ),
@@ -50,4 +89,48 @@ func main() {
5089 }
5190 dremioUserId := createDremioUserResponse .Id
5291 fmt .Printf ("[Dremio] Created Dremio User with ID: %s\n " , dremioUserId )
92+
93+ _ , err = wait .CreateDremioUserWaitHandler (ctx , dremioClient .DefaultAPI , projectId , region , dremioId , dremioUserId ).WaitWithContext (ctx )
94+ if err != nil {
95+ fmt .Fprintf (os .Stderr , "[Dremio] Error when waiting for user creation: %v\n " , err )
96+ os .Exit (1 )
97+ }
98+
99+ // List Dremio users
100+ listUsersResp , err := dremioClient .DefaultAPI .ListDremioUsers (ctx , projectId , region , dremioId ).Execute ()
101+ if err != nil {
102+ fmt .Fprintf (os .Stderr , "[Dremio] Error when listing Dremio users: %v\n " , err )
103+ os .Exit (1 )
104+ }
105+ fmt .Println ("Dremio users:" )
106+ for _ , user := range listUsersResp .DremioUsers {
107+ fmt .Printf ("%s - %s\n " , user .Id , user .Name )
108+ }
109+ fmt .Println ()
110+
111+ // Delete a Dremio user
112+ err = dremioClient .DefaultAPI .DeleteDremioUser (ctx , projectId , region , dremioId , dremioUserId ).Execute ()
113+ if err != nil {
114+ fmt .Fprintf (os .Stderr , "[Dremio] Error when deleting Dremio user: %v\n " , err )
115+ os .Exit (1 )
116+ }
117+ _ , err = wait .DeleteDremioUserWaitHandler (ctx , dremioClient .DefaultAPI , projectId , region , dremioId , dremioUserId ).WaitWithContext (ctx )
118+ if err != nil {
119+ fmt .Fprintf (os .Stderr , "[Dremio] Error when waiting for user deletion: %v\n " , err )
120+ os .Exit (1 )
121+ }
122+
123+ // Delete a Dremio instance
124+ err = dremioClient .DefaultAPI .DeleteDremioInstance (ctx , projectId , region , dremioId ).Execute ()
125+ if err != nil {
126+ fmt .Fprintf (os .Stderr , "[Dremio] Error when deleting Dremio instance: %v\n " , err )
127+ os .Exit (1 )
128+ }
129+ _ , err = wait .DeleteDremioWaitHandler (ctx , dremioClient .DefaultAPI , projectId , region , dremioId ).WaitWithContext (ctx )
130+ if err != nil {
131+ fmt .Fprintf (os .Stderr , "[Dremio] Error when waiting for deletion: %v\n " , err )
132+ os .Exit (1 )
133+ }
134+
135+
53136}
0 commit comments