yc

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: Apache-2.0 Imports: 13 Imported by: 4

README

ydb-go-yc-metadata

helpers to connect to YDB inside yandex-cloud using metadata service

godoc

Overview

Currently package provides helpers to connect to YDB inside yandex-cloud.

Usage

import (
	yc "github.com/ydb-platform/ydb-go-yc-metadata"
)
...
    db, err := ydb.Open(
        ctx,
	os.Getenv("YDB_CONNECTION_STRING"),
        yc.WithInternalCA(),
        yc.WithCredentials(ctx), // auth inside cloud (virtual machine or yandex function)
    )
    

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithInternalCA

func WithInternalCA() ydb.Option

Types

type InstanceServiceAccountCredentials added in v0.5.0

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

func NewInstanceServiceAccount

NewInstanceServiceAccount makes credentials provider that uses instance metadata url to obtain token for service account attached to instance. Cancelling context will lead to credentials refresh halt. It should be used during application stop or credentials recreation.

Example
package main

import (
	"context"

	ydb "github.com/ydb-platform/ydb-go-sdk/v3"
	yc "github.com/ydb-platform/ydb-go-yc-metadata"
)

func main() {
	db, err := ydb.Open(context.TODO(), "grpc://localhost:2136/local",
		ydb.WithCredentials(
			yc.NewInstanceServiceAccount(
				yc.WithURL("http://localhost:6770/meatadata/v1/instance/service-accounts/default/token"),
			),
		),
	)
	if err != nil {
		panic(err)
	}
	_ = db.Close(context.TODO())
}
Output:

func (*InstanceServiceAccountCredentials) Stop added in v0.5.0

func (*InstanceServiceAccountCredentials) String added in v0.5.0

func (*InstanceServiceAccountCredentials) Token added in v0.5.0

func (m *InstanceServiceAccountCredentials) Token(ctx context.Context) (token string, err error)

Token returns cached token if it is valid. Otherwise, will try to renew.

type InstanceServiceAccountCredentialsOption added in v0.5.0

type InstanceServiceAccountCredentialsOption interface {
	ApplyInstanceServiceAccountCredentialsOption(c *InstanceServiceAccountCredentials)
}

func WithInstanceServiceAccountCredentialsSourceInfo added in v0.5.0

func WithInstanceServiceAccountCredentialsSourceInfo(sourceInfo string) InstanceServiceAccountCredentialsOption

func WithInstanceServiceAccountURL added in v0.5.0

func WithInstanceServiceAccountURL(url string) InstanceServiceAccountCredentialsOption

func WithRetryNotFound added in v0.6.0

func WithRetryNotFound() InstanceServiceAccountCredentialsOption

func WithTrace added in v0.1.0

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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