azure-data-tables
Loading...
Searching...
No Matches
account_sas_builder.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "azure/data/tables/credentials/named_key_credential.hpp"
8
9#include <azure/core/datetime.hpp>
10#include <azure/core/nullable.hpp>
11
12#include <string>
13
14namespace Azure { namespace Data { namespace Tables { namespace Sas {
15 constexpr const char* HttpsAndHttp = "https,http";
16 constexpr const char* HttpsOnly = "https";
21 enum class SasProtocol
22 {
26 HttpsAndHttp,
27
31 HttpsOnly,
32 };
33
34 namespace _detail {
35 inline std::string SasProtocolToString(SasProtocol protocol)
36 {
37 return protocol == SasProtocol::HttpsAndHttp ? HttpsAndHttp : HttpsOnly;
38 }
39 } // namespace _detail
40
45 enum class AccountSasResourceType
46 {
51 Service = 1,
52
57 Container = 2,
58
63 Object = 4,
64
69 All = ~0,
70 };
71
75 enum class AccountSasServices
76 {
81 Table = 1,
86 All = ~0,
87 };
88
92 enum class AccountSasPermissions
93 {
97 Read = 1,
98
102 Write = 2,
103
107 Delete = 4,
108
112 Add = 8,
113
117 List = 16,
118
122 Update = 32,
123
127 All = ~0,
128 };
129
134 class AccountSasBuilder final {
135 public:
140 SasProtocol Protocol = SasProtocol::HttpsOnly;
141
146 Azure::Nullable<Azure::DateTime> StartsOn;
147
152 Azure::DateTime ExpiresOn;
153
160 Azure::Nullable<std::string> IPRange;
161
166 AccountSasServices Services;
167
172 AccountSasResourceType ResourceTypes;
173
177 std::string EncryptionScope;
178
185 void SetPermissions(AccountSasPermissions permissions);
186
192 void SetPermissions(std::string rawPermissions) { Permissions = std::move(rawPermissions); }
193
201 std::string GenerateSasToken(
203
204 private:
205 std::string Permissions;
206 };
207}}}} // namespace Azure::Data::Tables::Sas
A NamedKeyCredential is a credential backed by an account's name and one of its access keys.
Definition named_key_credential.hpp:26
AccountSasBuilder is used to generate an account level Shared Access Signature (SAS) for Azure Storag...
Definition account_sas_builder.hpp:134
AccountSasResourceType ResourceTypes
Definition account_sas_builder.hpp:172
AccountSasServices Services
The services associated with the shared access signature. The user is restricted to operations with t...
Definition account_sas_builder.hpp:166
Azure::Nullable< Azure::DateTime > StartsOn
Optionally specify the time at which the shared access signature becomes valid.
Definition account_sas_builder.hpp:146
SasProtocol Protocol
The optional signed protocol field specifies the protocol permitted for a request made with the SAS.
Definition account_sas_builder.hpp:140
std::string GenerateSasToken(const Azure::Data::Tables::Credentials::NamedKeyCredential &credential)
Uses the NamedKeyCredential to sign this shared access signature, to produce the proper SAS query par...
Definition account_sas_builder.cpp:46
Azure::Nullable< std::string > IPRange
Specifies an IP address or a range of IP addresses from which to accept requests. If the IP address f...
Definition account_sas_builder.hpp:160
std::string EncryptionScope
Optional encryption scope to use when sending requests authorized with this SAS url.
Definition account_sas_builder.hpp:177
Azure::DateTime ExpiresOn
The time at which the shared access signature becomes invalid. This field must be omitted if it has b...
Definition account_sas_builder.hpp:152
void SetPermissions(AccountSasPermissions permissions)
Sets the permissions for an account SAS.
Definition account_sas_builder.cpp:17
void SetPermissions(std::string rawPermissions)
Sets the permissions for the SAS using a raw permissions string.
Definition account_sas_builder.hpp:192
Defines bitwise operators for enums.