Documentation
¶
Index ¶
- Constants
- type Credentials
- func CustomAuthenticator(auth auth.Authenticator) Credentials
- func CustomTokener(tokener auth.BearerTokener) Credentials
- func IAMToken(token string) Credentials
- func NoCredentials() Credentials
- func OneOfCredentials(creds map[auth.Selector]Credentials) Credentials
- func PropagateAuthorizationHeader() Credentials
- func ServiceAccount(account auth.ServiceAccount) Credentials
- func ServiceAccountReader(reader auth.ServiceAccountReader) Credentials
- type NoopHandler
- type Option
- func WithAddressTemplate(find string, replace string) Option
- func WithAuthTimeout(timeout time.Duration) Option
- func WithConfigReader(configReader config.ConfigInterface) Option
- func WithCredentials(creds Credentials) Option
- func WithDialOptions(opts ...grpc.DialOption) Option
- func WithDomain(domain string) Option
- func WithExplicitInit(explicitInit bool) Option
- func WithInit(fn func(context.Context, *SDK) error) Option
- func WithLogger(logger *slog.Logger) Option
- func WithLoggerHandler(handler slog.Handler) Option
- func WithLoggingOptions(opts ...logging.Option) Option
- func WithNoParentID(noParentID bool) Option
- func WithParentID(parentID string) Option
- func WithResolvers(resolvers ...conn.Resolver) Option
- func WithRetryOptions(opts ...retry.CallOption) Option
- func WithTenantID(tenantID string) Option
- func WithTimeout(timeout time.Duration) Option
- func WithUserAgentPrefix(prefix string) Option
- func WithoutParentID() Option
- type SDK
- func (s *SDK) BearerToken(ctx context.Context) (auth.BearerToken, error)
- func (s *SDK) Close() error
- func (s *SDK) Context() context.Context
- func (s *SDK) Dial(ctx context.Context, address conn.Address) (grpc.ClientConnInterface, error)
- func (s *SDK) GetLogger() *slog.Logger
- func (s *SDK) Init(ctx context.Context) error
- func (s *SDK) ParentID() string
- func (s *SDK) Resolve(ctx context.Context, id conn.ServiceID) (conn.Address, error)
- func (s *SDK) Services() nebius.Services
- func (s *SDK) TenantID() string
Examples ¶
Constants ¶
const ( DefaultTimeout = 1 * time.Minute DefaultRetries = 3 DefaultPerRetry = DefaultTimeout / DefaultRetries DefaultAuthTimeout = 15 * time.Minute // should be large enough to authenticate manually )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
type Credentials interface {
// contains filtered or unexported methods
}
Credentials are used to authenticate outgoing gRPC requests. To disable authentication for a specific request use the auth.Disable call option.
Example (UseIAMToken) ¶
package main
import (
"context"
"log/slog"
"os"
"github.com/nebius/gosdk"
)
func main() {
ctx := context.Background()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
sdk, err := gosdk.New(
ctx,
gosdk.WithLogger(logger),
gosdk.WithCredentials(
gosdk.IAMToken(os.Getenv("MY_ENV")),
),
)
if err != nil {
return // fmt.Errorf("create gosdk: %w", err)
}
defer func() {
errX := sdk.Close()
if errX != nil {
logger.ErrorContext(ctx, "failed to close sdk", slog.Any("error", errX))
}
}()
}
Example (UseServiceAccount) ¶
package main
import (
"context"
"log/slog"
"os"
"github.com/nebius/gosdk"
"github.com/nebius/gosdk/auth"
)
func main() {
ctx := context.Background()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
// you can find more ways to create a service account in the auth package
serviceAccount := auth.NewPrivateKeyFileParser(
nil, // or you can set up your own fs, eg: `os.DirFS("."),`
"private/key/file/path",
"public-key-id",
"service-account-id",
)
sdk, err := gosdk.New(
ctx,
gosdk.WithLogger(logger),
gosdk.WithCredentials(
gosdk.ServiceAccountReader(serviceAccount),
),
)
if err != nil {
return // fmt.Errorf("create gosdk: %w", err)
}
defer func() {
errX := sdk.Close()
if errX != nil {
logger.ErrorContext(ctx, "failed to close sdk", slog.Any("error", errX))
}
}()
}
func CustomAuthenticator ¶
func CustomAuthenticator(auth auth.Authenticator) Credentials
CustomAuthenticator allows the user to define its own auth.Authenticator implementation.
func CustomTokener ¶
func CustomTokener(tokener auth.BearerTokener) Credentials
CustomTokener allows the user to define its own auth.BearerTokener implementation for authentication.
func IAMToken ¶
func IAMToken(token string) Credentials
IAMToken is a Credentials that uses a predefined token for authentication.
func NoCredentials ¶
func NoCredentials() Credentials
NoCredentials is the default Credentials that disables authentication.
func OneOfCredentials ¶
func OneOfCredentials(creds map[auth.Selector]Credentials) Credentials
OneOfCredentials allows you to use different credentials for different requests. Exactly one auth.Selector from creds map must be added to call options to choose one.
You can use predefined auth.Base and auth.Propagate selectors as well as auth.Select with custom name.
func PropagateAuthorizationHeader ¶
func PropagateAuthorizationHeader() Credentials
PropagateAuthorizationHeader uses auth.AuthorizationHeader from the incoming grpc metadata and puts it into the outgoing metadata.
func ServiceAccount ¶
func ServiceAccount(account auth.ServiceAccount) Credentials
ServiceAccount is the same as ServiceAccountReader but with constant auth.ServiceAccount.
func ServiceAccountReader ¶
func ServiceAccountReader(reader auth.ServiceAccountReader) Credentials
ServiceAccountReader authorizes gRPC requests using auth.ServiceAccount. It receives an auth.BearerToken from the IAM by exchanging a JWT. The JWT is signed using the private key of the service account.
The SDK ensures a continuously valid bearer token by caching the current token and asynchronously requesting a new one before expiration.
Note: the reader is used only once as it is wrapped with auth.CachedServiceAccount.
type NoopHandler ¶
type NoopHandler struct{}
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is an interface combining all options for New func.
func WithAddressTemplate ¶
WithAddressTemplate customizes service address resolution.
func WithAuthTimeout ¶
WithAuthTimeout sets overall timeout for the request plus authentication. The default is 15 minutes. This timeout should be larger than the timeout set by WithTimeout. If the authentication process takes longer than this timeout, the request will fail.
func WithConfigReader ¶
func WithConfigReader(configReader config.ConfigInterface) Option
WithConfigReader sets the config reader to read configuration from. It will enable ParentID autofill, if ParentID is set in the config. You can disable ParentID autofill by adding WithNoParentID or WithoutParentID option. By default, it reads configuration from the standard Nebius CLI config file.
func WithCredentials ¶
func WithCredentials(creds Credentials) Option
WithCredentials enables client authentication. By default, NoCredentials is used.
Credentials are applied under the following conditions:
- The outgoing gRPC metadata does not already include authorization information.
- The list of gRPC call options does not contain github.com/nebius/gosdk/auth.DisableAuth.
If either of these conditions is not met, the provided credentials will not be used.
func WithDialOptions ¶
func WithDialOptions(opts ...grpc.DialOption) Option
WithDialOptions allows you to specify additional grpc dial options for all services. You can use conn.WithAddressDialOptions to use different options for a specific conn.Address.
func WithDomain ¶
WithDomain changes the default "api.nebius.cloud:443" domain.
func WithExplicitInit ¶
WithExplicitInit alters the behavior of the New constructor. If explicitInit is false (the default), SDK.Init is automatically called by New. If explicitInit is true, you must manually call SDK.Init yourself. This option is useful for separating the SDK instantiation from I/O operations.
func WithInit ¶
WithInit adds an extra fn, which will be called on init SDK. The context passed to the function is short-lived. If you need to start a goroutine, use SDK.Context to get a long-lived context.
func WithLogger ¶
WithLogger enables logging in the SDK. By default NoopHandler is used.
func WithLoggerHandler ¶
WithLoggerHandler enables logging in the SDK. By default NoopHandler is used.
func WithLoggingOptions ¶
WithLoggingOptions allows you to specify additional configurations for the grpc-ecosystem logging interceptor.
func WithNoParentID ¶
WithNoParentID indicates that the SDK should not use a parent ID by default. This is useful when the parent ID is not applicable to the service being used.
If withParentID is set to true, it will override any previous call to WithParentID.
func WithParentID ¶
WithParentID sets the default parent ID for all requests. This can be overridden by methods that accept a parent ID parameter.
If no parent ID is set (the default), methods that require a parent ID will return an error if the parent ID is not provided in the method call.
It will override any previous call to WithNoParentID or WithoutParentID.
func WithResolvers ¶
WithResolvers customizes service address resolution.
func WithRetryOptions ¶
func WithRetryOptions(opts ...retry.CallOption) Option
WithRetryOptions enables retries and allows you to specify additional configurations for the grpc-ecosystem retry interceptor. By default, if this option is not set, retries will be set with three attempts, 1/3 of timeout per retry attempt, no cooldown or backoff, and with a custom retry function that takes into account the API-specific retry information. It is advised to set backoff and overall timeout (using WithTimeout) depending on your request and usage.
func WithTenantID ¶
WithTenantID sets the default tenant ID for all requests that need a tenant as a parent ID. This can be overridden by methods that accept a parent ID parameter.
If no tenant ID is set (the default), methods that require a tenant as a parent ID will return an error if the parent ID is not provided in the method call.
func WithTimeout ¶
WithTimeout changes timeout for all requests. The default is 1 minute. This timeout does not include authentication time, which is controlled by WithAuthTimeout.
func WithUserAgentPrefix ¶
WithUserAgentPrefix adds a prefix to the User-Agent header sent with each request. By default, the User-Agent is "nebius-gosdk/<version> (os arch; go/ver) grpc-go/<version>". You can use this option to identify your application. Please, use the following format for the prefix: "<app-name>[/<app-version>][ (critical-dependency/versions; if-necessary-to-track)]".
func WithoutParentID ¶
func WithoutParentID() Option
WithoutParentID is a shorthand for WithNoParentID with true value. It will override any previous call to WithParentID.
type SDK ¶
type SDK struct {
// contains filtered or unexported fields
}
SDK is the Nebius API client.
Example ¶
This example demonstrates how to create and configure a new gosdk.SDK instance with logging and credentials, then retrieve a list of compute instances using the gosdk API.
After usage, the SDK instance should be closed.
Note: Be sure to replace `creds` with appropriate credentials.
package main
import (
"context"
"fmt"
"log/slog"
"os"
"github.com/nebius/gosdk"
compute "github.com/nebius/gosdk/proto/nebius/compute/v1"
)
func main() {
ctx := context.Background()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
var creds gosdk.Credentials // define your credentials (see other examples)
sdk, err := gosdk.New(
ctx,
gosdk.WithLogger(logger),
gosdk.WithCredentials(creds),
)
if err != nil {
return // fmt.Errorf("create gosdk: %w", err)
}
defer func() {
errX := sdk.Close()
if errX != nil {
logger.ErrorContext(ctx, "failed to close sdk", slog.Any("error", errX))
}
}()
list, err := sdk.Services().Compute().V1().Instance().List(ctx, &compute.ListInstancesRequest{
ParentId: "my-parent",
})
if err != nil {
return // fmt.Errorf("list instances: %w", err)
}
for _, instance := range list.GetItems() {
fmt.Println(instance.GetMetadata().GetId())
}
}
func New ¶
New creates a new SDK with the provided options. By default, it also performs any necessary I/O operations. To separate I/O operations from instantiation, use the WithExplicitInit option. The context provided to New can be short-lived, as it is used only for the initial setup. SDK may span goroutines that will use the context returned by SDK.Context. If you want to stop the goroutines, you should call SDK.Close. Add a WithConfigReader option to read configuration from the standard Nebius CLI config file. We also recommend setting a WithUserAgentPrefix option to identify your application.
func (*SDK) BearerToken ¶
BearerToken returns the token used to authorize gRPC requests.
func (*SDK) Context ¶
Context returns a long-lived context for the internal SDK operations that lives as long as the SDK itself and is canceled when the SDK is closed (by calling SDK.Close).
func (*SDK) Init ¶
Init finalizes the creation of the SDK by performing all required I/O operations. It is automatically called by the New constructor by default. This method should only be called manually if the WithExplicitInit option is used.
Example ¶
This examples demonstrates using the gosdk.WithExplicitInit option to separate gosdk.SDK construction (gosdk.New) from IO operations performed during gosdk.SDK.Init. This allows for explicit control over initialization timing.
package main
import (
"context"
"log/slog"
"os"
"github.com/nebius/gosdk"
)
func main() {
ctx := context.Background()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
var creds gosdk.Credentials // define your credentials (see other examples)
sdk, err := gosdk.New(
ctx,
gosdk.WithLogger(logger),
gosdk.WithCredentials(creds),
gosdk.WithExplicitInit(true),
)
if err != nil {
return // fmt.Errorf("create gosdk: %w", err)
}
defer func() {
errX := sdk.Close()
if errX != nil {
logger.ErrorContext(ctx, "failed to close sdk", slog.Any("error", errX))
}
}()
err = sdk.Init(ctx)
if err != nil {
return // fmt.Errorf("init gosdk: %w", err)
}
}
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package iter is created to simplify migration to iter package from stdlib when we support it.
|
Package iter is created to simplify migration to iter package from stdlib when we support it. |
|
mocks
|
|
|
nebius/applications/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/audit/v2
Package v2 is a generated GoMock package.
|
Package v2 is a generated GoMock package. |
|
nebius/billing/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/compute/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/compute/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/dns/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/iam/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/iam/v2
Package v2 is a generated GoMock package.
|
Package v2 is a generated GoMock package. |
|
nebius/logging/v1/agentmanager
Package agentmanager is a generated GoMock package.
|
Package agentmanager is a generated GoMock package. |
|
nebius/maintenance/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/mk8s/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/mk8s/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/msp/mlflow/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/msp/postgresql/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/msp/serverless/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/mysterybox/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/quotas/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/registry/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/storage/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/storage/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
nebius/vpc/v1
Package v1 is a generated GoMock package.
|
Package v1 is a generated GoMock package. |
|
nebius/vpc/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
|
operations
Package operations is a generated GoMock package.
|
Package operations is a generated GoMock package. |
|
proto
|
|
|
services
|
|