aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/yandex/tvm/tvmtool/qloud.go
blob: 4dcf0648dbee42a32087a958ced15287f03eac51 (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
package tvmtool

import (
	"fmt"
	"os"
)

const (
	QloudEndpointEnvKey  = "QLOUD_TVM_INTERFACE_ORIGIN"
	QloudTokenEnvKey     = "QLOUD_TVM_TOKEN"
	QloudDefaultEndpoint = "http://localhost:1"
)

// NewQloudClient method creates a new tvmtool client for Qloud environment.
// You must reuse it to prevent connection/goroutines leakage.
func NewQloudClient(opts ...Option) (*Client, error) {
	baseURI := os.Getenv(QloudEndpointEnvKey)
	if baseURI == "" {
		baseURI = QloudDefaultEndpoint
	}

	authToken := os.Getenv(QloudTokenEnvKey)
	if authToken == "" {
		return nil, fmt.Errorf("empty auth token (looked at ENV[%s])", QloudTokenEnvKey)
	}

	opts = append([]Option{WithAuthToken(authToken)}, opts...)
	return NewClient(
		baseURI,
		opts...,
	)
}