aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/yandex/tvm/tvmtool/examples/get_service_ticket/main.go
blob: 90e12f35c40ba3d3c29b724a9fe9e825cc5e5512 (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
package main

import (
	"context"
	"flag"
	"fmt"
	"os"

	"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/tvmtool"
)

var (
	baseURI = "http://localhost:3000"
	dst     = "dst"
)

func main() {
	flag.StringVar(&baseURI, "tool-uri", baseURI, "TVM tool uri")
	flag.StringVar(&dst, "dst", dst, "Destination TVM app (must be configured in tvm-tool)")
	flag.Parse()

	zlog, err := zap.New(zap.ConsoleConfig(log.DebugLevel))
	if err != nil {
		panic(err)
	}

	auth := os.Getenv("TVMTOOL_LOCAL_AUTHTOKEN")
	if auth == "" {
		zlog.Fatal("Please provide tvm-tool auth in env[TVMTOOL_LOCAL_AUTHTOKEN]")
		return
	}

	tvmClient, err := tvmtool.NewClient(
		baseURI,
		tvmtool.WithAuthToken(auth),
		tvmtool.WithLogger(zlog),
	)
	if err != nil {
		zlog.Fatal("failed create tvm client", log.Error(err))
		return
	}
	defer tvmClient.Close()

	ticket, err := tvmClient.GetServiceTicketForAlias(context.Background(), dst)
	if err != nil {
		zlog.Fatal("failed to get tvm ticket", log.String("dst", dst), log.Error(err))
		return
	}

	fmt.Printf("ticket: %s\n", ticket)
}