Skip to content

Commit 65769c3

Browse files
author
Devansh Thakur
committed
added intake service example with version v0.2.0
1 parent 63ce414 commit 65769c3

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

examples/intake/go.mod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/stackitcloud/stackit-sdk-go/examples/intake
2+
3+
go 1.21
4+
5+
require (
6+
github.com/stackitcloud/stackit-sdk-go/core v0.17.3
7+
github.com/stackitcloud/stackit-sdk-go/services/intake v0.2.0
8+
)
9+
10+
require (
11+
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
12+
github.com/google/uuid v1.6.0 // indirect
13+
)

examples/intake/go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
2+
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
3+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7+
github.com/stackitcloud/stackit-sdk-go/core v0.17.3 h1:GsZGmRRc/3GJLmCUnsZswirr5wfLRrwavbnL/renOqg=
8+
github.com/stackitcloud/stackit-sdk-go/core v0.17.3/go.mod h1:HBCXJGPgdRulplDzhrmwC+Dak9B/x0nzNtmOpu+1Ahg=
9+
github.com/stackitcloud/stackit-sdk-go/services/intake v0.2.0 h1:p/zi4VPoCQWk7/2ubi3hxsqiaye41x/Pl3GXYbPkYOY=
10+
github.com/stackitcloud/stackit-sdk-go/services/intake v0.2.0/go.mod h1:jOArPjNRkwv4487+9ab3dRG+lM09leu5FiRohbQs9Z4=

examples/intake/intake.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
9+
"github.com/stackitcloud/stackit-sdk-go/core/utils"
10+
"github.com/stackitcloud/stackit-sdk-go/services/intake"
11+
)
12+
13+
func main() {
14+
region := "eu01" // Region where the resources will be created
15+
projectId := "PROJECT_ID" // Your STACKIT project ID
16+
17+
dremioCatalogURI := "DREMIO_CATALOG_URI" // E.g., "https://my-dremio-catalog.data-platform.stackit.run/iceberg"
18+
dremioTokenEndpoint := "DREMIO_TOKEN_ENDPOINT" // E.g., "https://my-dremio.data-platform.stackit.run/oauth/token"
19+
dremioPAT := "DREMIO_PERSONAL_ACCESS_TOKEN" // Your Dremio Personal Access Token
20+
catalogWarehouse := "CATALOG_WAREHOUSE" // Catalog warehouse where the data will be ingested
21+
22+
intakeUserPassword := "s3cuRe_p@ssW0rd_f0r_1ntake!" // A secure password for the new intake user
23+
24+
ctx := context.Background()
25+
26+
intakeClient, err := intake.NewAPIClient(
27+
sdkConfig.WithRegion(region),
28+
)
29+
if err != nil {
30+
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
31+
os.Exit(1)
32+
}
33+
34+
// Create an Intake Runner
35+
createRunnerPayload := intake.CreateIntakeRunnerPayload{
36+
DisplayName: utils.Ptr("my-example-runner"),
37+
MaxMessageSizeKiB: utils.Ptr(int64(10)),
38+
MaxMessagesPerHour: utils.Ptr(int64(1000)),
39+
}
40+
createRunnerResp, err := intakeClient.CreateIntakeRunner(ctx, projectId, region).CreateIntakeRunnerPayload(createRunnerPayload).Execute()
41+
if err != nil {
42+
fmt.Fprintf(os.Stderr, "Error creating Intake Runner: %v\n", err)
43+
os.Exit(1)
44+
}
45+
intakeRunnerId := *createRunnerResp.Id
46+
fmt.Printf("Triggered creation of Intake Runner with ID: %s. Waiting for it to become active...\n", intakeRunnerId)
47+
48+
// Create an Intake
49+
dremioAuthType := intake.CatalogAuthType("dremio") // can also be set to "none" if the catalog is not authenticated
50+
createIntakePayload := intake.CreateIntakePayload{
51+
DisplayName: utils.Ptr("my-example-intake"),
52+
IntakeRunnerId: utils.Ptr(intakeRunnerId),
53+
Catalog: &intake.IntakeCatalog{
54+
Uri: utils.Ptr(dremioCatalogURI),
55+
Warehouse: utils.Ptr(catalogWarehouse),
56+
Namespace: utils.Ptr("example_namespace"),
57+
TableName: utils.Ptr("example_table"),
58+
Auth: &intake.CatalogAuth{
59+
Type: &dremioAuthType,
60+
Dremio: &intake.DremioAuth{
61+
TokenEndpoint: utils.Ptr(dremioTokenEndpoint),
62+
PersonalAccessToken: utils.Ptr(dremioPAT),
63+
},
64+
},
65+
},
66+
}
67+
createIntakeResp, err := intakeClient.CreateIntake(ctx, projectId, region).CreateIntakePayload(createIntakePayload).Execute()
68+
if err != nil {
69+
fmt.Fprintf(os.Stderr, "Error creating Intake: %v\n", err)
70+
os.Exit(1)
71+
}
72+
intakeId := *createIntakeResp.Id
73+
fmt.Printf("Triggered creation of Intake with ID: %s. Waiting for it to become active...\n", intakeRunnerId)
74+
75+
createIntakeUserPayload := intake.CreateIntakeUserPayload{
76+
DisplayName: utils.Ptr("my-example-user"),
77+
Password: utils.Ptr(intakeUserPassword),
78+
}
79+
createIntakeUserResp, err := intakeClient.CreateIntakeUser(ctx, projectId, region, intakeId).CreateIntakeUserPayload(createIntakeUserPayload).Execute()
80+
if err != nil {
81+
fmt.Fprintf(os.Stderr, "Error creating Intake User: %v\n", err)
82+
os.Exit(1)
83+
}
84+
intakeUserId := *createIntakeUserResp.Id
85+
fmt.Printf("Created Intake User with ID: %s\n", intakeUserId)
86+
}

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use (
1010
./examples/dns
1111
./examples/errorhandling
1212
./examples/iaas
13+
./examples/intake
1314
./examples/kms
1415
./examples/loadbalancer
1516
./examples/logme

0 commit comments

Comments
 (0)