|
| 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 | + "github.com/stackitcloud/stackit-sdk-go/services/intake/wait" |
| 12 | +) |
| 13 | + |
| 14 | +func main() { |
| 15 | + region := "REGION" // Region where the resources will be created |
| 16 | + projectId := "PROJECT_ID" // Your STACKIT project ID |
| 17 | + |
| 18 | + dremioCatalogURI := "DREMIO_CATALOG_URI" // E.g., "https://my-dremio-catalog.data-platform.stackit.run/iceberg" |
| 19 | + dremioTokenEndpoint := "DREMIO_TOKEN_ENDPOINT" // E.g., "https://my-dremio.data-platform.stackit.run/oauth/token" |
| 20 | + dremioPAT := "DREMIO_PERSONAL_ACCESS_TOKEN" // Your Dremio Personal Access Token |
| 21 | + catalogWarehouse := "CATALOG_WAREHOUSE" // Catalog warehouse where the data will be ingested |
| 22 | + |
| 23 | + intakeUserPassword := "s3cuRe_p@ssW0rd_f0r_1ntake!" // A secure password for the new intake user |
| 24 | + |
| 25 | + ctx := context.Background() |
| 26 | + |
| 27 | + intakeClient, err := intake.NewAPIClient( |
| 28 | + sdkConfig.WithRegion(region), |
| 29 | + ) |
| 30 | + if err != nil { |
| 31 | + fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) |
| 32 | + os.Exit(1) |
| 33 | + } |
| 34 | + |
| 35 | + // Create an Intake Runner |
| 36 | + createRunnerPayload := intake.CreateIntakeRunnerPayload{ |
| 37 | + DisplayName: utils.Ptr("my-example-runner"), |
| 38 | + MaxMessageSizeKiB: utils.Ptr(int64(10)), |
| 39 | + MaxMessagesPerHour: utils.Ptr(int64(1000)), |
| 40 | + } |
| 41 | + createRunnerResp, err := intakeClient.CreateIntakeRunner(ctx, projectId, region).CreateIntakeRunnerPayload(createRunnerPayload).Execute() |
| 42 | + if err != nil { |
| 43 | + fmt.Fprintf(os.Stderr, "Error creating Intake Runner: %v\n", err) |
| 44 | + os.Exit(1) |
| 45 | + } |
| 46 | + intakeRunnerId := *createRunnerResp.Id |
| 47 | + fmt.Printf("Triggered creation of Intake Runner with ID: %s. Waiting for it to become active...\n", intakeRunnerId) |
| 48 | + |
| 49 | + // Wait for the Intake Runner to become active |
| 50 | + _, err = wait.CreateOrUpdateIntakeRunnerWaitHandler(ctx, intakeClient, projectId, region, intakeRunnerId).WaitWithContext(ctx) |
| 51 | + if err != nil { |
| 52 | + fmt.Fprintf(os.Stderr, "Error waiting for Intake Runner: %v\n", err) |
| 53 | + os.Exit(1) |
| 54 | + } |
| 55 | + |
| 56 | + // Create an Intake |
| 57 | + dremioAuthType := intake.CatalogAuthType("dremio") // can also be set to "none" if the catalog is not authenticated |
| 58 | + createIntakePayload := intake.CreateIntakePayload{ |
| 59 | + DisplayName: utils.Ptr("my-example-intake"), |
| 60 | + IntakeRunnerId: utils.Ptr(intakeRunnerId), |
| 61 | + Catalog: &intake.IntakeCatalog{ |
| 62 | + Uri: utils.Ptr(dremioCatalogURI), |
| 63 | + Warehouse: utils.Ptr(catalogWarehouse), |
| 64 | + Namespace: utils.Ptr("example_namespace"), |
| 65 | + TableName: utils.Ptr("example_table"), |
| 66 | + Auth: &intake.CatalogAuth{ |
| 67 | + Type: &dremioAuthType, |
| 68 | + Dremio: &intake.DremioAuth{ |
| 69 | + TokenEndpoint: utils.Ptr(dremioTokenEndpoint), |
| 70 | + PersonalAccessToken: utils.Ptr(dremioPAT), |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + } |
| 75 | + createIntakeResp, err := intakeClient.CreateIntake(ctx, projectId, region).CreateIntakePayload(createIntakePayload).Execute() |
| 76 | + if err != nil { |
| 77 | + fmt.Fprintf(os.Stderr, "Error creating Intake: %v\n", err) |
| 78 | + os.Exit(1) |
| 79 | + } |
| 80 | + intakeId := *createIntakeResp.Id |
| 81 | + fmt.Printf("Triggered creation of Intake with ID: %s. Waiting for it to become active...\n", intakeRunnerId) |
| 82 | + |
| 83 | + // Wait for the Intake to become active |
| 84 | + _, err = wait.CreateOrUpdateIntakeWaitHandler(ctx, intakeClient, projectId, region, intakeId).WaitWithContext(ctx) |
| 85 | + if err != nil { |
| 86 | + fmt.Fprintf(os.Stderr, "Error waiting for Intake: %v\n", err) |
| 87 | + os.Exit(1) |
| 88 | + } |
| 89 | + |
| 90 | + createIntakeUserPayload := intake.CreateIntakeUserPayload{ |
| 91 | + DisplayName: utils.Ptr("my-example-user"), |
| 92 | + Password: utils.Ptr(intakeUserPassword), |
| 93 | + } |
| 94 | + createIntakeUserResp, err := intakeClient.CreateIntakeUser(ctx, projectId, region, intakeId).CreateIntakeUserPayload(createIntakeUserPayload).Execute() |
| 95 | + if err != nil { |
| 96 | + fmt.Fprintf(os.Stderr, "Error creating Intake User: %v\n", err) |
| 97 | + os.Exit(1) |
| 98 | + } |
| 99 | + intakeUserId := *createIntakeUserResp.Id |
| 100 | + fmt.Printf("Triggered creation of Intake User with ID: %s. Waiting for it to become active...\n", intakeRunnerId) |
| 101 | + |
| 102 | + // Wait for the Intake User to become active |
| 103 | + _, err = wait.CreateOrUpdateIntakeUserWaitHandler(ctx, intakeClient, projectId, region, intakeId, intakeUserId).WaitWithContext(ctx) |
| 104 | + if err != nil { |
| 105 | + fmt.Fprintf(os.Stderr, "Error waiting for Intake User: %v\n", err) |
| 106 | + os.Exit(1) |
| 107 | + } |
| 108 | +} |
0 commit comments