dcsdk

package module
v0.0.0-...-8bc9604 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

README

DoubleCloud Go SDK

GoDoc

Go SDK for DoubleCloud API.

Installation

go install github.com/doublecloud/go-sdk@latest

Usage examples

Initializing SDK
key, err := iamkey.ReadFromJSONFile(*flags.saPath)
if err != nil {
    panic(err)
}
creds, err := dc.ServiceAccountKey(key)
if err != nil {
    panic(err)
}
sdk, err := dc.Build(ctx, dc.Config{
    Credentials: creds,
})
More examples

More examples can be found in examples directory.

Documentation

Index

Constants

View Source
const (
	DefaultPageSize int64 = 1000

	ClickHouseServiceID    Endpoint = "clickhouse"
	KafkaServiceID         Endpoint = "kafka"
	VpcServiceID           Endpoint = "vpc"
	TransferServiceID      Endpoint = "transfer"
	VisualizationServiceID Endpoint = "visualization"
	LogsServiceID          Endpoint = "logs"
)

Variables

This section is empty.

Functions

func WithAuthAsServiceAccount

func WithAuthAsServiceAccount(serviceAccountID string) grpc.CallOption

func WithAuthAsServiceAccounts

func WithAuthAsServiceAccounts(saGetter SAGetter) grpc.CallOption

Types

type APIEndpoint

type APIEndpoint struct {
	Id      Endpoint
	Address string
}

type Authenticator

type Authenticator interface {
	CreateIAMToken(ctx context.Context) (*iamkey.CreateIamTokenResponse, error)
	CreateIAMTokenForServiceAccount(ctx context.Context, serviceAccountID string) (*iamkey.CreateIamTokenResponse, error)
}

type Config

type Config struct {
	// Credentials are used to authenticate the client. See Credentials for more info.
	Credentials Credentials
	// DialContextTimeout specifies timeout of dial on API endpoint that
	// is used when building an SDK instance.
	// DialContextTimeout time.Duration
	// TLSConfig is optional tls.Config that one can use in order to tune TLS options.
	TLSConfig *tls.Config

	// Endpoint is an API endpoint of DoubleCloud against which the SDK is used.
	// Most users won't need to explicitly set it.
	Endpoint         string
	OverrideEndpoint bool
	Plaintext        bool
}

Config is a config that is used to create SDK instance.

type Credentials

type Credentials interface {
	DCAPICredentials()
}

Credentials is an abstraction of API authorization credentials. See https://double.cloud/docs/en/public-api/get-iam-token for details. Note that functions that return Credentials may return different Credentials implementation in next SDK version, and this is not considered breaking change.

func ServiceAccountKey

func ServiceAccountKey(key *iamkey.Key) (Credentials, error)

ServiceAccountKey returns credentials for the given IAM Key. The key is used to sign JWT tokens. JWT tokens are exchanged for IAM Tokens used to authorize API calls. This authorization method is not supported for IAM Keys issued for User Accounts.

type Endpoint

type Endpoint string

type ExchangeableCredentials

type ExchangeableCredentials interface {
	Credentials
	// IAMTokenRequest returns request for fresh IAM token or error.
	IAMTokenRequest() (*iamkey.CreateIamTokenRequest, error)
}

ExchangeableCredentials can be exchanged for IAM Token in IAM Token Service, that can be used to authorize API calls. See https://double.cloud/docs/en/public-api/get-iam-token for details.

type IAMTokenCredentials

type IAMTokenCredentials struct {
	// contains filtered or unexported fields
}

IAMTokenCredentials implements Credentials with IAM token as-is

func (IAMTokenCredentials) DCAPICredentials

func (creds IAMTokenCredentials) DCAPICredentials()

func (IAMTokenCredentials) IAMToken

type IamTokenMiddleware

type IamTokenMiddleware struct {
	// contains filtered or unexported fields
}

func NewIAMTokenMiddleware

func NewIAMTokenMiddleware(authenticator Authenticator, now func() time.Time) *IamTokenMiddleware

func (*IamTokenMiddleware) GetIAMToken

func (c *IamTokenMiddleware) GetIAMToken(ctx context.Context, originalSubject bool, opts ...grpc.CallOption) (string, error)

func (*IamTokenMiddleware) InterceptStream

func (c *IamTokenMiddleware) InterceptStream(ctx context.Context, desc *grpc.StreamDesc, conn *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)

func (*IamTokenMiddleware) InterceptUnary

func (c *IamTokenMiddleware) InterceptUnary(ctx context.Context, method string, req, reply interface{}, conn *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

type NoCredentials

type NoCredentials struct{}

NoCredentials implements Credentials, it allows to create unauthenticated connections

func (NoCredentials) DCAPICredentials

func (creds NoCredentials) DCAPICredentials()

func (NoCredentials) IAMToken

IAMToken always returns gRPC error with status UNAUTHENTICATED

type NonExchangeableCredentials

type NonExchangeableCredentials interface {
	Credentials
	// IAMToken returns IAM Token.
	IAMToken(ctx context.Context) (*iamkey.CreateIamTokenResponse, error)
}

NonExchangeableCredentials allows to get IAM Token without calling IAM Token Service.

func NewIAMTokenCredentials

func NewIAMTokenCredentials(iamToken string) NonExchangeableCredentials

type SAGetter

type SAGetter func(ctx context.Context) (string, error)

type SDK

type SDK struct {
	// contains filtered or unexported fields
}

SDK is a DoubleCloud SDK

func Build

func Build(ctx context.Context, conf Config, customOpts ...grpc.DialOption) (*SDK, error)

Build creates an SDK instance

func (*SDK) CheckEndpointConnection

func (sdk *SDK) CheckEndpointConnection(ctx context.Context, endpoint Endpoint) error

func (*SDK) ClickHouse

func (sdk *SDK) ClickHouse() *clickhouse.ClickHouse

func (*SDK) CreateIAMToken

func (sdk *SDK) CreateIAMToken(ctx context.Context) (*iamkey.CreateIamTokenResponse, error)

func (*SDK) CreateIAMTokenForServiceAccount

func (sdk *SDK) CreateIAMTokenForServiceAccount(ctx context.Context, serviceAccountID string) (*iamkey.CreateIamTokenResponse, error)

func (*SDK) Endpoint

func (sdk *SDK) Endpoint(endpointName Endpoint) (ep *APIEndpoint, exist bool)

func (*SDK) InitErr

func (sdk *SDK) InitErr() error

func (*SDK) Kafka

func (sdk *SDK) Kafka() *kafka.Kafka

func (*SDK) KnownServices

func (sdk *SDK) KnownServices() []string

func (*SDK) Logs

func (sdk *SDK) Logs() *logs.Export

func (*SDK) Network

func (sdk *SDK) Network() *network.Network

func (*SDK) Shutdown

func (sdk *SDK) Shutdown(ctx context.Context) error

Shutdown shutdowns SDK and closes all open connections.

func (*SDK) Transfer

func (sdk *SDK) Transfer() *transfer.Transfer

func (*SDK) Visualization

func (sdk *SDK) Visualization() *visualization.Visualization

func (*SDK) WrapOperation

func (sdk *SDK) WrapOperation(o *dcv1.Operation, err error) (*operation.Operation, error)

WrapOperation wraps operation proto message to handy structure

type ServiceIsNotAvailableError

type ServiceIsNotAvailableError struct {
	ServiceID   Endpoint
	APIEndpoint string
	// contains filtered or unexported fields
}

func (*ServiceIsNotAvailableError) Error

Directories

Path Synopsis
examples
gen
clickhouse
nolint
nolint
kafka
nolint
nolint
logs
nolint
nolint
network
nolint
nolint
transfer
nolint
nolint
visualization
nolint
nolint
pkg

Jump to

Keyboard shortcuts

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