Loading [MathJax]/extensions/tex2jax.js
azure-storage-blobs
All Classes Functions Variables Pages
blob_sas_builder.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "azure/storage/blobs/blob_responses.hpp"
7
8#include <azure/storage/common/account_sas_builder.hpp>
9
10#include <string>
11
12namespace Azure { namespace Storage { namespace Sas {
13
17 enum class BlobSasResource
18 {
23 BlobContainer,
24
28 Blob,
29
34 BlobSnapshot,
35
40 BlobVersion,
41 };
42
46 enum class BlobContainerSasPermissions
47 {
51 Read = 1,
52
56 Write = 2,
57
61 Delete = 4,
62
66 List = 8,
67
71 Add = 16,
72
76 Create = 32,
77
81 Tags = 64,
82
86 DeleteVersion = 128,
87
91 SetImmutabilityPolicy = 256,
92
96 PermanentDelete = 512,
97
101 All = ~0,
102 };
103
104 inline BlobContainerSasPermissions operator|(
105 BlobContainerSasPermissions lhs,
106 BlobContainerSasPermissions rhs)
107 {
108 using type = std::underlying_type_t<BlobContainerSasPermissions>;
109 return static_cast<BlobContainerSasPermissions>(
110 static_cast<type>(lhs) | static_cast<type>(rhs));
111 }
112
113 inline BlobContainerSasPermissions operator&(
114 BlobContainerSasPermissions lhs,
115 BlobContainerSasPermissions rhs)
116 {
117 using type = std::underlying_type_t<BlobContainerSasPermissions>;
118 return static_cast<BlobContainerSasPermissions>(
119 static_cast<type>(lhs) & static_cast<type>(rhs));
120 }
121
125 enum class BlobSasPermissions
126 {
130 Read = 1,
131
135 Write = 2,
136
141 Delete = 4,
142
146 Add = 8,
147
151 Create = 16,
152
156 Tags = 32,
157
161 DeleteVersion = 64,
162
166 SetImmutabilityPolicy = 128,
167
171 PermanentDelete = 256,
172
176 All = ~0,
177 };
178
179 inline BlobSasPermissions operator|(BlobSasPermissions lhs, BlobSasPermissions rhs)
180 {
181 using type = std::underlying_type_t<BlobSasPermissions>;
182 return static_cast<BlobSasPermissions>(static_cast<type>(lhs) | static_cast<type>(rhs));
183 }
184
185 inline BlobSasPermissions operator&(BlobSasPermissions lhs, BlobSasPermissions rhs)
186 {
187 using type = std::underlying_type_t<BlobSasPermissions>;
188 return static_cast<BlobSasPermissions>(static_cast<type>(lhs) & static_cast<type>(rhs));
189 }
190
195 struct BlobSasBuilder final
196 {
201 SasProtocol Protocol;
202
207 Azure::Nullable<Azure::DateTime> StartsOn;
208
214 Azure::DateTime ExpiresOn;
215
222 Azure::Nullable<std::string> IPRange;
223
228 std::string Identifier;
229
233 std::string BlobContainerName;
234
238 std::string BlobName;
239
244 std::string Snapshot;
245
250 std::string BlobVersionId;
251
255 BlobSasResource Resource;
256
260 std::string CacheControl;
261
266
270 std::string ContentEncoding;
271
275 std::string ContentLanguage;
276
280 std::string ContentType;
281
285 std::string EncryptionScope;
286
292 void SetPermissions(BlobContainerSasPermissions permissions);
293
299 void SetPermissions(BlobSasPermissions permissions);
300
306 void SetPermissions(std::string rawPermissions) { Permissions = std::move(rawPermissions); }
307
315 std::string GenerateSasToken(const StorageSharedKeyCredential& credential);
316
326 std::string GenerateSasToken(
327 const Blobs::Models::UserDelegationKey& userDelegationKey,
328 const std::string& accountName);
329
338 std::string GenerateSasStringToSign(const StorageSharedKeyCredential& credential);
339
349 std::string GenerateSasStringToSign(
350 const Blobs::Models::UserDelegationKey& userDelegationKey,
351 const std::string& accountName);
352
353 private:
354 std::string Permissions;
355 };
356
357}}} // namespace Azure::Storage::Sas
A user delegation key.
Definition rest_client.hpp:511
BlobSasBuilder is used to generate a Shared Access Signature (SAS) for an Azure Storage container or ...
Definition blob_sas_builder.hpp:196
void SetPermissions(std::string rawPermissions)
Sets the permissions for the SAS using a raw permissions string.
Definition blob_sas_builder.hpp:306
std::string Snapshot
The name of the blob snapshot being made accessible, or empty for a container SAS and blob SAS.
Definition blob_sas_builder.hpp:244
Azure::Nullable< Azure::DateTime > StartsOn
Optionally specify the time at which the shared access signature becomes valid. This timestamp will b...
Definition blob_sas_builder.hpp:207
void SetPermissions(BlobContainerSasPermissions permissions)
Sets the permissions for the blob container SAS.
Definition blob_sas_builder.cpp:41
std::string BlobName
The name of the blob being made accessible, or empty for a container SAS..
Definition blob_sas_builder.hpp:238
SasProtocol Protocol
The optional signed protocol field specifies the protocol permitted for a request made with the SAS.
Definition blob_sas_builder.hpp:201
std::string CacheControl
Override the value returned for Cache-Control response header..
Definition blob_sas_builder.hpp:260
std::string Identifier
An optional unique value up to 64 characters in length that correlates to an access policy specified ...
Definition blob_sas_builder.hpp:228
std::string ContentType
Override the value returned for Content-Type response header..
Definition blob_sas_builder.hpp:280
Azure::DateTime ExpiresOn
The time at which the shared access signature becomes invalid. This field must be omitted if it has b...
Definition blob_sas_builder.hpp:214
std::string GenerateSasStringToSign(const StorageSharedKeyCredential &credential)
For debugging purposes only.
Definition blob_sas_builder.cpp:326
std::string ContentLanguage
Override the value returned for Content-Language response header..
Definition blob_sas_builder.hpp:275
std::string GenerateSasToken(const StorageSharedKeyCredential &credential)
Uses the StorageSharedKeyCredential to sign this shared access signature, to produce the proper SAS q...
Definition blob_sas_builder.cpp:133
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 blob_sas_builder.hpp:222
std::string ContentDisposition
Override the value returned for Content-Disposition response header..
Definition blob_sas_builder.hpp:265
BlobSasResource Resource
Specifies which resources are accessible via the shared access signature.
Definition blob_sas_builder.hpp:255
std::string ContentEncoding
Override the value returned for Content-Encoding response header..
Definition blob_sas_builder.hpp:270
std::string EncryptionScope
Optional encryption scope to use when sending requests authorized with this SAS url.
Definition blob_sas_builder.hpp:285
std::string BlobVersionId
The ID of the blob version being made accessible, or empty for a container SAS, blob SAS and blob sna...
Definition blob_sas_builder.hpp:250
std::string BlobContainerName
The name of the blob container being made accessible.
Definition blob_sas_builder.hpp:233