aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/misc/tool/settings.cpp
blob: 894501f19d22307da7337953f27b46acd7ce7d38 (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
#include "settings.h"

#include <library/cpp/string_utils/url/url.h>

#include <util/system/env.h>

namespace NTvmAuth::NTvmTool {
    TClientSettings::TClientSettings(const TAlias& selfAias)
        : SelfAias_(selfAias)
        , Hostname_("localhost")
        , Port_(1)
        , SocketTimeout_(TDuration::Seconds(5))
        , ConnectTimeout_(TDuration::Seconds(30))
    {
        AuthToken_ = GetEnv("TVMTOOL_LOCAL_AUTHTOKEN");
        if (!AuthToken_) {
            AuthToken_ = GetEnv("QLOUD_TVM_TOKEN");
        }
        TStringBuf auth(AuthToken_);
        FixSpaces(auth);
        AuthToken_ = auth;

        const TString url = GetEnv("DEPLOY_TVM_TOOL_URL");
        if (url) {
            TStringBuf scheme, host;
            TryGetSchemeHostAndPort(url, scheme, host, Port_);
        }

        Y_ENSURE_EX(SelfAias_, TBrokenTvmClientSettings() << "Alias for your TVM client cannot be empty");
    }

    void TClientSettings::FixSpaces(TStringBuf& str) {
        while (str && isspace(str.back())) {
            str.Chop(1);
        }
    }
}