aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/yandex/tvm/client.go
blob: f05a97e2d54da5566708691b4329494ed134b5ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tvm

//go:generate ya tool mockgen -source=$GOFILE -destination=mocks/tvm.gen.go Client

import (
	"context"
	"fmt"
)

type ClientStatus int

// This constants must be in sync with EStatus from library/cpp/tvmauth/client/client_status.h
const (
	ClientOK ClientStatus = iota
	ClientWarning
	ClientError
)

func (s ClientStatus) String() string {
	switch s {
	case ClientOK:
		return "OK"
	case ClientWarning:
		return "Warning"
	case ClientError:
		return "Error"
	default:
		return fmt.Sprintf("Unknown%d", s)
	}
}

type ClientStatusInfo struct {
	Status ClientStatus

	// This message allows to trigger alert with useful message
	// It returns "OK" if Status==Ok
	LastError string
}

// Client allows to use aliases for ClientID.
//
// Alias is local label for ClientID which can be used to avoid this number in every checking case in code.
type Client interface {
	GetServiceTicketForAlias(ctx context.Context, alias string) (string, error)
	GetServiceTicketForID(ctx context.Context, dstID ClientID) (string, error)

	// CheckServiceTicket returns struct with SrcID: you should check it by yourself with ACL
	CheckServiceTicket(ctx context.Context, ticket string) (*CheckedServiceTicket, error)
	CheckUserTicket(ctx context.Context, ticket string, opts ...CheckUserTicketOption) (*CheckedUserTicket, error)
	GetRoles(ctx context.Context) (*Roles, error)

	// GetStatus returns current status of client:
	//  * you should trigger your monitoring if status is not Ok
	//  * it will be unable to operate if status is Invalid
	GetStatus(ctx context.Context) (ClientStatusInfo, error)
}

// Dynamic client allows to add dsts dynamically
type DynamicClient interface {
	Client

	GetOptionalServiceTicketForID(ctx context.Context, dstID ClientID) (*string, error)
	AddDsts(ctx context.Context, dsts []ClientID) error
}