credential_client.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <memory>
  3. #include <string>
  4. #include <vector>
  5. #include <grpcpp/grpcpp.h>
  6. #include "proto/credentials.grpc.pb.h"
  7. #include "credential_types.hpp"
  8. #include "common/error.hpp"
  9. namespace smartbotic::credentials {
  10. // Configuration for credential client
  11. struct CredentialClientConfig {
  12. std::string address = "localhost:9013"; // Credential service address
  13. int timeout_ms = 5000;
  14. };
  15. // gRPC client for credential service
  16. class CredentialClient {
  17. public:
  18. explicit CredentialClient(const CredentialClientConfig& config);
  19. ~CredentialClient() = default;
  20. // Get HTTP authentication header for a credential
  21. common::Result<HttpAuth> getHttpAuth(const std::string& credential_id,
  22. const std::string& workflow_id = "");
  23. // Get IMAP credentials
  24. common::Result<ImapData> getImapCredentials(const std::string& credential_id,
  25. const std::string& workflow_id = "");
  26. // The mTLS identity a workflow presents. The private key comes back over
  27. // this call and is held in memory for the length of the run, never written
  28. // anywhere.
  29. common::Result<ClientCertificateData> getClientCertificate(const std::string& credential_id,
  30. const std::string& workflow_id = "");
  31. // Also satisfied by an imap credential for the same account.
  32. common::Result<SmtpData> getSmtpCredentials(const std::string& credential_id,
  33. const std::string& workflow_id = "");
  34. // Get MySQL credentials
  35. common::Result<MysqlData> getMysqlCredentials(const std::string& credential_id,
  36. const std::string& workflow_id = "");
  37. // Get PostgreSQL credentials
  38. common::Result<PostgresqlData> getPostgresqlCredentials(const std::string& credential_id,
  39. const std::string& workflow_id = "");
  40. // List available credentials
  41. common::Result<std::vector<CredentialInfo>> listCredentials(const std::string& workflow_id = "");
  42. // Check if connected
  43. bool isConnected() const;
  44. private:
  45. CredentialClientConfig config_;
  46. std::shared_ptr<grpc::Channel> channel_;
  47. std::unique_ptr<proto::CredentialService::Stub> stub_;
  48. };
  49. } // namespace smartbotic::credentials