aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/credentials/yql_credentials.h
blob: e076aff12cffdfd73d0f885b9211051885a6c223 (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
65
#pragma once

#include <util/generic/string.h>
#include <util/generic/strbuf.h>
#include <util/generic/ptr.h>
#include <util/generic/hash.h>

#include <functional>
#include <unordered_set>

namespace NYql {

struct TCredential {
    const TString Category;
    const TString Subcategory;
    const TString Content;

    TCredential(const TString& category, const TString& subcategory, const TString& content)
        : Category(category)
        , Subcategory(subcategory)
        , Content(content)
    {
    }
};

struct TUserCredentials {
    TString OauthToken;
    TString BlackboxSessionIdCookie;
};

class TCredentials: public TThrRefBase {
public:
    using TPtr = TIntrusivePtr<TCredentials>;

    TCredentials() = default;
    ~TCredentials() = default;

    void AddCredential(const TString& alias, const TCredential& cred);
    void SetUserCredentials(const TUserCredentials& userCredentials) {
        UserCredentials_ = userCredentials;
    }
    
    void SetGroups(std::unordered_set<TString>&& groups) {
        Groups_ = std::move(groups);
    }

    const std::unordered_set<TString>& GetGroups() const {
        return Groups_;
    }

    const TCredential* FindCredential(const TStringBuf& name) const;
    TString FindCredentialContent(const TStringBuf& name1, const TStringBuf& name2, const TString& defaultContent) const;

    const TUserCredentials& GetUserCredentials() const  {
        return UserCredentials_;
    }
    void ForEach(const std::function<void(const TString, const TCredential&)>& callback) const;

private:
    THashMap<TString, TCredential> CredentialTable_;
    TUserCredentials UserCredentials_;
    std::unordered_set<TString> Groups_;
};

} // namespace NYql