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
65
66
67
68
69
70
71
|
package tvmtool_test
import (
"context"
"fmt"
"github.com/ydb-platform/ydb/library/go/core/log"
"github.com/ydb-platform/ydb/library/go/core/log/zap"
"github.com/ydb-platform/ydb/library/go/yandex/tvm"
"github.com/ydb-platform/ydb/library/go/yandex/tvm/tvmtool"
)
func ExampleNewQloudClient_simple() {
zlog, err := zap.New(zap.ConsoleConfig(log.DebugLevel))
if err != nil {
panic(err)
}
tvmClient, err := tvmtool.NewQloudClient(tvmtool.WithLogger(zlog))
if err != nil {
panic(err)
}
ticket, err := tvmClient.GetServiceTicketForAlias(context.Background(), "black-box")
if err != nil {
retryable := false
if tvmErr, ok := err.(*tvm.Error); ok {
retryable = tvmErr.Retriable
}
zlog.Fatal(
"failed to get service ticket",
log.String("alias", "black-box"),
log.Error(err),
log.Bool("retryable", retryable),
)
}
fmt.Printf("ticket: %s\n", ticket)
}
func ExampleNewQloudClient_custom() {
zlog, err := zap.New(zap.ConsoleConfig(log.DebugLevel))
if err != nil {
panic(err)
}
tvmClient, err := tvmtool.NewQloudClient(
tvmtool.WithSrc("second_app"),
tvmtool.WithOverrideEnv(tvm.BlackboxProd),
tvmtool.WithLogger(zlog),
)
if err != nil {
panic(err)
}
ticket, err := tvmClient.GetServiceTicketForAlias(context.Background(), "black-box")
if err != nil {
retryable := false
if tvmErr, ok := err.(*tvm.Error); ok {
retryable = tvmErr.Retriable
}
zlog.Fatal(
"failed to get service ticket",
log.String("alias", "black-box"),
log.Error(err),
log.Bool("retryable", retryable),
)
}
fmt.Printf("ticket: %s\n", ticket)
}
|