SDKs

Octelium APIs are all developed over gRPC. Most octeliumctl commands are wrappers over the Cluster's Core API methods. The SDK clients make it easy for applications to authenticate to the Cluster and manage resources such as Users, Services and Sessions programmatically.

The examples below create an authenticated client, list Users, create and update a User, create a Service and list Sessions. The authenticated User must have a Policy that permits these operations. Read more about authentication-token Credentials here and Policies here.

Golang SDK

The octelium-go library provides an authenticated gRPC connection for the Cluster APIs. It also handles obtaining and refreshing the Session access token used by the connection.

Install the module in your Go application as follows:

go get github.com/octelium/octelium/octelium-go

Here is a complete management example:

package main import ( "context" "fmt" "os" "time" "github.com/octelium/octelium/apis/main/corev1" "github.com/octelium/octelium/apis/main/metav1" octelium "github.com/octelium/octelium/octelium-go" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() if err := run(ctx); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func run(ctx context.Context) error { domain := os.Getenv("OCTELIUM_DOMAIN") authToken := os.Getenv("OCTELIUM_AUTH_TOKEN") if domain == "" || authToken == "" { return fmt.Errorf("OCTELIUM_DOMAIN and OCTELIUM_AUTH_TOKEN must be set") } client, err := octelium.New(ctx, octelium.WithDomain(domain), octelium.WithAuthenticator( octelium.AuthenticationToken(authToken), ), ) if err != nil { return err } defer client.Close() conn, err := client.Conn(ctx) if err != nil { return err } coreClient := corev1.NewMainServiceClient(conn) users, err := coreClient.ListUser(ctx, &corev1.ListUserOptions{}) if err != nil { return err } fmt.Printf("Cluster has %d users\n", len(users.Items)) userName := "linus" user, err := coreClient.CreateUser(ctx, &corev1.User{ Metadata: &metav1.Metadata{Name: userName}, Spec: &corev1.User_Spec{ Type: corev1.User_Spec_HUMAN, Email: "linus@example.com", }, }) if err != nil { return err } user.Spec.Email = "linus.updated@example.com" user, err = coreClient.UpdateUser(ctx, user) if err != nil { return err } fmt.Printf("Updated %q email to %s\n", user.Metadata.Name, user.Spec.Email) service, err := coreClient.CreateService(ctx, &corev1.Service{ Metadata: &metav1.Metadata{Name: "example-svc"}, Spec: &corev1.Service_Spec{ Mode: corev1.Service_Spec_HTTP, Port: 443, IsPublic: true, Config: &corev1.Service_Spec_Config{ Upstream: &corev1.Service_Spec_Config_Upstream{ Type: &corev1.Service_Spec_Config_Upstream_Url{ Url: "https://example.com", }, }, }, }, }) if err != nil { return err } fmt.Printf("Created service %q\n", service.Metadata.Name) sessions, err := coreClient.ListSession(ctx, &corev1.ListSessionOptions{}) if err != nil { return err } for _, session := range sessions.Items { fmt.Printf("Session %q is present\n", session.Metadata.Name) } return nil }

Set OCTELIUM_DOMAIN and OCTELIUM_AUTH_TOKEN before running the program.