cedanagosdk

package module
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2025 License: GPL-3.0 Imports: 12 Imported by: 2

README

cedana-go-sdk

A very robust cedana-go-sdk library generated using kiota from OpenAPI spec.

Usage

package example

import (
	"context"
	"fmt"
	"os"

	sdk "github.com/cedana/cedana-go-sdk"
	sdk_models "github.com/cedana/cedana-go-sdk/models"
)

func FromEnvOrElse(key, def string) string {
	if value, found := os.LookupEnv(key); found {
		return value
	}
	return def
}

var (
	apiKey    = os.Getenv("CEDANA_AUTH_TOKEN_TEST")
	cedanaUrl = FromEnvOrElse("CEDANA_URL_TEST", "http://localhost:1324")
)

func Main() {
	client := sdk.NewCedanaClient(cedanaUrl, apiKey)

  // get user
	user, err := client.V2().User().Get(context.Background(), nil)
	if err != nil {
		switch v := err.(type) {
		case *sdk_models.HttpError:
			fmt.Printf("failed to get user: %s :error_code(%d)", *v.GetMessage(), *v.GetCedanaErrorCode())
		default:
			fmt.Printf("unknown error: %v", v)
		}
	} else {
		fmt.Printf("user: %s\n", *user)
	}

	jobs, err := client.V2().Jobs().Get(context.Background(), nil)
	if err != nil {
		switch v := err.(type) {
		case *sdk_models.HttpError:
			fmt.Printf("failed to get job: %s :error_code(%d)", *v.GetMessage(), *v.GetCedanaErrorCode())
		default:
			fmt.Printf("unknown error: %v", v)
		}
	} else {
		for i, job := range jobs {
			fmt.Printf("job %d: %s %s\n", i, *job.GetJid(), *job.GetTypeEscaped())
		}
	}

	checkpoints, err := client.V2().Checkpoints().Get(context.Background(), nil)
	if err != nil {
		switch v := err.(type) {
		case *sdk_models.HttpError:
			fmt.Printf("failed to get checkpoint: %s :error_code(%d)", *v.GetMessage(), *v.GetCedanaErrorCode())
		default:
			fmt.Printf("unknown error: %v", v)
		}
	} else {
		for i, checkpoint := range checkpoints {
			fmt.Printf("checkpoint %d: %s %s\n", i, *checkpoint.GetId(), *checkpoint.GetStatus())
		}
	}

	uuid, err := client.V2().Checkpoints().Post(context.Background(), nil)
	if err != nil {
		switch v := err.(type) {
		case *sdk_models.HttpError:
			fmt.Printf("failed to create checkpoint: %s :error_code(%d)", *v.GetMessage(), *v.GetCedanaErrorCode())
		default:
			fmt.Printf("unknown error: %v", v)
		}
	} else {
		fmt.Printf("new checkpoint %v\n", *uuid)
	}
}

func testCheckpointsUpload() {
	client := sdk.NewCedanaClient(cedanaUrl, apiKey)
	uuid := "04ee4678-d934-4eeb-97ed-d4cf779ae4fc"
	upload_url, err := client.V2().Checkpoints().Upload().ById(uuid).Patch(context.Background(), nil)
	if err != nil {
		switch v := err.(type) {
		case *sdk_models.HttpError:
			fmt.Printf("failed to get upload url for checkpoint: %s :error_code(%d)", *v.GetMessage(), *v.GetCedanaErrorCode())
		default:
			fmt.Printf("unknown error: %v", v)
		}
	} else {
		fmt.Printf("uploading checkpoint %v\n", *upload_url)
	}
}

func testCheckpointsDownload() {
	client := sdk.NewCedanaClient(cedanaUrl, apiKey)
	uuid := "04ee4678-d934-4eeb-97ed-d4cf779ae4fc"
	download_url, err := client.V2().Checkpoints().Download().ById(uuid).Get(context.Background(), nil)
	if err != nil {
		switch v := err.(type) {
		case *sdk_models.HttpError:
			fmt.Printf("failed to get download url for checkpoint: %s :error_code(%d)", *v.GetMessage(), *v.GetCedanaErrorCode())
		default:
			fmt.Printf("unknown error: %v", v)
		}
	} else {
		fmt.Printf("download checkpoint from %v\n", *download_url)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

ApiClient the main entry point of the SDK, exposes the configuration and the fluent API.

func NewApiClient

NewApiClient instantiates a new ApiClient and sets the default values.

func NewCedanaClient

func NewCedanaClient(rawUrl, api_key string) *ApiClient

func (*ApiClient) V2

V2 the v2 property returns a *V2RequestBuilder when successful

type StaticAccessTokenProvider

type StaticAccessTokenProvider struct {
	AccessToken string
}

func (*StaticAccessTokenProvider) GetAllowedHostsValidator

func (*StaticAccessTokenProvider) GetAllowedHostsValidator() *auth.AllowedHostsValidator

GetAllowedHostsValidator returns the hosts validator.

func (*StaticAccessTokenProvider) GetAuthorizationToken

func (s *StaticAccessTokenProvider) GetAuthorizationToken(_ context.Context, _ *url.URL, _ map[string]any) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL