Golang SDK
Octelium APIs are all developed over gRPC. Currently the Golang implementation is officially supported and as it is the primary programming language for developing Octelium itself. For example, most octeliumctl commands are nothing but wrappers over the Cluster's Core API (or service methods according to the gRPC nomenclature). The octelium-go library makes it easy for Golang-based applications to actually authenticate to the Cluster, mainly using an authentication token (read more about authentication token Credentials here), interact with its APIs, and also be able to access the Cluster's Services without having to worry about manually re-authentcating their Session before its access token expires.
Here is a simple example that uses octelium-go client to create a gRPC client that can access the Core API service methods to manage the different Core API resources such as User and ClusterConfig:
package main
import (
"context"
"fmt"
"os"
"github.com/octelium/octelium/apis/main/corev1"
"github.com/octelium/octelium/apis/main/metav1"
"github.com/octelium/octelium/octelium-go"
)
func main() {
if err := doMain(context.Background()); err != nil {
panic(err)
}
}
func doMain(ctx context.Context) error {
octeliumC, err := octelium.NewClient(ctx, &octelium.ClientConfig{
Domain: "example.com",
AuthenticationToken: os.Getenv("AUTH_TOKEN"),
})
if err != nil {
return err
}
defer octeliumC.Close()
grpcConn, err := octeliumC.GRPC().GetConn(ctx)
if err != nil {
return err
}
coreC := corev1.NewMainServiceClient(grpcConn)
{
usr, err := coreC.CreateUser(ctx, &corev1.User{
Metadata: &metav1.Metadata{
Name: "usr-01",
},
Spec: &corev1.User_Spec{
Type: corev1.User_Spec_HUMAN,
Email: "usr01@example.com",
},
})
if err != nil {
return err
}
userList, err := coreC.ListUser(ctx, &corev1.ListUserOptions{})
if err != nil {
return err
}
fmt.Printf("%+v\n", userList)
usr, err = coreC.GetUser(ctx, &metav1.GetOptions{
Name: usr.Metadata.Name,
})
if err != nil {
return err
}
_, err = coreC.DeleteUser(ctx, &metav1.DeleteOptions{
Uid: usr.Metadata.Uid,
})
if err != nil {
return err
}
}
{
cc, err := coreC.GetClusterConfig(ctx, &corev1.GetClusterConfigRequest{})
if err != nil {
return err
}
cc.Spec.Session = &corev1.ClusterConfig_Spec_Session{
Human: &corev1.ClusterConfig_Spec_Session_Human{
MaxPerUser: 16,
},
}
_, err = coreC.UpdateClusterConfig(ctx, cc)
if err != nil {
return err
}
}
return nil
}You can also use the Octelium Golang client in your HTTP and gRPC clients to access the Cluster publicly exposed/BeyondCorp Services. You can discover more examples about using the GO SDK to access APIs and Kubernetes clusters here and here.