yql_credentials.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <util/generic/string.h>
  3. #include <util/generic/strbuf.h>
  4. #include <util/generic/ptr.h>
  5. #include <util/generic/hash.h>
  6. #include <functional>
  7. #include <unordered_set>
  8. namespace NYql {
  9. struct TCredential {
  10. const TString Category;
  11. const TString Subcategory;
  12. const TString Content;
  13. TCredential(const TString& category, const TString& subcategory, const TString& content)
  14. : Category(category)
  15. , Subcategory(subcategory)
  16. , Content(content)
  17. {
  18. }
  19. };
  20. struct TUserCredentials {
  21. TString OauthToken;
  22. TString BlackboxSessionIdCookie;
  23. };
  24. class TCredentials: public TThrRefBase {
  25. public:
  26. using TPtr = TIntrusivePtr<TCredentials>;
  27. TCredentials() = default;
  28. ~TCredentials() = default;
  29. void AddCredential(const TString& alias, const TCredential& cred);
  30. void SetUserCredentials(const TUserCredentials& userCredentials) {
  31. UserCredentials_ = userCredentials;
  32. }
  33. void SetGroups(std::unordered_set<TString>&& groups) {
  34. Groups_ = std::move(groups);
  35. }
  36. const std::unordered_set<TString>& GetGroups() const {
  37. return Groups_;
  38. }
  39. const TCredential* FindCredential(const TStringBuf& name) const;
  40. TString FindCredentialContent(const TStringBuf& name1, const TStringBuf& name2, const TString& defaultContent) const;
  41. const TUserCredentials& GetUserCredentials() const {
  42. return UserCredentials_;
  43. }
  44. void ForEach(const std::function<void(const TString, const TCredential&)>& callback) const;
  45. private:
  46. THashMap<TString, TCredential> CredentialTable_;
  47. TUserCredentials UserCredentials_;
  48. std::unordered_set<TString> Groups_;
  49. };
  50. } // namespace NYql