azure-storage-blobs
blob_rest_client.hpp
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
4 #pragma once
5 
6 #include <cstring>
7 #include <limits>
8 #include <map>
9 #include <set>
10 #include <stdexcept>
11 #include <string>
12 #include <type_traits>
13 #include <vector>
14 
15 #include <azure/core/context.hpp>
16 #include <azure/core/datetime.hpp>
17 #include <azure/core/etag.hpp>
18 #include <azure/core/http/http.hpp>
19 #include <azure/core/internal/http/pipeline.hpp>
20 #include <azure/core/internal/strings.hpp>
21 #include <azure/core/nullable.hpp>
22 #include <azure/core/response.hpp>
23 #include <azure/storage/common/crypt.hpp>
24 #include <azure/storage/common/internal/xml_wrapper.hpp>
25 #include <azure/storage/common/storage_common.hpp>
26 #include <azure/storage/common/storage_exception.hpp>
27 
29 
30 namespace Azure { namespace Storage { namespace Blobs {
31 
32  namespace _detail {
33  constexpr static const char* ApiVersion = "2020-02-10";
34  } // namespace _detail
35 
36  namespace Models {
37 
41  class AccountKind final {
42  public:
43  AccountKind() = default;
44  explicit AccountKind(std::string value) : m_value(std::move(value)) {}
45  bool operator==(const AccountKind& other) const { return m_value == other.m_value; }
46  bool operator!=(const AccountKind& other) const { return !(*this == other); }
47  const std::string& ToString() const { return m_value; }
68 
69  private:
70  std::string m_value;
71  }; // extensible enum AccountKind
72 
76  struct BlobBlock final
77  {
81  std::string Name;
85  int64_t Size = 0;
86  }; // struct BlobBlock
87 
91  class CopyStatus final {
92  public:
93  CopyStatus() = default;
94  explicit CopyStatus(std::string value) : m_value(std::move(value)) {}
95  bool operator==(const CopyStatus& other) const { return m_value == other.m_value; }
96  bool operator!=(const CopyStatus& other) const { return !(*this == other); }
97  const std::string& ToString() const { return m_value; }
106 
107  private:
108  std::string m_value;
109  }; // extensible enum CopyStatus
110 
114  class GeoReplicationStatus final {
115  public:
116  GeoReplicationStatus() = default;
117  explicit GeoReplicationStatus(std::string value) : m_value(std::move(value)) {}
118  bool operator==(const GeoReplicationStatus& other) const { return m_value == other.m_value; }
119  bool operator!=(const GeoReplicationStatus& other) const { return !(*this == other); }
120  const std::string& ToString() const { return m_value; }
133 
134  private:
135  std::string m_value;
136  }; // extensible enum GeoReplicationStatus
137 
141  class LeaseDurationType final {
142  public:
143  LeaseDurationType() = default;
144  explicit LeaseDurationType(std::string value) : m_value(std::move(value)) {}
145  bool operator==(const LeaseDurationType& other) const { return m_value == other.m_value; }
146  bool operator!=(const LeaseDurationType& other) const { return !(*this == other); }
147  const std::string& ToString() const { return m_value; }
156 
157  private:
158  std::string m_value;
159  }; // extensible enum LeaseDurationType
160 
164  class LeaseState final {
165  public:
166  LeaseState() = default;
167  explicit LeaseState(std::string value) : m_value(std::move(value)) {}
168  bool operator==(const LeaseState& other) const { return m_value == other.m_value; }
169  bool operator!=(const LeaseState& other) const { return !(*this == other); }
170  const std::string& ToString() const { return m_value; }
192 
193  private:
194  std::string m_value;
195  }; // extensible enum LeaseState
196 
200  class LeaseStatus final {
201  public:
202  LeaseStatus() = default;
203  explicit LeaseStatus(std::string value) : m_value(std::move(value)) {}
204  bool operator==(const LeaseStatus& other) const { return m_value == other.m_value; }
205  bool operator!=(const LeaseStatus& other) const { return !(*this == other); }
206  const std::string& ToString() const { return m_value; }
215 
216  private:
217  std::string m_value;
218  }; // extensible enum LeaseStatus
219 
224  public:
225  ObjectReplicationStatus() = default;
226  explicit ObjectReplicationStatus(std::string value) : m_value(std::move(value)) {}
227  bool operator==(const ObjectReplicationStatus& other) const
228  {
229  return m_value == other.m_value;
230  }
231  bool operator!=(const ObjectReplicationStatus& other) const { return !(*this == other); }
232  const std::string& ToString() const { return m_value; }
241 
242  private:
243  std::string m_value;
244  }; // extensible enum ObjectReplicationStatus
245 
250  class PublicAccessType final {
251  public:
252  PublicAccessType() = default;
253  explicit PublicAccessType(std::string value) : m_value(std::move(value)) {}
254  bool operator==(const PublicAccessType& other) const { return m_value == other.m_value; }
255  bool operator!=(const PublicAccessType& other) const { return !(*this == other); }
256  const std::string& ToString() const { return m_value; }
273 
274  private:
275  std::string m_value;
276  }; // extensible enum PublicAccessType
277 
281  struct RetentionPolicy final
282  {
286  bool IsEnabled = false;
291  Azure::Nullable<int32_t> Days;
292  }; // struct RetentionPolicy
293 
297  struct SignedIdentifier final
298  {
302  std::string Id;
306  Azure::DateTime StartsOn;
310  Azure::DateTime ExpiresOn;
314  std::string Permissions;
315  }; // struct SignedIdentifier
316 
320  class SkuName final {
321  public:
322  SkuName() = default;
323  explicit SkuName(std::string value) : m_value(std::move(value)) {}
324  bool operator==(const SkuName& other) const { return m_value == other.m_value; }
325  bool operator!=(const SkuName& other) const { return !(*this == other); }
326  const std::string& ToString() const { return m_value; }
359 
360  private:
361  std::string m_value;
362  }; // extensible enum SkuName
363 
368  struct TaggedBlobItem final
369  {
373  std::string BlobName;
377  std::string BlobContainerName;
378  }; // struct TaggedBlobItem
379 
383  struct AnalyticsLogging final
384  {
388  std::string Version;
392  bool Delete = false;
396  bool Read = false;
400  bool Write = false;
405  }; // struct AnalyticsLogging
406 
411  {
415  Azure::ETag ETag;
421  Azure::DateTime LastModified;
425  Storage::Metadata Metadata;
433  bool HasImmutabilityPolicy = false;
437  bool HasLegalHold = false;
442  Azure::Nullable<LeaseDurationType> LeaseDuration;
463  Azure::Nullable<int32_t> RemainingRetentionDays;
468  Azure::Nullable<Azure::DateTime> DeletedOn;
469  }; // struct BlobContainerItemDetails
470 
474  struct CorsRule final
475  {
480  std::string AllowedOrigins;
485  std::string AllowedMethods;
489  std::string AllowedHeaders;
493  std::string ExposedHeaders;
497  int32_t MaxAgeInSeconds = 0;
498  }; // struct CorsRule
499 
503  struct GeoReplication final
504  {
514  Azure::Nullable<Azure::DateTime> LastSyncedOn;
515  }; // struct GeoReplication
516 
520  struct Metrics final
521  {
525  std::string Version;
529  bool IsEnabled = false;
537  Azure::Nullable<bool> IncludeApis;
538  }; // struct Metrics
539 
544  {
548  std::string RuleId;
553  }; // struct ObjectReplicationRule
554 
558  struct StaticWebsite final
559  {
563  bool IsEnabled = false;
567  Azure::Nullable<std::string> IndexDocument;
571  Azure::Nullable<std::string> DefaultIndexDocumentPath;
575  Azure::Nullable<std::string> ErrorDocument404Path;
576  }; // struct StaticWebsite
577 
581  class AccessTier final {
582  public:
583  AccessTier() = default;
584  explicit AccessTier(std::string value) : m_value(std::move(value)) {}
585  bool operator==(const AccessTier& other) const { return m_value == other.m_value; }
586  bool operator!=(const AccessTier& other) const { return !(*this == other); }
587  const std::string& ToString() const { return m_value; }
657 
658  private:
659  std::string m_value;
660  }; // extensible enum AccessTier
661 
666  class ArchiveStatus final {
667  public:
668  ArchiveStatus() = default;
669  explicit ArchiveStatus(std::string value) : m_value(std::move(value)) {}
670  bool operator==(const ArchiveStatus& other) const { return m_value == other.m_value; }
671  bool operator!=(const ArchiveStatus& other) const { return !(*this == other); }
672  const std::string& ToString() const { return m_value; }
681 
682  private:
683  std::string m_value;
684  }; // extensible enum ArchiveStatus
685 
690  struct BlobContainerItem final
691  {
695  std::string Name;
699  bool IsDeleted = false;
703  Azure::Nullable<std::string> VersionId;
708  }; // struct BlobContainerItem
709 
713  struct BlobHttpHeaders final
714  {
718  std::string ContentType;
722  std::string ContentEncoding;
726  std::string ContentLanguage;
730  Storage::ContentHash ContentHash;
734  std::string CacheControl;
739  std::string ContentDisposition;
740  }; // struct BlobHttpHeaders
741 
745  class BlobType final {
746  public:
747  BlobType() = default;
748  explicit BlobType(std::string value) : m_value(std::move(value)) {}
749  bool operator==(const BlobType& other) const { return m_value == other.m_value; }
750  bool operator!=(const BlobType& other) const { return !(*this == other); }
751  const std::string& ToString() const { return m_value; }
764 
765  private:
766  std::string m_value;
767  }; // extensible enum BlobType
768 
776  {
780  std::string PolicyId;
784  std::vector<ObjectReplicationRule> Rules;
785  }; // struct ObjectReplicationPolicy
786 
790  class RehydratePriority final {
791  public:
792  RehydratePriority() = default;
793  explicit RehydratePriority(std::string value) : m_value(std::move(value)) {}
794  bool operator==(const RehydratePriority& other) const { return m_value == other.m_value; }
795  bool operator!=(const RehydratePriority& other) const { return !(*this == other); }
796  const std::string& ToString() const { return m_value; }
805 
806  private:
807  std::string m_value;
808  }; // extensible enum RehydratePriority
809 
813  struct BlobItemDetails final
814  {
822  Storage::Metadata Metadata;
826  Azure::DateTime CreatedOn;
830  Azure::Nullable<Azure::DateTime> ExpiresOn;
834  Azure::Nullable<Azure::DateTime> LastAccessedOn;
840  Azure::DateTime LastModified;
844  Azure::ETag ETag;
848  Azure::Nullable<Models::AccessTier> AccessTier;
852  Azure::Nullable<bool> IsAccessTierInferred;
865  Azure::Nullable<LeaseDurationType> LeaseDuration;
871  bool IsServerEncrypted = false;
875  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
879  Azure::Nullable<std::string> EncryptionScope;
884  Azure::Nullable<int64_t> SequenceNumber;
888  Azure::Nullable<bool> IsSealed;
892  std::vector<ObjectReplicationPolicy> ObjectReplicationSourceProperties;
893  }; // struct BlobItemDetails
894 
898  struct DownloadBlobDetails final
899  {
903  Azure::ETag ETag;
909  Azure::DateTime LastModified;
913  Azure::DateTime CreatedOn;
917  Azure::Nullable<Azure::DateTime> ExpiresOn;
921  Azure::Nullable<Azure::DateTime> LastAccessedOn;
929  Storage::Metadata Metadata;
934  Azure::Nullable<int64_t> SequenceNumber;
939  Azure::Nullable<int32_t> CommittedBlockCount;
943  Azure::Nullable<bool> IsSealed;
948  Azure::Nullable<LeaseDurationType> LeaseDuration;
952  Azure::Nullable<Models::LeaseState> LeaseState;
956  Azure::Nullable<Models::LeaseStatus> LeaseStatus;
962  bool IsServerEncrypted = false;
966  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
970  Azure::Nullable<std::string> EncryptionScope;
974  Azure::Nullable<std::string> ObjectReplicationDestinationPolicyId;
978  std::vector<ObjectReplicationPolicy> ObjectReplicationSourceProperties;
982  Azure::Nullable<int32_t> TagCount;
988  Azure::Nullable<std::string> CopyId;
995  Azure::Nullable<std::string> CopySource;
1002  Azure::Nullable<Models::CopyStatus> CopyStatus;
1007  Azure::Nullable<std::string> CopyStatusDescription;
1012  Azure::Nullable<std::string> CopyProgress;
1017  Azure::Nullable<Azure::DateTime> CopyCompletedOn;
1022  Azure::Nullable<std::string> VersionId;
1027  Azure::Nullable<bool> IsCurrentVersion;
1028  }; // struct DownloadBlobDetails
1029 
1033  struct BlobItem final
1034  {
1035  std::string Name;
1039  int64_t BlobSize = 0;
1047  bool IsDeleted = false;
1051  std::string Snapshot;
1056  Azure::Nullable<std::string> VersionId;
1061  Azure::Nullable<bool> IsCurrentVersion;
1066  }; // struct BlobItem
1067 
1072  {
1073  }; // struct AbortBlobCopyFromUriResult
1074 
1078  struct AccountInfo final
1079  {
1094  }; // struct AccountInfo
1095 
1100  {
1104  Azure::ETag ETag;
1110  Azure::DateTime LastModified;
1114  Azure::Nullable<ContentHash> TransactionalContentHash;
1118  int64_t AppendOffset = 0;
1123  int32_t CommittedBlockCount = 0;
1129  bool IsServerEncrypted = false;
1133  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1137  Azure::Nullable<std::string> EncryptionScope;
1138  }; // struct AppendBlockFromUriResult
1139 
1143  struct AppendBlockResult final
1144  {
1148  Azure::ETag ETag;
1154  Azure::DateTime LastModified;
1158  Azure::Nullable<ContentHash> TransactionalContentHash;
1162  int64_t AppendOffset = 0;
1167  int32_t CommittedBlockCount = 0;
1173  bool IsServerEncrypted = false;
1177  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1181  Azure::Nullable<std::string> EncryptionScope;
1182  }; // struct AppendBlockResult
1183 
1188  {
1196  std::vector<SignedIdentifier> SignedIdentifiers;
1197  }; // struct BlobContainerAccessPolicy
1198 
1203  {
1207  Azure::ETag ETag;
1213  Azure::DateTime LastModified;
1217  Storage::Metadata Metadata;
1229  bool HasLegalHold = false;
1234  Azure::Nullable<LeaseDurationType> LeaseDuration;
1251  }; // struct BlobContainerProperties
1252 
1256  struct BlobProperties final
1257  {
1261  Azure::ETag ETag;
1267  Azure::DateTime LastModified;
1271  Azure::DateTime CreatedOn;
1275  Azure::Nullable<Azure::DateTime> ExpiresOn;
1279  Azure::Nullable<Azure::DateTime> LastAccessedOn;
1283  Storage::Metadata Metadata;
1292  Azure::Nullable<LeaseDurationType> LeaseDuration;
1296  Azure::Nullable<Models::LeaseState> LeaseState;
1300  Azure::Nullable<Models::LeaseStatus> LeaseStatus;
1304  int64_t BlobSize = 0;
1313  Azure::Nullable<int64_t> SequenceNumber;
1318  Azure::Nullable<int32_t> CommittedBlockCount;
1322  Azure::Nullable<bool> IsSealed;
1328  bool IsServerEncrypted = false;
1332  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1336  Azure::Nullable<std::string> EncryptionScope;
1340  Azure::Nullable<Models::AccessTier> AccessTier;
1344  Azure::Nullable<bool> IsAccessTierInferred;
1348  Azure::Nullable<Models::ArchiveStatus> ArchiveStatus;
1352  Azure::Nullable<Models::RehydratePriority> RehydratePriority;
1356  Azure::Nullable<Azure::DateTime> AccessTierChangedOn;
1362  Azure::Nullable<std::string> CopyId;
1369  Azure::Nullable<std::string> CopySource;
1376  Azure::Nullable<Models::CopyStatus> CopyStatus;
1381  Azure::Nullable<std::string> CopyStatusDescription;
1385  Azure::Nullable<bool> IsIncrementalCopy;
1389  Azure::Nullable<std::string> IncrementalCopyDestinationSnapshot;
1394  Azure::Nullable<std::string> CopyProgress;
1399  Azure::Nullable<Azure::DateTime> CopyCompletedOn;
1403  Azure::Nullable<std::string> ObjectReplicationDestinationPolicyId;
1407  std::vector<ObjectReplicationPolicy> ObjectReplicationSourceProperties;
1411  Azure::Nullable<int32_t> TagCount;
1416  Azure::Nullable<std::string> VersionId;
1421  Azure::Nullable<bool> IsCurrentVersion;
1422  }; // struct BlobProperties
1423 
1428  {
1444  std::vector<CorsRule> Cors;
1449  Azure::Nullable<std::string> DefaultServiceVersion;
1458  }; // struct BlobServiceProperties
1459 
1463  class BlockListType final {
1464  public:
1465  BlockListType() = default;
1466  explicit BlockListType(std::string value) : m_value(std::move(value)) {}
1467  bool operator==(const BlockListType& other) const { return m_value == other.m_value; }
1468  bool operator!=(const BlockListType& other) const { return !(*this == other); }
1469  const std::string& ToString() const { return m_value; }
1482 
1483  private:
1484  std::string m_value;
1485  }; // extensible enum BlockListType
1486 
1490  class BlockType final {
1491  public:
1492  BlockType() = default;
1493  explicit BlockType(std::string value) : m_value(std::move(value)) {}
1494  bool operator==(const BlockType& other) const { return m_value == other.m_value; }
1495  bool operator!=(const BlockType& other) const { return !(*this == other); }
1496  const std::string& ToString() const { return m_value; }
1510 
1511  private:
1512  std::string m_value;
1513  }; // extensible enum BlockType
1514 
1518  struct ClearPagesResult final
1519  {
1523  Azure::ETag ETag;
1529  Azure::DateTime LastModified;
1534  int64_t SequenceNumber = 0;
1535  }; // struct ClearPagesResult
1536 
1541  {
1545  Azure::ETag ETag;
1551  Azure::DateTime LastModified;
1556  Azure::Nullable<std::string> VersionId;
1562  bool IsServerEncrypted = false;
1566  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1570  Azure::Nullable<std::string> EncryptionScope;
1574  Azure::Nullable<ContentHash> TransactionalContentHash;
1575  }; // struct CommitBlockListResult
1576 
1581  {
1585  bool Created = true;
1589  Azure::ETag ETag;
1595  Azure::DateTime LastModified;
1600  Azure::Nullable<std::string> VersionId;
1606  bool IsServerEncrypted = false;
1610  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1614  Azure::Nullable<std::string> EncryptionScope;
1615  }; // struct CreateAppendBlobResult
1616 
1621  {
1625  bool Created = true;
1629  Azure::ETag ETag;
1635  Azure::DateTime LastModified;
1636  }; // struct CreateBlobContainerResult
1637 
1642  {
1643  std::string Snapshot;
1647  Azure::ETag ETag;
1653  Azure::DateTime LastModified;
1658  Azure::Nullable<std::string> VersionId;
1664  bool IsServerEncrypted = false;
1668  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1672  Azure::Nullable<std::string> EncryptionScope;
1673  }; // struct CreateBlobSnapshotResult
1674 
1679  {
1683  bool Created = true;
1687  Azure::ETag ETag;
1693  Azure::DateTime LastModified;
1698  Azure::Nullable<std::string> VersionId;
1704  bool IsServerEncrypted = false;
1708  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
1712  Azure::Nullable<std::string> EncryptionScope;
1717  Azure::Nullable<int64_t> SequenceNumber;
1718  }; // struct CreatePageBlobResult
1719 
1724  {
1728  bool Deleted = true;
1729  }; // struct DeleteBlobContainerResult
1730 
1734  struct DeleteBlobResult final
1735  {
1739  bool Deleted = true;
1740  }; // struct DeleteBlobResult
1741 
1747  public:
1748  DeleteSnapshotsOption() = default;
1749  explicit DeleteSnapshotsOption(std::string value) : m_value(std::move(value)) {}
1750  bool operator==(const DeleteSnapshotsOption& other) const { return m_value == other.m_value; }
1751  bool operator!=(const DeleteSnapshotsOption& other) const { return !(*this == other); }
1752  const std::string& ToString() const { return m_value; }
1761 
1762  private:
1763  std::string m_value;
1764  }; // extensible enum DeleteSnapshotsOption
1765 
1769  struct DownloadBlobResult final
1770  {
1774  std::unique_ptr<Azure::Core::IO::BodyStream> BodyStream;
1778  Azure::Core::Http::HttpRange ContentRange;
1782  int64_t BlobSize = 0;
1790  Azure::Nullable<ContentHash> TransactionalContentHash;
1795  }; // struct DownloadBlobResult
1796 
1801  public:
1802  EncryptionAlgorithmType() = default;
1803  explicit EncryptionAlgorithmType(std::string value) : m_value(std::move(value)) {}
1804  bool operator==(const EncryptionAlgorithmType& other) const
1805  {
1806  return m_value == other.m_value;
1807  }
1808  bool operator!=(const EncryptionAlgorithmType& other) const { return !(*this == other); }
1809  const std::string& ToString() const { return m_value; }
1814 
1815  private:
1816  std::string m_value;
1817  }; // extensible enum EncryptionAlgorithmType
1818 
1822  struct GetBlockListResult final
1823  {
1827  Azure::ETag ETag;
1833  Azure::DateTime LastModified;
1837  int64_t BlobSize = 0;
1841  std::vector<BlobBlock> CommittedBlocks;
1845  std::vector<BlobBlock> UncommittedBlocks;
1846  }; // struct GetBlockListResult
1847 
1848  enum class ListBlobContainersIncludeFlags
1849  {
1853  None = 0,
1857  Metadata = 1,
1861  Deleted = 2,
1862  }; // bitwise enum ListBlobContainersIncludeFlags
1863 
1864  inline ListBlobContainersIncludeFlags operator|(
1865  ListBlobContainersIncludeFlags lhs,
1866  ListBlobContainersIncludeFlags rhs)
1867  {
1868  using type = std::underlying_type_t<ListBlobContainersIncludeFlags>;
1869  return static_cast<ListBlobContainersIncludeFlags>(
1870  static_cast<type>(lhs) | static_cast<type>(rhs));
1871  }
1872 
1873  inline ListBlobContainersIncludeFlags& operator|=(
1874  ListBlobContainersIncludeFlags& lhs,
1875  ListBlobContainersIncludeFlags rhs)
1876  {
1877  lhs = lhs | rhs;
1878  return lhs;
1879  }
1880 
1881  inline ListBlobContainersIncludeFlags operator&(
1882  ListBlobContainersIncludeFlags lhs,
1883  ListBlobContainersIncludeFlags rhs)
1884  {
1885  using type = std::underlying_type_t<ListBlobContainersIncludeFlags>;
1886  return static_cast<ListBlobContainersIncludeFlags>(
1887  static_cast<type>(lhs) & static_cast<type>(rhs));
1888  }
1889 
1890  inline ListBlobContainersIncludeFlags& operator&=(
1891  ListBlobContainersIncludeFlags& lhs,
1892  ListBlobContainersIncludeFlags rhs)
1893  {
1894  lhs = lhs & rhs;
1895  return lhs;
1896  }
1897 
1898  enum class ListBlobsIncludeFlags
1899  {
1903  None = 0,
1907  Copy = 1,
1911  Deleted = 2,
1915  Metadata = 4,
1919  Snapshots = 8,
1923  Versions = 16,
1927  UncomittedBlobs = 32,
1928  }; // bitwise enum ListBlobsIncludeFlags
1929 
1930  inline ListBlobsIncludeFlags operator|(ListBlobsIncludeFlags lhs, ListBlobsIncludeFlags rhs)
1931  {
1932  using type = std::underlying_type_t<ListBlobsIncludeFlags>;
1933  return static_cast<ListBlobsIncludeFlags>(static_cast<type>(lhs) | static_cast<type>(rhs));
1934  }
1935 
1936  inline ListBlobsIncludeFlags& operator|=(ListBlobsIncludeFlags& lhs, ListBlobsIncludeFlags rhs)
1937  {
1938  lhs = lhs | rhs;
1939  return lhs;
1940  }
1941 
1942  inline ListBlobsIncludeFlags operator&(ListBlobsIncludeFlags lhs, ListBlobsIncludeFlags rhs)
1943  {
1944  using type = std::underlying_type_t<ListBlobsIncludeFlags>;
1945  return static_cast<ListBlobsIncludeFlags>(static_cast<type>(lhs) & static_cast<type>(rhs));
1946  }
1947 
1948  inline ListBlobsIncludeFlags& operator&=(ListBlobsIncludeFlags& lhs, ListBlobsIncludeFlags rhs)
1949  {
1950  lhs = lhs & rhs;
1951  return lhs;
1952  }
1953 
1958  {
1962  Azure::ETag ETag;
1968  Azure::DateTime LastModified;
1973  int64_t SequenceNumber = 0;
1974  }; // struct ResizePageBlobResult
1975 
1980  public:
1981  ScheduleBlobExpiryOriginType() = default;
1982  explicit ScheduleBlobExpiryOriginType(std::string value) : m_value(std::move(value)) {}
1983  bool operator==(const ScheduleBlobExpiryOriginType& other) const
1984  {
1985  return m_value == other.m_value;
1986  }
1987  bool operator!=(const ScheduleBlobExpiryOriginType& other) const { return !(*this == other); }
1988  const std::string& ToString() const { return m_value; }
2005 
2006  private:
2007  std::string m_value;
2008  }; // extensible enum ScheduleBlobExpiryOriginType
2009 
2014  {
2018  Azure::ETag ETag;
2024  Azure::DateTime LastModified;
2028  bool IsSealed = true;
2029  }; // struct SealAppendBlobResult
2030 
2034  struct ServiceStatistics final
2035  {
2040  }; // struct ServiceStatistics
2041 
2046  {
2047  }; // struct SetBlobAccessTierResult
2048 
2053  {
2057  Azure::ETag ETag;
2063  Azure::DateTime LastModified;
2064  }; // struct SetBlobContainerAccessPolicyResult
2065 
2070  {
2074  Azure::ETag ETag;
2080  Azure::DateTime LastModified;
2081  }; // struct SetBlobContainerMetadataResult
2082 
2087  struct SetBlobExpiryResult final
2088  {
2089  }; // struct SetBlobExpiryResult
2090 
2095  {
2099  Azure::ETag ETag;
2105  Azure::DateTime LastModified;
2110  Azure::Nullable<int64_t> SequenceNumber;
2111  }; // struct SetBlobHttpHeadersResult
2112 
2117  {
2121  Azure::ETag ETag;
2127  Azure::DateTime LastModified;
2132  Azure::Nullable<int64_t> SequenceNumber;
2133  }; // struct SetBlobMetadataResult
2134 
2138  struct SetBlobTagsResult final
2139  {
2140  }; // struct SetBlobTagsResult
2141 
2146  {
2147  }; // struct SetServicePropertiesResult
2148 
2153  {
2157  Azure::Nullable<ContentHash> TransactionalContentHash;
2163  bool IsServerEncrypted = false;
2167  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
2171  Azure::Nullable<std::string> EncryptionScope;
2172  }; // struct StageBlockFromUriResult
2173 
2177  struct StageBlockResult final
2178  {
2182  Azure::Nullable<ContentHash> TransactionalContentHash;
2188  bool IsServerEncrypted = false;
2192  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
2196  Azure::Nullable<std::string> EncryptionScope;
2197  }; // struct StageBlockResult
2198 
2202  struct UndeleteBlobResult final
2203  {
2204  }; // struct UndeleteBlobResult
2205 
2210  {
2214  Azure::ETag ETag;
2220  Azure::DateTime LastModified;
2225  Azure::Nullable<std::string> VersionId;
2231  bool IsServerEncrypted = false;
2235  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
2239  Azure::Nullable<std::string> EncryptionScope;
2243  Azure::Nullable<ContentHash> TransactionalContentHash;
2244  }; // struct UploadBlockBlobResult
2245 
2250  {
2254  Azure::ETag ETag;
2260  Azure::DateTime LastModified;
2264  Azure::Nullable<ContentHash> TransactionalContentHash;
2269  int64_t SequenceNumber = 0;
2275  bool IsServerEncrypted = false;
2279  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
2283  Azure::Nullable<std::string> EncryptionScope;
2284  }; // struct UploadPagesFromUriResult
2285 
2289  struct UploadPagesResult final
2290  {
2294  Azure::ETag ETag;
2300  Azure::DateTime LastModified;
2304  Azure::Nullable<ContentHash> TransactionalContentHash;
2309  int64_t SequenceNumber = 0;
2315  bool IsServerEncrypted = false;
2319  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
2323  Azure::Nullable<std::string> EncryptionScope;
2324  }; // struct UploadPagesResult
2325 
2329  struct UserDelegationKey final
2330  {
2334  std::string SignedObjectId;
2338  std::string SignedTenantId;
2342  Azure::DateTime SignedStartsOn;
2346  Azure::DateTime SignedExpiresOn;
2350  std::string SignedService;
2354  std::string SignedVersion;
2358  std::string Value;
2359  }; // struct UserDelegationKey
2360 
2361  namespace _detail {
2362  struct AcquireBlobContainerLeaseResult final
2363  {
2367  Azure::ETag ETag;
2373  Azure::DateTime LastModified;
2377  std::string LeaseId;
2378  }; // struct AcquireBlobContainerLeaseResult
2379  } // namespace _detail
2380 
2381  namespace _detail {
2382  struct AcquireBlobLeaseResult final
2383  {
2387  Azure::ETag ETag;
2393  Azure::DateTime LastModified;
2397  std::string LeaseId;
2398  }; // struct AcquireBlobLeaseResult
2399  } // namespace _detail
2400 
2401  namespace _detail {
2402  struct BreakBlobContainerLeaseResult final
2403  {
2407  Azure::ETag ETag;
2413  Azure::DateTime LastModified;
2417  int32_t LeaseTime = 0;
2418  }; // struct BreakBlobContainerLeaseResult
2419  } // namespace _detail
2420 
2421  namespace _detail {
2422  struct BreakBlobLeaseResult final
2423  {
2427  Azure::ETag ETag;
2433  Azure::DateTime LastModified;
2437  int32_t LeaseTime = 0;
2438  }; // struct BreakBlobLeaseResult
2439  } // namespace _detail
2440 
2441  namespace _detail {
2442  struct ChangeBlobContainerLeaseResult final
2443  {
2447  Azure::ETag ETag;
2453  Azure::DateTime LastModified;
2457  std::string LeaseId;
2458  }; // struct ChangeBlobContainerLeaseResult
2459  } // namespace _detail
2460 
2461  namespace _detail {
2462  struct ChangeBlobLeaseResult final
2463  {
2467  Azure::ETag ETag;
2473  Azure::DateTime LastModified;
2477  std::string LeaseId;
2478  }; // struct ChangeBlobLeaseResult
2479  } // namespace _detail
2480 
2481  namespace _detail {
2482  struct FindBlobsByTagsResult final
2483  {
2484  std::string ServiceEndpoint;
2485  Azure::Nullable<std::string> ContinuationToken;
2486  std::vector<TaggedBlobItem> Items;
2487  }; // struct FindBlobsByTagsResult
2488  } // namespace _detail
2489 
2490  namespace _detail {
2491  struct GetBlobTagsResult final
2492  {
2493  std::map<std::string, std::string> Tags;
2494  }; // struct GetBlobTagsResult
2495  } // namespace _detail
2496 
2497  namespace _detail {
2498  struct GetPageRangesResult final
2499  {
2503  Azure::ETag ETag;
2509  Azure::DateTime LastModified;
2513  int64_t BlobSize = 0;
2514  std::vector<Azure::Core::Http::HttpRange> PageRanges;
2515  std::vector<Azure::Core::Http::HttpRange> ClearRanges;
2516  }; // struct GetPageRangesResult
2517  } // namespace _detail
2518 
2519  namespace _detail {
2520  struct ListBlobContainersResult final
2521  {
2522  std::string ServiceEndpoint;
2523  std::string Prefix;
2524  Azure::Nullable<std::string> ContinuationToken;
2525  std::vector<BlobContainerItem> Items;
2526  }; // struct ListBlobContainersResult
2527  } // namespace _detail
2528 
2529  namespace _detail {
2530  struct ListBlobsByHierarchyResult final
2531  {
2532  std::string ServiceEndpoint;
2533  std::string BlobContainerName;
2534  std::string Prefix;
2535  std::string Delimiter;
2536  Azure::Nullable<std::string> ContinuationToken;
2537  std::vector<BlobItem> Items;
2538  std::vector<std::string> BlobPrefixes;
2539  }; // struct ListBlobsByHierarchyResult
2540  } // namespace _detail
2541 
2542  namespace _detail {
2543  struct ListBlobsResult final
2544  {
2545  std::string ServiceEndpoint;
2546  std::string BlobContainerName;
2547  std::string Prefix;
2548  Azure::Nullable<std::string> ContinuationToken;
2549  std::vector<BlobItem> Items;
2550  }; // struct ListBlobsResult
2551  } // namespace _detail
2552 
2553  namespace _detail {
2554  struct ReleaseBlobContainerLeaseResult final
2555  {
2559  Azure::ETag ETag;
2565  Azure::DateTime LastModified;
2566  }; // struct ReleaseBlobContainerLeaseResult
2567  } // namespace _detail
2568 
2569  namespace _detail {
2570  struct ReleaseBlobLeaseResult final
2571  {
2575  Azure::ETag ETag;
2581  Azure::DateTime LastModified;
2586  Azure::Nullable<int64_t> SequenceNumber;
2587  }; // struct ReleaseBlobLeaseResult
2588  } // namespace _detail
2589 
2590  namespace _detail {
2591  struct RenewBlobContainerLeaseResult final
2592  {
2596  Azure::ETag ETag;
2602  Azure::DateTime LastModified;
2606  std::string LeaseId;
2607  }; // struct RenewBlobContainerLeaseResult
2608  } // namespace _detail
2609 
2610  namespace _detail {
2611  struct RenewBlobLeaseResult final
2612  {
2616  Azure::ETag ETag;
2622  Azure::DateTime LastModified;
2626  std::string LeaseId;
2627  }; // struct RenewBlobLeaseResult
2628  } // namespace _detail
2629 
2630  namespace _detail {
2631  struct StartBlobCopyFromUriResult final
2632  {
2636  Azure::ETag ETag;
2642  Azure::DateTime LastModified;
2648  std::string CopyId;
2655  Models::CopyStatus CopyStatus;
2660  Azure::Nullable<std::string> VersionId;
2661  }; // struct StartBlobCopyFromUriResult
2662  } // namespace _detail
2663 
2664  namespace _detail {
2665  struct StartBlobCopyIncrementalResult final
2666  {
2670  Azure::ETag ETag;
2676  Azure::DateTime LastModified;
2682  std::string CopyId;
2689  Models::CopyStatus CopyStatus;
2694  Azure::Nullable<std::string> VersionId;
2695  }; // struct StartBlobCopyIncrementalResult
2696  } // namespace _detail
2697 
2698  namespace _detail {
2699  struct SubmitBlobBatchResult final
2700  {
2701  std::string ContentType;
2702  }; // struct SubmitBlobBatchResult
2703  } // namespace _detail
2704 
2705  namespace _detail {
2706  struct UndeleteBlobContainerResult final
2707  {
2708  }; // struct UndeleteBlobContainerResult
2709  } // namespace _detail
2710 
2711  } // namespace Models
2712 
2713  namespace _detail {
2714 
2715  using namespace Models;
2716 
2717  inline std::string ListBlobContainersIncludeFlagsToString(
2718  const ListBlobContainersIncludeFlags& val)
2719  {
2720  ListBlobContainersIncludeFlags value_list[] = {
2721  ListBlobContainersIncludeFlags::Metadata,
2722  ListBlobContainersIncludeFlags::Deleted,
2723  };
2724  const char* string_list[] = {
2725  "metadata",
2726  "deleted",
2727  };
2728  std::string ret;
2729  for (size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobContainersIncludeFlags); ++i)
2730  {
2731  if ((val & value_list[i]) == value_list[i])
2732  {
2733  if (!ret.empty())
2734  {
2735  ret += ",";
2736  }
2737  ret += string_list[i];
2738  }
2739  }
2740  return ret;
2741  }
2742 
2743  inline std::string ListBlobsIncludeFlagsToString(const ListBlobsIncludeFlags& val)
2744  {
2745  ListBlobsIncludeFlags value_list[] = {
2746  ListBlobsIncludeFlags::Copy,
2747  ListBlobsIncludeFlags::Deleted,
2748  ListBlobsIncludeFlags::Metadata,
2749  ListBlobsIncludeFlags::Snapshots,
2750  ListBlobsIncludeFlags::Versions,
2751  ListBlobsIncludeFlags::UncomittedBlobs,
2752  };
2753  const char* string_list[] = {
2754  "copy",
2755  "deleted",
2756  "metadata",
2757  "snapshots",
2758  "versions",
2759  "uncommittedblobs",
2760  };
2761  std::string ret;
2762  for (size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobsIncludeFlags); ++i)
2763  {
2764  if ((val & value_list[i]) == value_list[i])
2765  {
2766  if (!ret.empty())
2767  {
2768  ret += ",";
2769  }
2770  ret += string_list[i];
2771  }
2772  }
2773  return ret;
2774  }
2775 
2776  class BlobRestClient final {
2777  public:
2778  class Service final {
2779  public:
2780  struct ListBlobContainersOptions final
2781  {
2782  Azure::Nullable<int32_t> Timeout;
2783  Azure::Nullable<std::string> Prefix;
2784  Azure::Nullable<std::string> ContinuationToken;
2785  Azure::Nullable<int32_t> MaxResults;
2786  ListBlobContainersIncludeFlags Include = ListBlobContainersIncludeFlags::None;
2787  }; // struct ListBlobContainersOptions
2788 
2789  static Azure::Response<Models::_detail::ListBlobContainersResult> ListBlobContainers(
2790  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2791  const Azure::Core::Url& url,
2792  const ListBlobContainersOptions& options,
2793  const Azure::Core::Context& context)
2794  {
2795  (void)options;
2796  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
2797  request.SetHeader("x-ms-version", "2020-02-10");
2798  if (options.Timeout.HasValue())
2799  {
2800  request.GetUrl().AppendQueryParameter(
2801  "timeout", std::to_string(options.Timeout.Value()));
2802  }
2803  request.GetUrl().AppendQueryParameter("comp", "list");
2804  if (options.Prefix.HasValue())
2805  {
2806  request.GetUrl().AppendQueryParameter(
2807  "prefix", _internal::UrlEncodeQueryParameter(options.Prefix.Value()));
2808  }
2809  if (options.ContinuationToken.HasValue())
2810  {
2811  request.GetUrl().AppendQueryParameter(
2812  "marker", _internal::UrlEncodeQueryParameter(options.ContinuationToken.Value()));
2813  }
2814  if (options.MaxResults.HasValue())
2815  {
2816  request.GetUrl().AppendQueryParameter(
2817  "maxresults", std::to_string(options.MaxResults.Value()));
2818  }
2819  std::string list_blob_containers_include_flags
2820  = ListBlobContainersIncludeFlagsToString(options.Include);
2821  if (!list_blob_containers_include_flags.empty())
2822  {
2823  request.GetUrl().AppendQueryParameter(
2824  "include", _internal::UrlEncodeQueryParameter(list_blob_containers_include_flags));
2825  }
2826  auto pHttpResponse = pipeline.Send(request, context);
2827  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
2828  Models::_detail::ListBlobContainersResult response;
2829  auto http_status_code
2830  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
2831  httpResponse.GetStatusCode());
2832  if (!(http_status_code == 200))
2833  {
2834  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
2835  }
2836  {
2837  const auto& httpResponseBody = httpResponse.GetBody();
2838  _internal::XmlReader reader(
2839  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
2840  response = ListBlobContainersResultInternalFromXml(reader);
2841  }
2842  return Azure::Response<Models::_detail::ListBlobContainersResult>(
2843  std::move(response), std::move(pHttpResponse));
2844  }
2845 
2846  struct GetUserDelegationKeyOptions final
2847  {
2848  Azure::Nullable<int32_t> Timeout;
2849  Azure::DateTime StartsOn;
2850  Azure::DateTime ExpiresOn;
2851  }; // struct GetUserDelegationKeyOptions
2852 
2853  static Azure::Response<UserDelegationKey> GetUserDelegationKey(
2854  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2855  const Azure::Core::Url& url,
2856  const GetUserDelegationKeyOptions& options,
2857  const Azure::Core::Context& context)
2858  {
2859  (void)options;
2860  std::string xml_body;
2861  {
2862  _internal::XmlWriter writer;
2863  GetUserDelegationKeyOptionsToXml(writer, options);
2864  xml_body = writer.GetDocument();
2865  writer.Write(_internal::XmlNode{_internal::XmlNodeType::End});
2866  }
2867  Azure::Core::IO::MemoryBodyStream xml_body_stream(
2868  reinterpret_cast<const uint8_t*>(xml_body.data()), xml_body.length());
2869  auto request = Azure::Core::Http::Request(
2870  Azure::Core::Http::HttpMethod::Post, url, &xml_body_stream);
2871  request.SetHeader("Content-Length", std::to_string(xml_body_stream.Length()));
2872  request.GetUrl().AppendQueryParameter("restype", "service");
2873  request.GetUrl().AppendQueryParameter("comp", "userdelegationkey");
2874  request.SetHeader("x-ms-version", "2020-02-10");
2875  if (options.Timeout.HasValue())
2876  {
2877  request.GetUrl().AppendQueryParameter(
2878  "timeout", std::to_string(options.Timeout.Value()));
2879  }
2880  auto pHttpResponse = pipeline.Send(request, context);
2881  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
2882  UserDelegationKey response;
2883  auto http_status_code
2884  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
2885  httpResponse.GetStatusCode());
2886  if (!(http_status_code == 200))
2887  {
2888  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
2889  }
2890  {
2891  const auto& httpResponseBody = httpResponse.GetBody();
2892  _internal::XmlReader reader(
2893  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
2894  response = UserDelegationKeyFromXml(reader);
2895  }
2896  return Azure::Response<UserDelegationKey>(std::move(response), std::move(pHttpResponse));
2897  }
2898 
2899  struct GetServicePropertiesOptions final
2900  {
2901  Azure::Nullable<int32_t> Timeout;
2902  }; // struct GetServicePropertiesOptions
2903 
2904  static Azure::Response<BlobServiceProperties> GetProperties(
2905  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2906  const Azure::Core::Url& url,
2907  const GetServicePropertiesOptions& options,
2908  const Azure::Core::Context& context)
2909  {
2910  (void)options;
2911  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
2912  request.GetUrl().AppendQueryParameter("restype", "service");
2913  request.GetUrl().AppendQueryParameter("comp", "properties");
2914  request.SetHeader("x-ms-version", "2020-02-10");
2915  if (options.Timeout.HasValue())
2916  {
2917  request.GetUrl().AppendQueryParameter(
2918  "timeout", std::to_string(options.Timeout.Value()));
2919  }
2920  auto pHttpResponse = pipeline.Send(request, context);
2921  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
2922  BlobServiceProperties response;
2923  auto http_status_code
2924  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
2925  httpResponse.GetStatusCode());
2926  if (!(http_status_code == 200))
2927  {
2928  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
2929  }
2930  {
2931  const auto& httpResponseBody = httpResponse.GetBody();
2932  _internal::XmlReader reader(
2933  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
2934  response = BlobServicePropertiesFromXml(reader);
2935  }
2936  return Azure::Response<BlobServiceProperties>(
2937  std::move(response), std::move(pHttpResponse));
2938  }
2939 
2940  struct SetServicePropertiesOptions final
2941  {
2942  Azure::Nullable<int32_t> Timeout;
2943  BlobServiceProperties Properties;
2944  }; // struct SetServicePropertiesOptions
2945 
2946  static Azure::Response<SetServicePropertiesResult> SetProperties(
2947  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2948  const Azure::Core::Url& url,
2949  const SetServicePropertiesOptions& options,
2950  const Azure::Core::Context& context)
2951  {
2952  (void)options;
2953  std::string xml_body;
2954  {
2955  _internal::XmlWriter writer;
2956  SetServicePropertiesOptionsToXml(writer, options);
2957  xml_body = writer.GetDocument();
2958  writer.Write(_internal::XmlNode{_internal::XmlNodeType::End});
2959  }
2960  Azure::Core::IO::MemoryBodyStream xml_body_stream(
2961  reinterpret_cast<const uint8_t*>(xml_body.data()), xml_body.length());
2962  auto request = Azure::Core::Http::Request(
2963  Azure::Core::Http::HttpMethod::Put, url, &xml_body_stream);
2964  request.SetHeader("Content-Length", std::to_string(xml_body_stream.Length()));
2965  request.GetUrl().AppendQueryParameter("restype", "service");
2966  request.GetUrl().AppendQueryParameter("comp", "properties");
2967  request.SetHeader("x-ms-version", "2020-02-10");
2968  if (options.Timeout.HasValue())
2969  {
2970  request.GetUrl().AppendQueryParameter(
2971  "timeout", std::to_string(options.Timeout.Value()));
2972  }
2973  auto pHttpResponse = pipeline.Send(request, context);
2974  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
2975  SetServicePropertiesResult response;
2976  auto http_status_code
2977  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
2978  httpResponse.GetStatusCode());
2979  if (!(http_status_code == 202))
2980  {
2981  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
2982  }
2983  return Azure::Response<SetServicePropertiesResult>(
2984  std::move(response), std::move(pHttpResponse));
2985  }
2986 
2987  struct GetAccountInfoOptions final
2988  {
2989  Azure::Nullable<int32_t> Timeout;
2990  }; // struct GetAccountInfoOptions
2991 
2992  static Azure::Response<AccountInfo> GetAccountInfo(
2993  Azure::Core::Http::_internal::HttpPipeline& pipeline,
2994  const Azure::Core::Url& url,
2995  const GetAccountInfoOptions& options,
2996  const Azure::Core::Context& context)
2997  {
2998  (void)options;
2999  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Head, url);
3000  request.GetUrl().AppendQueryParameter("restype", "account");
3001  request.GetUrl().AppendQueryParameter("comp", "properties");
3002  request.SetHeader("x-ms-version", "2020-02-10");
3003  if (options.Timeout.HasValue())
3004  {
3005  request.GetUrl().AppendQueryParameter(
3006  "timeout", std::to_string(options.Timeout.Value()));
3007  }
3008  auto pHttpResponse = pipeline.Send(request, context);
3009  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
3010  AccountInfo response;
3011  auto http_status_code
3012  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
3013  httpResponse.GetStatusCode());
3014  if (!(http_status_code == 200))
3015  {
3016  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
3017  }
3018  response.SkuName = SkuName(httpResponse.GetHeaders().at("x-ms-sku-name"));
3019  response.AccountKind = AccountKind(httpResponse.GetHeaders().at("x-ms-account-kind"));
3020  response.IsHierarchicalNamespaceEnabled
3021  = httpResponse.GetHeaders().at("x-ms-is-hns-enabled") == "true";
3022  return Azure::Response<AccountInfo>(std::move(response), std::move(pHttpResponse));
3023  }
3024 
3025  struct GetServiceStatisticsOptions final
3026  {
3027  Azure::Nullable<int32_t> Timeout;
3028  }; // struct GetServiceStatisticsOptions
3029 
3030  static Azure::Response<ServiceStatistics> GetStatistics(
3031  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3032  const Azure::Core::Url& url,
3033  const GetServiceStatisticsOptions& options,
3034  const Azure::Core::Context& context)
3035  {
3036  (void)options;
3037  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
3038  request.GetUrl().AppendQueryParameter("restype", "service");
3039  request.GetUrl().AppendQueryParameter("comp", "stats");
3040  request.SetHeader("x-ms-version", "2020-02-10");
3041  if (options.Timeout.HasValue())
3042  {
3043  request.GetUrl().AppendQueryParameter(
3044  "timeout", std::to_string(options.Timeout.Value()));
3045  }
3046  auto pHttpResponse = pipeline.Send(request, context);
3047  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
3048  ServiceStatistics response;
3049  auto http_status_code
3050  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
3051  httpResponse.GetStatusCode());
3052  if (!(http_status_code == 200))
3053  {
3054  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
3055  }
3056  {
3057  const auto& httpResponseBody = httpResponse.GetBody();
3058  _internal::XmlReader reader(
3059  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
3060  response = ServiceStatisticsFromXml(reader);
3061  }
3062  return Azure::Response<ServiceStatistics>(std::move(response), std::move(pHttpResponse));
3063  }
3064 
3065  struct FindBlobsByTagsOptions final
3066  {
3067  Azure::Nullable<int32_t> Timeout;
3068  std::string Where;
3069  Azure::Nullable<std::string> ContinuationToken;
3070  Azure::Nullable<int32_t> MaxResults;
3071  }; // struct FindBlobsByTagsOptions
3072 
3073  static Azure::Response<Models::_detail::FindBlobsByTagsResult> FindBlobsByTags(
3074  Azure::Core::Http::_internal::HttpPipeline& pipeline,
3075  const Azure::Core::Url& url,
3076  const FindBlobsByTagsOptions& options,
3077  const Azure::Core::Context& context)
3078  {
3079  (void)options;
3080  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
3081  request.SetHeader("x-ms-version", "2020-02-10");
3082  if (options.Timeout.HasValue())
3083  {
3084  request.GetUrl().AppendQueryParameter(
3085  "timeout", std::to_string(options.Timeout.Value()));
3086  }
3087  request.GetUrl().AppendQueryParameter("comp", "blobs");
3088  request.GetUrl().AppendQueryParameter(
3089  "where", _internal::UrlEncodeQueryParameter(options.Where));
3090  if (options.ContinuationToken.HasValue())
3091  {
3092  request.GetUrl().AppendQueryParameter(
3093  "marker", _internal::UrlEncodeQueryParameter(options.ContinuationToken.Value()));
3094  }
3095  if (options.MaxResults.HasValue())
3096  {
3097  request.GetUrl().AppendQueryParameter(
3098  "maxresults", std::to_string(options.MaxResults.Value()));
3099  }
3100  auto pHttpResponse = pipeline.Send(request, context);
3101  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
3102  Models::_detail::FindBlobsByTagsResult response;
3103  auto http_status_code
3104  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
3105  httpResponse.GetStatusCode());
3106  if (!(http_status_code == 200))
3107  {
3108  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
3109  }
3110  {
3111  const auto& httpResponseBody = httpResponse.GetBody();
3112  _internal::XmlReader reader(
3113  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
3114  response = FindBlobsByTagsResultInternalFromXml(reader);
3115  }
3116  return Azure::Response<Models::_detail::FindBlobsByTagsResult>(
3117  std::move(response), std::move(pHttpResponse));
3118  }
3119 
3120  private:
3121  static BlobServiceProperties BlobServicePropertiesFromXml(_internal::XmlReader& reader)
3122  {
3123  BlobServiceProperties ret;
3124  enum class XmlTagName
3125  {
3126  k_StorageServiceProperties,
3127  k_Logging,
3128  k_HourMetrics,
3129  k_MinuteMetrics,
3130  k_Cors,
3131  k_CorsRule,
3132  k_DefaultServiceVersion,
3133  k_DeleteRetentionPolicy,
3134  k_StaticWebsite,
3135  k_Unknown,
3136  };
3137  std::vector<XmlTagName> path;
3138  while (true)
3139  {
3140  auto node = reader.Read();
3141  if (node.Type == _internal::XmlNodeType::End)
3142  {
3143  break;
3144  }
3145  else if (node.Type == _internal::XmlNodeType::EndTag)
3146  {
3147  if (path.size() > 0)
3148  {
3149  path.pop_back();
3150  }
3151  else
3152  {
3153  break;
3154  }
3155  }
3156  else if (node.Type == _internal::XmlNodeType::StartTag)
3157  {
3158  if (std::strcmp(node.Name, "StorageServiceProperties") == 0)
3159  {
3160  path.emplace_back(XmlTagName::k_StorageServiceProperties);
3161  }
3162  else if (std::strcmp(node.Name, "Logging") == 0)
3163  {
3164  path.emplace_back(XmlTagName::k_Logging);
3165  }
3166  else if (std::strcmp(node.Name, "HourMetrics") == 0)
3167  {
3168  path.emplace_back(XmlTagName::k_HourMetrics);
3169  }
3170  else if (std::strcmp(node.Name, "MinuteMetrics") == 0)
3171  {
3172  path.emplace_back(XmlTagName::k_MinuteMetrics);
3173  }
3174  else if (std::strcmp(node.Name, "Cors") == 0)
3175  {
3176  path.emplace_back(XmlTagName::k_Cors);
3177  }
3178  else if (std::strcmp(node.Name, "CorsRule") == 0)
3179  {
3180  path.emplace_back(XmlTagName::k_CorsRule);
3181  }
3182  else if (std::strcmp(node.Name, "DefaultServiceVersion") == 0)
3183  {
3184  path.emplace_back(XmlTagName::k_DefaultServiceVersion);
3185  }
3186  else if (std::strcmp(node.Name, "DeleteRetentionPolicy") == 0)
3187  {
3188  path.emplace_back(XmlTagName::k_DeleteRetentionPolicy);
3189  }
3190  else if (std::strcmp(node.Name, "StaticWebsite") == 0)
3191  {
3192  path.emplace_back(XmlTagName::k_StaticWebsite);
3193  }
3194  else
3195  {
3196  path.emplace_back(XmlTagName::k_Unknown);
3197  }
3198  if (path.size() == 2 && path[0] == XmlTagName::k_StorageServiceProperties
3199  && path[1] == XmlTagName::k_Logging)
3200  {
3201  ret.Logging = AnalyticsLoggingFromXml(reader);
3202  path.pop_back();
3203  }
3204  else if (
3205  path.size() == 2 && path[0] == XmlTagName::k_StorageServiceProperties
3206  && path[1] == XmlTagName::k_HourMetrics)
3207  {
3208  ret.HourMetrics = MetricsFromXml(reader);
3209  path.pop_back();
3210  }
3211  else if (
3212  path.size() == 2 && path[0] == XmlTagName::k_StorageServiceProperties
3213  && path[1] == XmlTagName::k_MinuteMetrics)
3214  {
3215  ret.MinuteMetrics = MetricsFromXml(reader);
3216  path.pop_back();
3217  }
3218  else if (
3219  path.size() == 3 && path[0] == XmlTagName::k_StorageServiceProperties
3220  && path[1] == XmlTagName::k_Cors && path[2] == XmlTagName::k_CorsRule)
3221  {
3222  ret.Cors.emplace_back(CorsRuleFromXml(reader));
3223  path.pop_back();
3224  }
3225  else if (
3226  path.size() == 2 && path[0] == XmlTagName::k_StorageServiceProperties
3227  && path[1] == XmlTagName::k_DeleteRetentionPolicy)
3228  {
3229  ret.DeleteRetentionPolicy = RetentionPolicyFromXml(reader);
3230  path.pop_back();
3231  }
3232  else if (
3233  path.size() == 2 && path[0] == XmlTagName::k_StorageServiceProperties
3234  && path[1] == XmlTagName::k_StaticWebsite)
3235  {
3236  ret.StaticWebsite = StaticWebsiteFromXml(reader);
3237  path.pop_back();
3238  }
3239  }
3240  else if (node.Type == _internal::XmlNodeType::Text)
3241  {
3242  if (path.size() == 2 && path[0] == XmlTagName::k_StorageServiceProperties
3243  && path[1] == XmlTagName::k_DefaultServiceVersion)
3244  {
3245  ret.DefaultServiceVersion = node.Value;
3246  }
3247  }
3248  }
3249  return ret;
3250  }
3251 
3252  static Models::_detail::FindBlobsByTagsResult FindBlobsByTagsResultInternalFromXml(
3253  _internal::XmlReader& reader)
3254  {
3255  Models::_detail::FindBlobsByTagsResult ret;
3256  enum class XmlTagName
3257  {
3258  k_EnumerationResults,
3259  k_NextMarker,
3260  k_Blobs,
3261  k_Blob,
3262  k_Unknown,
3263  };
3264  std::vector<XmlTagName> path;
3265  while (true)
3266  {
3267  auto node = reader.Read();
3268  if (node.Type == _internal::XmlNodeType::End)
3269  {
3270  break;
3271  }
3272  else if (node.Type == _internal::XmlNodeType::EndTag)
3273  {
3274  if (path.size() > 0)
3275  {
3276  path.pop_back();
3277  }
3278  else
3279  {
3280  break;
3281  }
3282  }
3283  else if (node.Type == _internal::XmlNodeType::StartTag)
3284  {
3285  if (std::strcmp(node.Name, "EnumerationResults") == 0)
3286  {
3287  path.emplace_back(XmlTagName::k_EnumerationResults);
3288  }
3289  else if (std::strcmp(node.Name, "NextMarker") == 0)
3290  {
3291  path.emplace_back(XmlTagName::k_NextMarker);
3292  }
3293  else if (std::strcmp(node.Name, "Blobs") == 0)
3294  {
3295  path.emplace_back(XmlTagName::k_Blobs);
3296  }
3297  else if (std::strcmp(node.Name, "Blob") == 0)
3298  {
3299  path.emplace_back(XmlTagName::k_Blob);
3300  }
3301  else
3302  {
3303  path.emplace_back(XmlTagName::k_Unknown);
3304  }
3305  if (path.size() == 3 && path[0] == XmlTagName::k_EnumerationResults
3306  && path[1] == XmlTagName::k_Blobs && path[2] == XmlTagName::k_Blob)
3307  {
3308  ret.Items.emplace_back(TaggedBlobItemFromXml(reader));
3309  path.pop_back();
3310  }
3311  }
3312  else if (node.Type == _internal::XmlNodeType::Text)
3313  {
3314  if (path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
3315  && path[1] == XmlTagName::k_NextMarker)
3316  {
3317  ret.ContinuationToken = node.Value;
3318  }
3319  }
3320  else if (node.Type == _internal::XmlNodeType::Attribute)
3321  {
3322  if (path.size() == 1 && path[0] == XmlTagName::k_EnumerationResults
3323  && std::strcmp(node.Name, "ServiceEndpoint") == 0)
3324  {
3325  ret.ServiceEndpoint = node.Value;
3326  }
3327  }
3328  }
3329  return ret;
3330  }
3331 
3332  static Models::_detail::ListBlobContainersResult ListBlobContainersResultInternalFromXml(
3333  _internal::XmlReader& reader)
3334  {
3335  Models::_detail::ListBlobContainersResult ret;
3336  enum class XmlTagName
3337  {
3338  k_EnumerationResults,
3339  k_Prefix,
3340  k_NextMarker,
3341  k_Containers,
3342  k_Container,
3343  k_Unknown,
3344  };
3345  std::vector<XmlTagName> path;
3346  while (true)
3347  {
3348  auto node = reader.Read();
3349  if (node.Type == _internal::XmlNodeType::End)
3350  {
3351  break;
3352  }
3353  else if (node.Type == _internal::XmlNodeType::EndTag)
3354  {
3355  if (path.size() > 0)
3356  {
3357  path.pop_back();
3358  }
3359  else
3360  {
3361  break;
3362  }
3363  }
3364  else if (node.Type == _internal::XmlNodeType::StartTag)
3365  {
3366  if (std::strcmp(node.Name, "EnumerationResults") == 0)
3367  {
3368  path.emplace_back(XmlTagName::k_EnumerationResults);
3369  }
3370  else if (std::strcmp(node.Name, "Prefix") == 0)
3371  {
3372  path.emplace_back(XmlTagName::k_Prefix);
3373  }
3374  else if (std::strcmp(node.Name, "NextMarker") == 0)
3375  {
3376  path.emplace_back(XmlTagName::k_NextMarker);
3377  }
3378  else if (std::strcmp(node.Name, "Containers") == 0)
3379  {
3380  path.emplace_back(XmlTagName::k_Containers);
3381  }
3382  else if (std::strcmp(node.Name, "Container") == 0)
3383  {
3384  path.emplace_back(XmlTagName::k_Container);
3385  }
3386  else
3387  {
3388  path.emplace_back(XmlTagName::k_Unknown);
3389  }
3390  if (path.size() == 3 && path[0] == XmlTagName::k_EnumerationResults
3391  && path[1] == XmlTagName::k_Containers && path[2] == XmlTagName::k_Container)
3392  {
3393  ret.Items.emplace_back(BlobContainerItemFromXml(reader));
3394  path.pop_back();
3395  }
3396  }
3397  else if (node.Type == _internal::XmlNodeType::Text)
3398  {
3399  if (path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
3400  && path[1] == XmlTagName::k_Prefix)
3401  {
3402  ret.Prefix = node.Value;
3403  }
3404  else if (
3405  path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
3406  && path[1] == XmlTagName::k_NextMarker)
3407  {
3408  ret.ContinuationToken = node.Value;
3409  }
3410  }
3411  else if (node.Type == _internal::XmlNodeType::Attribute)
3412  {
3413  if (path.size() == 1 && path[0] == XmlTagName::k_EnumerationResults
3414  && std::strcmp(node.Name, "ServiceEndpoint") == 0)
3415  {
3416  ret.ServiceEndpoint = node.Value;
3417  }
3418  }
3419  }
3420  return ret;
3421  }
3422 
3423  static ServiceStatistics ServiceStatisticsFromXml(_internal::XmlReader& reader)
3424  {
3425  ServiceStatistics ret;
3426  enum class XmlTagName
3427  {
3428  k_StorageServiceStats,
3429  k_GeoReplication,
3430  k_Unknown,
3431  };
3432  std::vector<XmlTagName> path;
3433  while (true)
3434  {
3435  auto node = reader.Read();
3436  if (node.Type == _internal::XmlNodeType::End)
3437  {
3438  break;
3439  }
3440  else if (node.Type == _internal::XmlNodeType::EndTag)
3441  {
3442  if (path.size() > 0)
3443  {
3444  path.pop_back();
3445  }
3446  else
3447  {
3448  break;
3449  }
3450  }
3451  else if (node.Type == _internal::XmlNodeType::StartTag)
3452  {
3453  if (std::strcmp(node.Name, "StorageServiceStats") == 0)
3454  {
3455  path.emplace_back(XmlTagName::k_StorageServiceStats);
3456  }
3457  else if (std::strcmp(node.Name, "GeoReplication") == 0)
3458  {
3459  path.emplace_back(XmlTagName::k_GeoReplication);
3460  }
3461  else
3462  {
3463  path.emplace_back(XmlTagName::k_Unknown);
3464  }
3465  if (path.size() == 2 && path[0] == XmlTagName::k_StorageServiceStats
3466  && path[1] == XmlTagName::k_GeoReplication)
3467  {
3468  ret.GeoReplication = GeoReplicationFromXml(reader);
3469  path.pop_back();
3470  }
3471  }
3472  else if (node.Type == _internal::XmlNodeType::Text)
3473  {
3474  }
3475  }
3476  return ret;
3477  }
3478 
3479  static UserDelegationKey UserDelegationKeyFromXml(_internal::XmlReader& reader)
3480  {
3481  UserDelegationKey ret;
3482  enum class XmlTagName
3483  {
3484  k_UserDelegationKey,
3485  k_SignedOid,
3486  k_SignedTid,
3487  k_SignedStart,
3488  k_SignedExpiry,
3489  k_SignedService,
3490  k_SignedVersion,
3491  k_Value,
3492  k_Unknown,
3493  };
3494  std::vector<XmlTagName> path;
3495  while (true)
3496  {
3497  auto node = reader.Read();
3498  if (node.Type == _internal::XmlNodeType::End)
3499  {
3500  break;
3501  }
3502  else if (node.Type == _internal::XmlNodeType::EndTag)
3503  {
3504  if (path.size() > 0)
3505  {
3506  path.pop_back();
3507  }
3508  else
3509  {
3510  break;
3511  }
3512  }
3513  else if (node.Type == _internal::XmlNodeType::StartTag)
3514  {
3515  if (std::strcmp(node.Name, "UserDelegationKey") == 0)
3516  {
3517  path.emplace_back(XmlTagName::k_UserDelegationKey);
3518  }
3519  else if (std::strcmp(node.Name, "SignedOid") == 0)
3520  {
3521  path.emplace_back(XmlTagName::k_SignedOid);
3522  }
3523  else if (std::strcmp(node.Name, "SignedTid") == 0)
3524  {
3525  path.emplace_back(XmlTagName::k_SignedTid);
3526  }
3527  else if (std::strcmp(node.Name, "SignedStart") == 0)
3528  {
3529  path.emplace_back(XmlTagName::k_SignedStart);
3530  }
3531  else if (std::strcmp(node.Name, "SignedExpiry") == 0)
3532  {
3533  path.emplace_back(XmlTagName::k_SignedExpiry);
3534  }
3535  else if (std::strcmp(node.Name, "SignedService") == 0)
3536  {
3537  path.emplace_back(XmlTagName::k_SignedService);
3538  }
3539  else if (std::strcmp(node.Name, "SignedVersion") == 0)
3540  {
3541  path.emplace_back(XmlTagName::k_SignedVersion);
3542  }
3543  else if (std::strcmp(node.Name, "Value") == 0)
3544  {
3545  path.emplace_back(XmlTagName::k_Value);
3546  }
3547  else
3548  {
3549  path.emplace_back(XmlTagName::k_Unknown);
3550  }
3551  }
3552  else if (node.Type == _internal::XmlNodeType::Text)
3553  {
3554  if (path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3555  && path[1] == XmlTagName::k_SignedOid)
3556  {
3557  ret.SignedObjectId = node.Value;
3558  }
3559  else if (
3560  path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3561  && path[1] == XmlTagName::k_SignedTid)
3562  {
3563  ret.SignedTenantId = node.Value;
3564  }
3565  else if (
3566  path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3567  && path[1] == XmlTagName::k_SignedStart)
3568  {
3569  ret.SignedStartsOn
3570  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc3339);
3571  }
3572  else if (
3573  path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3574  && path[1] == XmlTagName::k_SignedExpiry)
3575  {
3576  ret.SignedExpiresOn
3577  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc3339);
3578  }
3579  else if (
3580  path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3581  && path[1] == XmlTagName::k_SignedService)
3582  {
3583  ret.SignedService = node.Value;
3584  }
3585  else if (
3586  path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3587  && path[1] == XmlTagName::k_SignedVersion)
3588  {
3589  ret.SignedVersion = node.Value;
3590  }
3591  else if (
3592  path.size() == 2 && path[0] == XmlTagName::k_UserDelegationKey
3593  && path[1] == XmlTagName::k_Value)
3594  {
3595  ret.Value = node.Value;
3596  }
3597  }
3598  }
3599  return ret;
3600  }
3601 
3602  static AnalyticsLogging AnalyticsLoggingFromXml(_internal::XmlReader& reader)
3603  {
3604  AnalyticsLogging ret;
3605  enum class XmlTagName
3606  {
3607  k_Version,
3608  k_Delete,
3609  k_Read,
3610  k_Write,
3611  k_RetentionPolicy,
3612  k_Unknown,
3613  };
3614  std::vector<XmlTagName> path;
3615  while (true)
3616  {
3617  auto node = reader.Read();
3618  if (node.Type == _internal::XmlNodeType::End)
3619  {
3620  break;
3621  }
3622  else if (node.Type == _internal::XmlNodeType::EndTag)
3623  {
3624  if (path.size() > 0)
3625  {
3626  path.pop_back();
3627  }
3628  else
3629  {
3630  break;
3631  }
3632  }
3633  else if (node.Type == _internal::XmlNodeType::StartTag)
3634  {
3635  if (std::strcmp(node.Name, "Version") == 0)
3636  {
3637  path.emplace_back(XmlTagName::k_Version);
3638  }
3639  else if (std::strcmp(node.Name, "Delete") == 0)
3640  {
3641  path.emplace_back(XmlTagName::k_Delete);
3642  }
3643  else if (std::strcmp(node.Name, "Read") == 0)
3644  {
3645  path.emplace_back(XmlTagName::k_Read);
3646  }
3647  else if (std::strcmp(node.Name, "Write") == 0)
3648  {
3649  path.emplace_back(XmlTagName::k_Write);
3650  }
3651  else if (std::strcmp(node.Name, "RetentionPolicy") == 0)
3652  {
3653  path.emplace_back(XmlTagName::k_RetentionPolicy);
3654  }
3655  else
3656  {
3657  path.emplace_back(XmlTagName::k_Unknown);
3658  }
3659  if (path.size() == 1 && path[0] == XmlTagName::k_RetentionPolicy)
3660  {
3661  ret.RetentionPolicy = RetentionPolicyFromXml(reader);
3662  path.pop_back();
3663  }
3664  }
3665  else if (node.Type == _internal::XmlNodeType::Text)
3666  {
3667  if (path.size() == 1 && path[0] == XmlTagName::k_Version)
3668  {
3669  ret.Version = node.Value;
3670  }
3671  else if (path.size() == 1 && path[0] == XmlTagName::k_Delete)
3672  {
3673  ret.Delete = std::strcmp(node.Value, "true") == 0;
3674  }
3675  else if (path.size() == 1 && path[0] == XmlTagName::k_Read)
3676  {
3677  ret.Read = std::strcmp(node.Value, "true") == 0;
3678  }
3679  else if (path.size() == 1 && path[0] == XmlTagName::k_Write)
3680  {
3681  ret.Write = std::strcmp(node.Value, "true") == 0;
3682  }
3683  }
3684  }
3685  return ret;
3686  }
3687 
3688  static BlobContainerItem BlobContainerItemFromXml(_internal::XmlReader& reader)
3689  {
3690  BlobContainerItem ret;
3691  enum class XmlTagName
3692  {
3693  k_Name,
3694  k_Properties,
3695  k_Etag,
3696  k_LastModified,
3697  k_PublicAccess,
3698  k_HasImmutabilityPolicy,
3699  k_HasLegalHold,
3700  k_LeaseStatus,
3701  k_LeaseState,
3702  k_LeaseDuration,
3703  k_DefaultEncryptionScope,
3704  k_DenyEncryptionScopeOverride,
3705  k_Metadata,
3706  k_Deleted,
3707  k_Version,
3708  k_DeletedTime,
3709  k_RemainingRetentionDays,
3710  k_Unknown,
3711  };
3712  std::vector<XmlTagName> path;
3713  while (true)
3714  {
3715  auto node = reader.Read();
3716  if (node.Type == _internal::XmlNodeType::End)
3717  {
3718  break;
3719  }
3720  else if (node.Type == _internal::XmlNodeType::EndTag)
3721  {
3722  if (path.size() > 0)
3723  {
3724  path.pop_back();
3725  }
3726  else
3727  {
3728  break;
3729  }
3730  }
3731  else if (node.Type == _internal::XmlNodeType::StartTag)
3732  {
3733  if (std::strcmp(node.Name, "Name") == 0)
3734  {
3735  path.emplace_back(XmlTagName::k_Name);
3736  }
3737  else if (std::strcmp(node.Name, "Properties") == 0)
3738  {
3739  path.emplace_back(XmlTagName::k_Properties);
3740  }
3741  else if (std::strcmp(node.Name, "Etag") == 0)
3742  {
3743  path.emplace_back(XmlTagName::k_Etag);
3744  }
3745  else if (std::strcmp(node.Name, "Last-Modified") == 0)
3746  {
3747  path.emplace_back(XmlTagName::k_LastModified);
3748  }
3749  else if (std::strcmp(node.Name, "PublicAccess") == 0)
3750  {
3751  path.emplace_back(XmlTagName::k_PublicAccess);
3752  }
3753  else if (std::strcmp(node.Name, "HasImmutabilityPolicy") == 0)
3754  {
3755  path.emplace_back(XmlTagName::k_HasImmutabilityPolicy);
3756  }
3757  else if (std::strcmp(node.Name, "HasLegalHold") == 0)
3758  {
3759  path.emplace_back(XmlTagName::k_HasLegalHold);
3760  }
3761  else if (std::strcmp(node.Name, "LeaseStatus") == 0)
3762  {
3763  path.emplace_back(XmlTagName::k_LeaseStatus);
3764  }
3765  else if (std::strcmp(node.Name, "LeaseState") == 0)
3766  {
3767  path.emplace_back(XmlTagName::k_LeaseState);
3768  }
3769  else if (std::strcmp(node.Name, "LeaseDuration") == 0)
3770  {
3771  path.emplace_back(XmlTagName::k_LeaseDuration);
3772  }
3773  else if (std::strcmp(node.Name, "DefaultEncryptionScope") == 0)
3774  {
3775  path.emplace_back(XmlTagName::k_DefaultEncryptionScope);
3776  }
3777  else if (std::strcmp(node.Name, "DenyEncryptionScopeOverride") == 0)
3778  {
3779  path.emplace_back(XmlTagName::k_DenyEncryptionScopeOverride);
3780  }
3781  else if (std::strcmp(node.Name, "Metadata") == 0)
3782  {
3783  path.emplace_back(XmlTagName::k_Metadata);
3784  }
3785  else if (std::strcmp(node.Name, "Deleted") == 0)
3786  {
3787  path.emplace_back(XmlTagName::k_Deleted);
3788  }
3789  else if (std::strcmp(node.Name, "Version") == 0)
3790  {
3791  path.emplace_back(XmlTagName::k_Version);
3792  }
3793  else if (std::strcmp(node.Name, "DeletedTime") == 0)
3794  {
3795  path.emplace_back(XmlTagName::k_DeletedTime);
3796  }
3797  else if (std::strcmp(node.Name, "RemainingRetentionDays") == 0)
3798  {
3799  path.emplace_back(XmlTagName::k_RemainingRetentionDays);
3800  }
3801  else
3802  {
3803  path.emplace_back(XmlTagName::k_Unknown);
3804  }
3805  if (path.size() == 1 && path[0] == XmlTagName::k_Metadata)
3806  {
3807  ret.Details.Metadata = MetadataFromXml(reader);
3808  path.pop_back();
3809  }
3810  }
3811  else if (node.Type == _internal::XmlNodeType::Text)
3812  {
3813  if (path.size() == 1 && path[0] == XmlTagName::k_Name)
3814  {
3815  ret.Name = node.Value;
3816  }
3817  else if (
3818  path.size() == 2 && path[0] == XmlTagName::k_Properties
3819  && path[1] == XmlTagName::k_Etag)
3820  {
3821  ret.Details.ETag = Azure::ETag(node.Value);
3822  }
3823  else if (
3824  path.size() == 2 && path[0] == XmlTagName::k_Properties
3825  && path[1] == XmlTagName::k_LastModified)
3826  {
3827  ret.Details.LastModified
3828  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
3829  }
3830  else if (
3831  path.size() == 2 && path[0] == XmlTagName::k_Properties
3832  && path[1] == XmlTagName::k_PublicAccess)
3833  {
3834  ret.Details.AccessType = PublicAccessType(node.Value);
3835  }
3836  else if (
3837  path.size() == 2 && path[0] == XmlTagName::k_Properties
3838  && path[1] == XmlTagName::k_HasImmutabilityPolicy)
3839  {
3840  ret.Details.HasImmutabilityPolicy = std::strcmp(node.Value, "true") == 0;
3841  }
3842  else if (
3843  path.size() == 2 && path[0] == XmlTagName::k_Properties
3844  && path[1] == XmlTagName::k_HasLegalHold)
3845  {
3846  ret.Details.HasLegalHold = std::strcmp(node.Value, "true") == 0;
3847  }
3848  else if (
3849  path.size() == 2 && path[0] == XmlTagName::k_Properties
3850  && path[1] == XmlTagName::k_LeaseStatus)
3851  {
3852  ret.Details.LeaseStatus = LeaseStatus(node.Value);
3853  }
3854  else if (
3855  path.size() == 2 && path[0] == XmlTagName::k_Properties
3856  && path[1] == XmlTagName::k_LeaseState)
3857  {
3858  ret.Details.LeaseState = LeaseState(node.Value);
3859  }
3860  else if (
3861  path.size() == 2 && path[0] == XmlTagName::k_Properties
3862  && path[1] == XmlTagName::k_LeaseDuration)
3863  {
3864  ret.Details.LeaseDuration = LeaseDurationType(node.Value);
3865  }
3866  else if (
3867  path.size() == 2 && path[0] == XmlTagName::k_Properties
3868  && path[1] == XmlTagName::k_DefaultEncryptionScope)
3869  {
3870  ret.Details.DefaultEncryptionScope = node.Value;
3871  }
3872  else if (
3873  path.size() == 2 && path[0] == XmlTagName::k_Properties
3874  && path[1] == XmlTagName::k_DenyEncryptionScopeOverride)
3875  {
3876  ret.Details.PreventEncryptionScopeOverride = std::strcmp(node.Value, "true") == 0;
3877  }
3878  else if (path.size() == 1 && path[0] == XmlTagName::k_Deleted)
3879  {
3880  ret.IsDeleted = std::strcmp(node.Value, "true") == 0;
3881  }
3882  else if (path.size() == 1 && path[0] == XmlTagName::k_Version)
3883  {
3884  ret.VersionId = node.Value;
3885  }
3886  else if (
3887  path.size() == 2 && path[0] == XmlTagName::k_Properties
3888  && path[1] == XmlTagName::k_DeletedTime)
3889  {
3890  ret.Details.DeletedOn
3891  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
3892  }
3893  else if (
3894  path.size() == 2 && path[0] == XmlTagName::k_Properties
3895  && path[1] == XmlTagName::k_RemainingRetentionDays)
3896  {
3897  ret.Details.RemainingRetentionDays = std::stoi(node.Value);
3898  }
3899  }
3900  }
3901  return ret;
3902  }
3903 
3904  static CorsRule CorsRuleFromXml(_internal::XmlReader& reader)
3905  {
3906  CorsRule ret;
3907  enum class XmlTagName
3908  {
3909  k_AllowedOrigins,
3910  k_AllowedMethods,
3911  k_MaxAgeInSeconds,
3912  k_ExposedHeaders,
3913  k_AllowedHeaders,
3914  k_Unknown,
3915  };
3916  std::vector<XmlTagName> path;
3917  while (true)
3918  {
3919  auto node = reader.Read();
3920  if (node.Type == _internal::XmlNodeType::End)
3921  {
3922  break;
3923  }
3924  else if (node.Type == _internal::XmlNodeType::EndTag)
3925  {
3926  if (path.size() > 0)
3927  {
3928  path.pop_back();
3929  }
3930  else
3931  {
3932  break;
3933  }
3934  }
3935  else if (node.Type == _internal::XmlNodeType::StartTag)
3936  {
3937  if (std::strcmp(node.Name, "AllowedOrigins") == 0)
3938  {
3939  path.emplace_back(XmlTagName::k_AllowedOrigins);
3940  }
3941  else if (std::strcmp(node.Name, "AllowedMethods") == 0)
3942  {
3943  path.emplace_back(XmlTagName::k_AllowedMethods);
3944  }
3945  else if (std::strcmp(node.Name, "MaxAgeInSeconds") == 0)
3946  {
3947  path.emplace_back(XmlTagName::k_MaxAgeInSeconds);
3948  }
3949  else if (std::strcmp(node.Name, "ExposedHeaders") == 0)
3950  {
3951  path.emplace_back(XmlTagName::k_ExposedHeaders);
3952  }
3953  else if (std::strcmp(node.Name, "AllowedHeaders") == 0)
3954  {
3955  path.emplace_back(XmlTagName::k_AllowedHeaders);
3956  }
3957  else
3958  {
3959  path.emplace_back(XmlTagName::k_Unknown);
3960  }
3961  }
3962  else if (node.Type == _internal::XmlNodeType::Text)
3963  {
3964  if (path.size() == 1 && path[0] == XmlTagName::k_AllowedOrigins)
3965  {
3966  ret.AllowedOrigins = node.Value;
3967  }
3968  else if (path.size() == 1 && path[0] == XmlTagName::k_AllowedMethods)
3969  {
3970  ret.AllowedMethods = node.Value;
3971  }
3972  else if (path.size() == 1 && path[0] == XmlTagName::k_MaxAgeInSeconds)
3973  {
3974  ret.MaxAgeInSeconds = std::stoi(node.Value);
3975  }
3976  else if (path.size() == 1 && path[0] == XmlTagName::k_ExposedHeaders)
3977  {
3978  ret.ExposedHeaders = node.Value;
3979  }
3980  else if (path.size() == 1 && path[0] == XmlTagName::k_AllowedHeaders)
3981  {
3982  ret.AllowedHeaders = node.Value;
3983  }
3984  }
3985  }
3986  return ret;
3987  }
3988 
3989  static GeoReplication GeoReplicationFromXml(_internal::XmlReader& reader)
3990  {
3991  GeoReplication ret;
3992  enum class XmlTagName
3993  {
3994  k_Status,
3995  k_LastSyncTime,
3996  k_Unknown,
3997  };
3998  std::vector<XmlTagName> path;
3999  while (true)
4000  {
4001  auto node = reader.Read();
4002  if (node.Type == _internal::XmlNodeType::End)
4003  {
4004  break;
4005  }
4006  else if (node.Type == _internal::XmlNodeType::EndTag)
4007  {
4008  if (path.size() > 0)
4009  {
4010  path.pop_back();
4011  }
4012  else
4013  {
4014  break;
4015  }
4016  }
4017  else if (node.Type == _internal::XmlNodeType::StartTag)
4018  {
4019  if (std::strcmp(node.Name, "Status") == 0)
4020  {
4021  path.emplace_back(XmlTagName::k_Status);
4022  }
4023  else if (std::strcmp(node.Name, "LastSyncTime") == 0)
4024  {
4025  path.emplace_back(XmlTagName::k_LastSyncTime);
4026  }
4027  else
4028  {
4029  path.emplace_back(XmlTagName::k_Unknown);
4030  }
4031  }
4032  else if (node.Type == _internal::XmlNodeType::Text)
4033  {
4034  if (path.size() == 1 && path[0] == XmlTagName::k_Status)
4035  {
4036  ret.Status = GeoReplicationStatus(node.Value);
4037  }
4038  else if (path.size() == 1 && path[0] == XmlTagName::k_LastSyncTime)
4039  {
4040  ret.LastSyncedOn
4041  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
4042  }
4043  }
4044  }
4045  return ret;
4046  }
4047 
4048  static Metrics MetricsFromXml(_internal::XmlReader& reader)
4049  {
4050  Metrics ret;
4051  enum class XmlTagName
4052  {
4053  k_Version,
4054  k_Enabled,
4055  k_IncludeAPIs,
4056  k_RetentionPolicy,
4057  k_Unknown,
4058  };
4059  std::vector<XmlTagName> path;
4060  while (true)
4061  {
4062  auto node = reader.Read();
4063  if (node.Type == _internal::XmlNodeType::End)
4064  {
4065  break;
4066  }
4067  else if (node.Type == _internal::XmlNodeType::EndTag)
4068  {
4069  if (path.size() > 0)
4070  {
4071  path.pop_back();
4072  }
4073  else
4074  {
4075  break;
4076  }
4077  }
4078  else if (node.Type == _internal::XmlNodeType::StartTag)
4079  {
4080  if (std::strcmp(node.Name, "Version") == 0)
4081  {
4082  path.emplace_back(XmlTagName::k_Version);
4083  }
4084  else if (std::strcmp(node.Name, "Enabled") == 0)
4085  {
4086  path.emplace_back(XmlTagName::k_Enabled);
4087  }
4088  else if (std::strcmp(node.Name, "IncludeAPIs") == 0)
4089  {
4090  path.emplace_back(XmlTagName::k_IncludeAPIs);
4091  }
4092  else if (std::strcmp(node.Name, "RetentionPolicy") == 0)
4093  {
4094  path.emplace_back(XmlTagName::k_RetentionPolicy);
4095  }
4096  else
4097  {
4098  path.emplace_back(XmlTagName::k_Unknown);
4099  }
4100  if (path.size() == 1 && path[0] == XmlTagName::k_RetentionPolicy)
4101  {
4102  ret.RetentionPolicy = RetentionPolicyFromXml(reader);
4103  path.pop_back();
4104  }
4105  }
4106  else if (node.Type == _internal::XmlNodeType::Text)
4107  {
4108  if (path.size() == 1 && path[0] == XmlTagName::k_Version)
4109  {
4110  ret.Version = node.Value;
4111  }
4112  else if (path.size() == 1 && path[0] == XmlTagName::k_Enabled)
4113  {
4114  ret.IsEnabled = std::strcmp(node.Value, "true") == 0;
4115  }
4116  else if (path.size() == 1 && path[0] == XmlTagName::k_IncludeAPIs)
4117  {
4118  ret.IncludeApis = std::strcmp(node.Value, "true") == 0;
4119  }
4120  }
4121  }
4122  return ret;
4123  }
4124 
4125  static RetentionPolicy RetentionPolicyFromXml(_internal::XmlReader& reader)
4126  {
4127  RetentionPolicy ret;
4128  enum class XmlTagName
4129  {
4130  k_Enabled,
4131  k_Days,
4132  k_Unknown,
4133  };
4134  std::vector<XmlTagName> path;
4135  while (true)
4136  {
4137  auto node = reader.Read();
4138  if (node.Type == _internal::XmlNodeType::End)
4139  {
4140  break;
4141  }
4142  else if (node.Type == _internal::XmlNodeType::EndTag)
4143  {
4144  if (path.size() > 0)
4145  {
4146  path.pop_back();
4147  }
4148  else
4149  {
4150  break;
4151  }
4152  }
4153  else if (node.Type == _internal::XmlNodeType::StartTag)
4154  {
4155  if (std::strcmp(node.Name, "Enabled") == 0)
4156  {
4157  path.emplace_back(XmlTagName::k_Enabled);
4158  }
4159  else if (std::strcmp(node.Name, "Days") == 0)
4160  {
4161  path.emplace_back(XmlTagName::k_Days);
4162  }
4163  else
4164  {
4165  path.emplace_back(XmlTagName::k_Unknown);
4166  }
4167  }
4168  else if (node.Type == _internal::XmlNodeType::Text)
4169  {
4170  if (path.size() == 1 && path[0] == XmlTagName::k_Enabled)
4171  {
4172  ret.IsEnabled = std::strcmp(node.Value, "true") == 0;
4173  }
4174  else if (path.size() == 1 && path[0] == XmlTagName::k_Days)
4175  {
4176  ret.Days = std::stoi(node.Value);
4177  }
4178  }
4179  }
4180  return ret;
4181  }
4182 
4183  static StaticWebsite StaticWebsiteFromXml(_internal::XmlReader& reader)
4184  {
4185  StaticWebsite ret;
4186  enum class XmlTagName
4187  {
4188  k_Enabled,
4189  k_IndexDocument,
4190  k_DefaultIndexDocumentPath,
4191  k_ErrorDocument404Path,
4192  k_Unknown,
4193  };
4194  std::vector<XmlTagName> path;
4195  while (true)
4196  {
4197  auto node = reader.Read();
4198  if (node.Type == _internal::XmlNodeType::End)
4199  {
4200  break;
4201  }
4202  else if (node.Type == _internal::XmlNodeType::EndTag)
4203  {
4204  if (path.size() > 0)
4205  {
4206  path.pop_back();
4207  }
4208  else
4209  {
4210  break;
4211  }
4212  }
4213  else if (node.Type == _internal::XmlNodeType::StartTag)
4214  {
4215  if (std::strcmp(node.Name, "Enabled") == 0)
4216  {
4217  path.emplace_back(XmlTagName::k_Enabled);
4218  }
4219  else if (std::strcmp(node.Name, "IndexDocument") == 0)
4220  {
4221  path.emplace_back(XmlTagName::k_IndexDocument);
4222  }
4223  else if (std::strcmp(node.Name, "DefaultIndexDocumentPath") == 0)
4224  {
4225  path.emplace_back(XmlTagName::k_DefaultIndexDocumentPath);
4226  }
4227  else if (std::strcmp(node.Name, "ErrorDocument404Path") == 0)
4228  {
4229  path.emplace_back(XmlTagName::k_ErrorDocument404Path);
4230  }
4231  else
4232  {
4233  path.emplace_back(XmlTagName::k_Unknown);
4234  }
4235  }
4236  else if (node.Type == _internal::XmlNodeType::Text)
4237  {
4238  if (path.size() == 1 && path[0] == XmlTagName::k_Enabled)
4239  {
4240  ret.IsEnabled = std::strcmp(node.Value, "true") == 0;
4241  }
4242  else if (path.size() == 1 && path[0] == XmlTagName::k_IndexDocument)
4243  {
4244  ret.IndexDocument = node.Value;
4245  }
4246  else if (path.size() == 1 && path[0] == XmlTagName::k_DefaultIndexDocumentPath)
4247  {
4248  ret.DefaultIndexDocumentPath = node.Value;
4249  }
4250  else if (path.size() == 1 && path[0] == XmlTagName::k_ErrorDocument404Path)
4251  {
4252  ret.ErrorDocument404Path = node.Value;
4253  }
4254  }
4255  }
4256  return ret;
4257  }
4258 
4259  static TaggedBlobItem TaggedBlobItemFromXml(_internal::XmlReader& reader)
4260  {
4261  TaggedBlobItem ret;
4262  enum class XmlTagName
4263  {
4264  k_Name,
4265  k_ContainerName,
4266  k_Unknown,
4267  };
4268  std::vector<XmlTagName> path;
4269  while (true)
4270  {
4271  auto node = reader.Read();
4272  if (node.Type == _internal::XmlNodeType::End)
4273  {
4274  break;
4275  }
4276  else if (node.Type == _internal::XmlNodeType::EndTag)
4277  {
4278  if (path.size() > 0)
4279  {
4280  path.pop_back();
4281  }
4282  else
4283  {
4284  break;
4285  }
4286  }
4287  else if (node.Type == _internal::XmlNodeType::StartTag)
4288  {
4289  if (std::strcmp(node.Name, "Name") == 0)
4290  {
4291  path.emplace_back(XmlTagName::k_Name);
4292  }
4293  else if (std::strcmp(node.Name, "ContainerName") == 0)
4294  {
4295  path.emplace_back(XmlTagName::k_ContainerName);
4296  }
4297  else
4298  {
4299  path.emplace_back(XmlTagName::k_Unknown);
4300  }
4301  }
4302  else if (node.Type == _internal::XmlNodeType::Text)
4303  {
4304  if (path.size() == 1 && path[0] == XmlTagName::k_Name)
4305  {
4306  ret.BlobName = node.Value;
4307  }
4308  else if (path.size() == 1 && path[0] == XmlTagName::k_ContainerName)
4309  {
4310  ret.BlobContainerName = node.Value;
4311  }
4312  }
4313  }
4314  return ret;
4315  }
4316 
4317  static Metadata MetadataFromXml(_internal::XmlReader& reader)
4318  {
4319  Metadata ret;
4320  int depth = 0;
4321  std::string key;
4322  while (true)
4323  {
4324  auto node = reader.Read();
4325  if (node.Type == _internal::XmlNodeType::End)
4326  {
4327  break;
4328  }
4329  else if (node.Type == _internal::XmlNodeType::StartTag)
4330  {
4331  if (depth++ == 0)
4332  {
4333  key = node.Name;
4334  }
4335  }
4336  else if (node.Type == _internal::XmlNodeType::EndTag)
4337  {
4338  if (depth-- == 0)
4339  {
4340  break;
4341  }
4342  }
4343  else if (depth == 1 && node.Type == _internal::XmlNodeType::Text)
4344  {
4345  ret.emplace(std::move(key), std::string(node.Value));
4346  }
4347  }
4348  return ret;
4349  }
4350 
4351  static void GetUserDelegationKeyOptionsToXml(
4352  _internal::XmlWriter& writer,
4353  const GetUserDelegationKeyOptions& options)
4354  {
4355  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "KeyInfo"});
4356  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"});
4357  writer.Write(_internal::XmlNode{
4358  _internal::XmlNodeType::Text,
4359  nullptr,
4360  options.StartsOn
4361  .ToString(
4362  Azure::DateTime::DateFormat::Rfc3339,
4363  Azure::DateTime::TimeFractionFormat::Truncate)
4364  .data()});
4365  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4366  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"});
4367  writer.Write(_internal::XmlNode{
4368  _internal::XmlNodeType::Text,
4369  nullptr,
4370  options.ExpiresOn
4371  .ToString(
4372  Azure::DateTime::DateFormat::Rfc3339,
4373  Azure::DateTime::TimeFractionFormat::Truncate)
4374  .data()});
4375  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4376  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4377  }
4378 
4379  static void SetServicePropertiesOptionsToXml(
4380  _internal::XmlWriter& writer,
4381  const SetServicePropertiesOptions& options)
4382  {
4383  writer.Write(
4384  _internal::XmlNode{_internal::XmlNodeType::StartTag, "StorageServiceProperties"});
4385  BlobServicePropertiesToXml(writer, options.Properties);
4386  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4387  }
4388 
4389  static void BlobServicePropertiesToXml(
4390  _internal::XmlWriter& writer,
4391  const BlobServiceProperties& options)
4392  {
4393  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Logging"});
4394  AnalyticsLoggingToXml(writer, options.Logging);
4395  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4396  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "HourMetrics"});
4397  MetricsToXml(writer, options.HourMetrics);
4398  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4399  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "MinuteMetrics"});
4400  MetricsToXml(writer, options.MinuteMetrics);
4401  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4402  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Cors"});
4403  for (const auto& i : options.Cors)
4404  {
4405  CorsRuleToXml(writer, i);
4406  }
4407  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4408  if (options.DefaultServiceVersion.HasValue())
4409  {
4410  writer.Write(
4411  _internal::XmlNode{_internal::XmlNodeType::StartTag, "DefaultServiceVersion"});
4412  writer.Write(_internal::XmlNode{
4413  _internal::XmlNodeType::Text,
4414  nullptr,
4415  options.DefaultServiceVersion.Value().data()});
4416  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4417  }
4418  writer.Write(
4419  _internal::XmlNode{_internal::XmlNodeType::StartTag, "DeleteRetentionPolicy"});
4420  RetentionPolicyToXml(writer, options.DeleteRetentionPolicy);
4421  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4422  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "StaticWebsite"});
4423  StaticWebsiteToXml(writer, options.StaticWebsite);
4424  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4425  }
4426 
4427  static void AnalyticsLoggingToXml(
4428  _internal::XmlWriter& writer,
4429  const AnalyticsLogging& options)
4430  {
4431  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Version"});
4432  writer.Write(
4433  _internal::XmlNode{_internal::XmlNodeType::Text, nullptr, options.Version.data()});
4434  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4435  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Delete"});
4436  writer.Write(_internal::XmlNode{
4437  _internal::XmlNodeType::Text, nullptr, options.Delete ? "true" : "false"});
4438  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4439  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Read"});
4440  writer.Write(_internal::XmlNode{
4441  _internal::XmlNodeType::Text, nullptr, options.Read ? "true" : "false"});
4442  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4443  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Write"});
4444  writer.Write(_internal::XmlNode{
4445  _internal::XmlNodeType::Text, nullptr, options.Write ? "true" : "false"});
4446  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4447  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "RetentionPolicy"});
4448  RetentionPolicyToXml(writer, options.RetentionPolicy);
4449  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4450  }
4451 
4452  static void CorsRuleToXml(_internal::XmlWriter& writer, const CorsRule& options)
4453  {
4454  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "CorsRule"});
4455  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AllowedOrigins"});
4456  writer.Write(_internal::XmlNode{
4457  _internal::XmlNodeType::Text, nullptr, options.AllowedOrigins.data()});
4458  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4459  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AllowedMethods"});
4460  writer.Write(_internal::XmlNode{
4461  _internal::XmlNodeType::Text, nullptr, options.AllowedMethods.data()});
4462  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4463  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AllowedHeaders"});
4464  writer.Write(_internal::XmlNode{
4465  _internal::XmlNodeType::Text, nullptr, options.AllowedHeaders.data()});
4466  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4467  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "ExposedHeaders"});
4468  writer.Write(_internal::XmlNode{
4469  _internal::XmlNodeType::Text, nullptr, options.ExposedHeaders.data()});
4470  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4471  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "MaxAgeInSeconds"});
4472  writer.Write(_internal::XmlNode{
4473  _internal::XmlNodeType::Text,
4474  nullptr,
4475  std::to_string(options.MaxAgeInSeconds).data()});
4476  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4477  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4478  }
4479 
4480  static void MetricsToXml(_internal::XmlWriter& writer, const Metrics& options)
4481  {
4482  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Version"});
4483  writer.Write(
4484  _internal::XmlNode{_internal::XmlNodeType::Text, nullptr, options.Version.data()});
4485  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4486  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Enabled"});
4487  writer.Write(_internal::XmlNode{
4488  _internal::XmlNodeType::Text, nullptr, options.IsEnabled ? "true" : "false"});
4489  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4490  if (options.IncludeApis.HasValue())
4491  {
4492  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "IncludeAPIs"});
4493  writer.Write(_internal::XmlNode{
4494  _internal::XmlNodeType::Text,
4495  nullptr,
4496  options.IncludeApis.Value() ? "true" : "false"});
4497  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4498  }
4499  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "RetentionPolicy"});
4500  RetentionPolicyToXml(writer, options.RetentionPolicy);
4501  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4502  }
4503 
4504  static void RetentionPolicyToXml(
4505  _internal::XmlWriter& writer,
4506  const RetentionPolicy& options)
4507  {
4508  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Enabled"});
4509  writer.Write(_internal::XmlNode{
4510  _internal::XmlNodeType::Text, nullptr, options.IsEnabled ? "true" : "false"});
4511  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4512  if (options.Days.HasValue())
4513  {
4514  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Days"});
4515  writer.Write(_internal::XmlNode{
4516  _internal::XmlNodeType::Text,
4517  nullptr,
4518  std::to_string(options.Days.Value()).data()});
4519  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4520  }
4521  }
4522 
4523  static void StaticWebsiteToXml(_internal::XmlWriter& writer, const StaticWebsite& options)
4524  {
4525  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Enabled"});
4526  writer.Write(_internal::XmlNode{
4527  _internal::XmlNodeType::Text, nullptr, options.IsEnabled ? "true" : "false"});
4528  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4529  if (options.IndexDocument.HasValue())
4530  {
4531  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "IndexDocument"});
4532  writer.Write(_internal::XmlNode{
4533  _internal::XmlNodeType::Text, nullptr, options.IndexDocument.Value().data()});
4534  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4535  }
4536  if (options.DefaultIndexDocumentPath.HasValue())
4537  {
4538  writer.Write(
4539  _internal::XmlNode{_internal::XmlNodeType::StartTag, "DefaultIndexDocumentPath"});
4540  writer.Write(_internal::XmlNode{
4541  _internal::XmlNodeType::Text,
4542  nullptr,
4543  options.DefaultIndexDocumentPath.Value().data()});
4544  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4545  }
4546  if (options.ErrorDocument404Path.HasValue())
4547  {
4548  writer.Write(
4549  _internal::XmlNode{_internal::XmlNodeType::StartTag, "ErrorDocument404Path"});
4550  writer.Write(_internal::XmlNode{
4551  _internal::XmlNodeType::Text,
4552  nullptr,
4553  options.ErrorDocument404Path.Value().data()});
4554  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
4555  }
4556  }
4557 
4558  }; // class Service
4559 
4560  class BlobContainer final {
4561  public:
4562  struct CreateBlobContainerOptions final
4563  {
4564  Azure::Nullable<int32_t> Timeout;
4565  PublicAccessType AccessType = PublicAccessType::None;
4566  Storage::Metadata Metadata;
4567  Azure::Nullable<std::string> DefaultEncryptionScope;
4568  Azure::Nullable<bool> PreventEncryptionScopeOverride;
4569  }; // struct CreateBlobContainerOptions
4570 
4571  static Azure::Response<CreateBlobContainerResult> Create(
4572  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4573  const Azure::Core::Url& url,
4574  const CreateBlobContainerOptions& options,
4575  const Azure::Core::Context& context)
4576  {
4577  (void)options;
4578  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
4579  request.SetHeader("Content-Length", "0");
4580  request.GetUrl().AppendQueryParameter("restype", "container");
4581  request.SetHeader("x-ms-version", "2020-02-10");
4582  if (options.Timeout.HasValue())
4583  {
4584  request.GetUrl().AppendQueryParameter(
4585  "timeout", std::to_string(options.Timeout.Value()));
4586  }
4587  for (const auto& pair : options.Metadata)
4588  {
4589  request.SetHeader("x-ms-meta-" + pair.first, pair.second);
4590  }
4591  if (!options.AccessType.ToString().empty())
4592  {
4593  request.SetHeader("x-ms-blob-public-access", options.AccessType.ToString());
4594  }
4595  if (options.DefaultEncryptionScope.HasValue())
4596  {
4597  request.SetHeader(
4598  "x-ms-default-encryption-scope", options.DefaultEncryptionScope.Value());
4599  }
4600  if (options.PreventEncryptionScopeOverride.HasValue())
4601  {
4602  request.SetHeader(
4603  "x-ms-deny-encryption-scope-override",
4604  options.PreventEncryptionScopeOverride.Value() ? "true" : "false");
4605  }
4606  auto pHttpResponse = pipeline.Send(request, context);
4607  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4608  CreateBlobContainerResult response;
4609  auto http_status_code
4610  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4611  httpResponse.GetStatusCode());
4612  if (!(http_status_code == 201))
4613  {
4614  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4615  }
4616  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
4617  response.LastModified = Azure::DateTime::Parse(
4618  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
4619  return Azure::Response<CreateBlobContainerResult>(
4620  std::move(response), std::move(pHttpResponse));
4621  }
4622 
4623  struct DeleteBlobContainerOptions final
4624  {
4625  Azure::Nullable<int32_t> Timeout;
4626  Azure::Nullable<std::string> LeaseId;
4627  Azure::Nullable<Azure::DateTime> IfModifiedSince;
4628  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
4629  }; // struct DeleteBlobContainerOptions
4630 
4631  static Azure::Response<DeleteBlobContainerResult> Delete(
4632  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4633  const Azure::Core::Url& url,
4634  const DeleteBlobContainerOptions& options,
4635  const Azure::Core::Context& context)
4636  {
4637  (void)options;
4638  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Delete, url);
4639  request.GetUrl().AppendQueryParameter("restype", "container");
4640  request.SetHeader("x-ms-version", "2020-02-10");
4641  if (options.Timeout.HasValue())
4642  {
4643  request.GetUrl().AppendQueryParameter(
4644  "timeout", std::to_string(options.Timeout.Value()));
4645  }
4646  if (options.LeaseId.HasValue())
4647  {
4648  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
4649  }
4650  if (options.IfModifiedSince.HasValue())
4651  {
4652  request.SetHeader(
4653  "If-Modified-Since",
4654  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
4655  }
4656  if (options.IfUnmodifiedSince.HasValue())
4657  {
4658  request.SetHeader(
4659  "If-Unmodified-Since",
4660  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
4661  }
4662  auto pHttpResponse = pipeline.Send(request, context);
4663  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4664  DeleteBlobContainerResult response;
4665  auto http_status_code
4666  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4667  httpResponse.GetStatusCode());
4668  if (!(http_status_code == 202))
4669  {
4670  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4671  }
4672  return Azure::Response<DeleteBlobContainerResult>(
4673  std::move(response), std::move(pHttpResponse));
4674  }
4675 
4676  struct UndeleteBlobContainerOptions final
4677  {
4678  Azure::Nullable<int32_t> Timeout;
4679  std::string DeletedBlobContainerName;
4680  std::string DeletedBlobContainerVersion;
4681  }; // struct UndeleteBlobContainerOptions
4682 
4683  static Azure::Response<Models::_detail::UndeleteBlobContainerResult> Undelete(
4684  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4685  const Azure::Core::Url& url,
4686  const UndeleteBlobContainerOptions& options,
4687  const Azure::Core::Context& context)
4688  {
4689  (void)options;
4690  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
4691  request.SetHeader("Content-Length", "0");
4692  request.GetUrl().AppendQueryParameter("restype", "container");
4693  request.GetUrl().AppendQueryParameter("comp", "undelete");
4694  request.SetHeader("x-ms-version", "2020-02-10");
4695  if (options.Timeout.HasValue())
4696  {
4697  request.GetUrl().AppendQueryParameter(
4698  "timeout", std::to_string(options.Timeout.Value()));
4699  }
4700  request.SetHeader("x-ms-deleted-container-name", options.DeletedBlobContainerName);
4701  request.SetHeader("x-ms-deleted-container-version", options.DeletedBlobContainerVersion);
4702  auto pHttpResponse = pipeline.Send(request, context);
4703  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4704  Models::_detail::UndeleteBlobContainerResult response;
4705  auto http_status_code
4706  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4707  httpResponse.GetStatusCode());
4708  if (!(http_status_code == 201))
4709  {
4710  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4711  }
4712  return Azure::Response<Models::_detail::UndeleteBlobContainerResult>(
4713  std::move(response), std::move(pHttpResponse));
4714  }
4715 
4716  struct GetBlobContainerPropertiesOptions final
4717  {
4718  Azure::Nullable<int32_t> Timeout;
4719  Azure::Nullable<std::string> LeaseId;
4720  }; // struct GetBlobContainerPropertiesOptions
4721 
4722  static Azure::Response<BlobContainerProperties> GetProperties(
4723  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4724  const Azure::Core::Url& url,
4725  const GetBlobContainerPropertiesOptions& options,
4726  const Azure::Core::Context& context)
4727  {
4728  (void)options;
4729  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Head, url);
4730  request.GetUrl().AppendQueryParameter("restype", "container");
4731  request.SetHeader("x-ms-version", "2020-02-10");
4732  if (options.Timeout.HasValue())
4733  {
4734  request.GetUrl().AppendQueryParameter(
4735  "timeout", std::to_string(options.Timeout.Value()));
4736  }
4737  if (options.LeaseId.HasValue())
4738  {
4739  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
4740  }
4741  auto pHttpResponse = pipeline.Send(request, context);
4742  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4743  BlobContainerProperties response;
4744  auto http_status_code
4745  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4746  httpResponse.GetStatusCode());
4747  if (!(http_status_code == 200))
4748  {
4749  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4750  }
4751  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
4752  response.LastModified = Azure::DateTime::Parse(
4753  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
4754  for (auto i = httpResponse.GetHeaders().lower_bound("x-ms-meta-");
4755  i != httpResponse.GetHeaders().end() && i->first.substr(0, 10) == "x-ms-meta-";
4756  ++i)
4757  {
4758  response.Metadata.emplace(i->first.substr(10), i->second);
4759  }
4760  auto x_ms_blob_public_access__iterator
4761  = httpResponse.GetHeaders().find("x-ms-blob-public-access");
4762  if (x_ms_blob_public_access__iterator != httpResponse.GetHeaders().end())
4763  {
4764  response.AccessType = PublicAccessType(x_ms_blob_public_access__iterator->second);
4765  }
4766  response.HasImmutabilityPolicy
4767  = httpResponse.GetHeaders().at("x-ms-has-immutability-policy") == "true";
4768  response.HasLegalHold = httpResponse.GetHeaders().at("x-ms-has-legal-hold") == "true";
4769  response.LeaseStatus = LeaseStatus(httpResponse.GetHeaders().at("x-ms-lease-status"));
4770  response.LeaseState = LeaseState(httpResponse.GetHeaders().at("x-ms-lease-state"));
4771  auto x_ms_lease_duration__iterator
4772  = httpResponse.GetHeaders().find("x-ms-lease-duration");
4773  if (x_ms_lease_duration__iterator != httpResponse.GetHeaders().end())
4774  {
4775  response.LeaseDuration = LeaseDurationType(x_ms_lease_duration__iterator->second);
4776  }
4777  response.DefaultEncryptionScope
4778  = httpResponse.GetHeaders().at("x-ms-default-encryption-scope");
4779  response.PreventEncryptionScopeOverride
4780  = httpResponse.GetHeaders().at("x-ms-deny-encryption-scope-override") == "true";
4781  return Azure::Response<BlobContainerProperties>(
4782  std::move(response), std::move(pHttpResponse));
4783  }
4784 
4785  struct SetBlobContainerMetadataOptions final
4786  {
4787  Azure::Nullable<int32_t> Timeout;
4788  Storage::Metadata Metadata;
4789  Azure::Nullable<std::string> LeaseId;
4790  Azure::Nullable<Azure::DateTime> IfModifiedSince;
4791  }; // struct SetBlobContainerMetadataOptions
4792 
4793  static Azure::Response<SetBlobContainerMetadataResult> SetMetadata(
4794  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4795  const Azure::Core::Url& url,
4796  const SetBlobContainerMetadataOptions& options,
4797  const Azure::Core::Context& context)
4798  {
4799  (void)options;
4800  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
4801  request.SetHeader("Content-Length", "0");
4802  request.GetUrl().AppendQueryParameter("restype", "container");
4803  request.GetUrl().AppendQueryParameter("comp", "metadata");
4804  request.SetHeader("x-ms-version", "2020-02-10");
4805  if (options.Timeout.HasValue())
4806  {
4807  request.GetUrl().AppendQueryParameter(
4808  "timeout", std::to_string(options.Timeout.Value()));
4809  }
4810  for (const auto& pair : options.Metadata)
4811  {
4812  request.SetHeader("x-ms-meta-" + pair.first, pair.second);
4813  }
4814  if (options.LeaseId.HasValue())
4815  {
4816  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
4817  }
4818  if (options.IfModifiedSince.HasValue())
4819  {
4820  request.SetHeader(
4821  "If-Modified-Since",
4822  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
4823  }
4824  auto pHttpResponse = pipeline.Send(request, context);
4825  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4826  SetBlobContainerMetadataResult response;
4827  auto http_status_code
4828  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4829  httpResponse.GetStatusCode());
4830  if (!(http_status_code == 200))
4831  {
4832  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4833  }
4834  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
4835  response.LastModified = Azure::DateTime::Parse(
4836  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
4837  return Azure::Response<SetBlobContainerMetadataResult>(
4838  std::move(response), std::move(pHttpResponse));
4839  }
4840 
4841  struct ListBlobsOptions final
4842  {
4843  Azure::Nullable<int32_t> Timeout;
4844  Azure::Nullable<std::string> Prefix;
4845  Azure::Nullable<std::string> ContinuationToken;
4846  Azure::Nullable<int32_t> MaxResults;
4847  ListBlobsIncludeFlags Include = ListBlobsIncludeFlags::None;
4848  }; // struct ListBlobsOptions
4849 
4850  static Azure::Response<Models::_detail::ListBlobsResult> ListBlobs(
4851  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4852  const Azure::Core::Url& url,
4853  const ListBlobsOptions& options,
4854  const Azure::Core::Context& context)
4855  {
4856  (void)options;
4857  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
4858  request.SetHeader("x-ms-version", "2020-02-10");
4859  if (options.Timeout.HasValue())
4860  {
4861  request.GetUrl().AppendQueryParameter(
4862  "timeout", std::to_string(options.Timeout.Value()));
4863  }
4864  request.GetUrl().AppendQueryParameter("restype", "container");
4865  request.GetUrl().AppendQueryParameter("comp", "list");
4866  if (options.Prefix.HasValue())
4867  {
4868  request.GetUrl().AppendQueryParameter(
4869  "prefix", _internal::UrlEncodeQueryParameter(options.Prefix.Value()));
4870  }
4871  if (options.ContinuationToken.HasValue())
4872  {
4873  request.GetUrl().AppendQueryParameter(
4874  "marker", _internal::UrlEncodeQueryParameter(options.ContinuationToken.Value()));
4875  }
4876  if (options.MaxResults.HasValue())
4877  {
4878  request.GetUrl().AppendQueryParameter(
4879  "maxresults", std::to_string(options.MaxResults.Value()));
4880  }
4881  std::string list_blobs_include_flags = ListBlobsIncludeFlagsToString(options.Include);
4882  if (!list_blobs_include_flags.empty())
4883  {
4884  request.GetUrl().AppendQueryParameter(
4885  "include", _internal::UrlEncodeQueryParameter(list_blobs_include_flags));
4886  }
4887  auto pHttpResponse = pipeline.Send(request, context);
4888  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4889  Models::_detail::ListBlobsResult response;
4890  auto http_status_code
4891  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4892  httpResponse.GetStatusCode());
4893  if (!(http_status_code == 200))
4894  {
4895  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4896  }
4897  {
4898  const auto& httpResponseBody = httpResponse.GetBody();
4899  _internal::XmlReader reader(
4900  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
4901  response = ListBlobsResultInternalFromXml(reader);
4902  }
4903  return Azure::Response<Models::_detail::ListBlobsResult>(
4904  std::move(response), std::move(pHttpResponse));
4905  }
4906 
4907  struct ListBlobsByHierarchyOptions final
4908  {
4909  Azure::Nullable<int32_t> Timeout;
4910  Azure::Nullable<std::string> Prefix;
4911  Azure::Nullable<std::string> Delimiter;
4912  Azure::Nullable<std::string> ContinuationToken;
4913  Azure::Nullable<int32_t> MaxResults;
4914  ListBlobsIncludeFlags Include = ListBlobsIncludeFlags::None;
4915  }; // struct ListBlobsByHierarchyOptions
4916 
4917  static Azure::Response<Models::_detail::ListBlobsByHierarchyResult> ListBlobsByHierarchy(
4918  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4919  const Azure::Core::Url& url,
4920  const ListBlobsByHierarchyOptions& options,
4921  const Azure::Core::Context& context)
4922  {
4923  (void)options;
4924  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
4925  request.SetHeader("x-ms-version", "2020-02-10");
4926  if (options.Timeout.HasValue())
4927  {
4928  request.GetUrl().AppendQueryParameter(
4929  "timeout", std::to_string(options.Timeout.Value()));
4930  }
4931  request.GetUrl().AppendQueryParameter("restype", "container");
4932  request.GetUrl().AppendQueryParameter("comp", "list");
4933  if (options.Prefix.HasValue())
4934  {
4935  request.GetUrl().AppendQueryParameter(
4936  "prefix", _internal::UrlEncodeQueryParameter(options.Prefix.Value()));
4937  }
4938  if (options.Delimiter.HasValue())
4939  {
4940  request.GetUrl().AppendQueryParameter(
4941  "delimiter", _internal::UrlEncodeQueryParameter(options.Delimiter.Value()));
4942  }
4943  if (options.ContinuationToken.HasValue())
4944  {
4945  request.GetUrl().AppendQueryParameter(
4946  "marker", _internal::UrlEncodeQueryParameter(options.ContinuationToken.Value()));
4947  }
4948  if (options.MaxResults.HasValue())
4949  {
4950  request.GetUrl().AppendQueryParameter(
4951  "maxresults", std::to_string(options.MaxResults.Value()));
4952  }
4953  std::string list_blobs_include_flags = ListBlobsIncludeFlagsToString(options.Include);
4954  if (!list_blobs_include_flags.empty())
4955  {
4956  request.GetUrl().AppendQueryParameter(
4957  "include", _internal::UrlEncodeQueryParameter(list_blobs_include_flags));
4958  }
4959  auto pHttpResponse = pipeline.Send(request, context);
4960  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
4961  Models::_detail::ListBlobsByHierarchyResult response;
4962  auto http_status_code
4963  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
4964  httpResponse.GetStatusCode());
4965  if (!(http_status_code == 200))
4966  {
4967  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
4968  }
4969  {
4970  const auto& httpResponseBody = httpResponse.GetBody();
4971  _internal::XmlReader reader(
4972  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
4973  response = ListBlobsByHierarchyResultInternalFromXml(reader);
4974  }
4975  return Azure::Response<Models::_detail::ListBlobsByHierarchyResult>(
4976  std::move(response), std::move(pHttpResponse));
4977  }
4978 
4979  struct GetBlobContainerAccessPolicyOptions final
4980  {
4981  Azure::Nullable<int32_t> Timeout;
4982  Azure::Nullable<std::string> LeaseId;
4983  }; // struct GetBlobContainerAccessPolicyOptions
4984 
4985  static Azure::Response<BlobContainerAccessPolicy> GetAccessPolicy(
4986  Azure::Core::Http::_internal::HttpPipeline& pipeline,
4987  const Azure::Core::Url& url,
4988  const GetBlobContainerAccessPolicyOptions& options,
4989  const Azure::Core::Context& context)
4990  {
4991  (void)options;
4992  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
4993  request.SetHeader("x-ms-version", "2020-02-10");
4994  if (options.Timeout.HasValue())
4995  {
4996  request.GetUrl().AppendQueryParameter(
4997  "timeout", std::to_string(options.Timeout.Value()));
4998  }
4999  request.GetUrl().AppendQueryParameter("restype", "container");
5000  request.GetUrl().AppendQueryParameter("comp", "acl");
5001  auto pHttpResponse = pipeline.Send(request, context);
5002  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5003  BlobContainerAccessPolicy response;
5004  auto http_status_code
5005  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5006  httpResponse.GetStatusCode());
5007  if (!(http_status_code == 200))
5008  {
5009  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5010  }
5011  {
5012  const auto& httpResponseBody = httpResponse.GetBody();
5013  _internal::XmlReader reader(
5014  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
5015  response = BlobContainerAccessPolicyFromXml(reader);
5016  }
5017  auto x_ms_blob_public_access__iterator
5018  = httpResponse.GetHeaders().find("x-ms-blob-public-access");
5019  if (x_ms_blob_public_access__iterator != httpResponse.GetHeaders().end())
5020  {
5021  response.AccessType = PublicAccessType(x_ms_blob_public_access__iterator->second);
5022  }
5023  return Azure::Response<BlobContainerAccessPolicy>(
5024  std::move(response), std::move(pHttpResponse));
5025  }
5026 
5027  struct SetBlobContainerAccessPolicyOptions final
5028  {
5029  Azure::Nullable<int32_t> Timeout;
5030  PublicAccessType AccessType = PublicAccessType::None;
5031  Azure::Nullable<std::string> LeaseId;
5032  Azure::Nullable<Azure::DateTime> IfModifiedSince;
5033  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
5034  std::vector<SignedIdentifier> SignedIdentifiers;
5035  }; // struct SetBlobContainerAccessPolicyOptions
5036 
5037  static Azure::Response<SetBlobContainerAccessPolicyResult> SetAccessPolicy(
5038  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5039  const Azure::Core::Url& url,
5040  const SetBlobContainerAccessPolicyOptions& options,
5041  const Azure::Core::Context& context)
5042  {
5043  (void)options;
5044  std::string xml_body;
5045  {
5046  _internal::XmlWriter writer;
5047  SetBlobContainerAccessPolicyOptionsToXml(writer, options);
5048  xml_body = writer.GetDocument();
5049  writer.Write(_internal::XmlNode{_internal::XmlNodeType::End});
5050  }
5051  Azure::Core::IO::MemoryBodyStream xml_body_stream(
5052  reinterpret_cast<const uint8_t*>(xml_body.data()), xml_body.length());
5053  auto request = Azure::Core::Http::Request(
5054  Azure::Core::Http::HttpMethod::Put, url, &xml_body_stream);
5055  request.SetHeader("Content-Length", std::to_string(xml_body_stream.Length()));
5056  request.SetHeader("x-ms-version", "2020-02-10");
5057  if (options.Timeout.HasValue())
5058  {
5059  request.GetUrl().AppendQueryParameter(
5060  "timeout", std::to_string(options.Timeout.Value()));
5061  }
5062  request.GetUrl().AppendQueryParameter("restype", "container");
5063  request.GetUrl().AppendQueryParameter("comp", "acl");
5064  if (!options.AccessType.ToString().empty())
5065  {
5066  request.SetHeader("x-ms-blob-public-access", options.AccessType.ToString());
5067  }
5068  if (options.LeaseId.HasValue())
5069  {
5070  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
5071  }
5072  if (options.IfModifiedSince.HasValue())
5073  {
5074  request.SetHeader(
5075  "If-Modified-Since",
5076  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5077  }
5078  if (options.IfUnmodifiedSince.HasValue())
5079  {
5080  request.SetHeader(
5081  "If-Unmodified-Since",
5082  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5083  }
5084  auto pHttpResponse = pipeline.Send(request, context);
5085  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5086  SetBlobContainerAccessPolicyResult response;
5087  auto http_status_code
5088  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5089  httpResponse.GetStatusCode());
5090  if (!(http_status_code == 200))
5091  {
5092  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5093  }
5094  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
5095  response.LastModified = Azure::DateTime::Parse(
5096  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
5097  return Azure::Response<SetBlobContainerAccessPolicyResult>(
5098  std::move(response), std::move(pHttpResponse));
5099  }
5100 
5101  struct AcquireBlobContainerLeaseOptions final
5102  {
5103  Azure::Nullable<int32_t> Timeout;
5104  std::chrono::seconds LeaseDuration;
5105  Azure::Nullable<std::string> ProposedLeaseId;
5106  Azure::Nullable<Azure::DateTime> IfModifiedSince;
5107  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
5108  }; // struct AcquireBlobContainerLeaseOptions
5109 
5110  static Azure::Response<Models::_detail::AcquireBlobContainerLeaseResult> AcquireLease(
5111  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5112  const Azure::Core::Url& url,
5113  const AcquireBlobContainerLeaseOptions& options,
5114  const Azure::Core::Context& context)
5115  {
5116  (void)options;
5117  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
5118  request.SetHeader("Content-Length", "0");
5119  request.SetHeader("x-ms-version", "2020-02-10");
5120  if (options.Timeout.HasValue())
5121  {
5122  request.GetUrl().AppendQueryParameter(
5123  "timeout", std::to_string(options.Timeout.Value()));
5124  }
5125  request.GetUrl().AppendQueryParameter("restype", "container");
5126  request.GetUrl().AppendQueryParameter("comp", "lease");
5127  request.SetHeader("x-ms-lease-action", "acquire");
5128  request.SetHeader("x-ms-lease-duration", std::to_string(options.LeaseDuration.count()));
5129  if (options.ProposedLeaseId.HasValue())
5130  {
5131  request.SetHeader("x-ms-proposed-lease-id", options.ProposedLeaseId.Value());
5132  }
5133  if (options.IfModifiedSince.HasValue())
5134  {
5135  request.SetHeader(
5136  "If-Modified-Since",
5137  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5138  }
5139  if (options.IfUnmodifiedSince.HasValue())
5140  {
5141  request.SetHeader(
5142  "If-Unmodified-Since",
5143  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5144  }
5145  auto pHttpResponse = pipeline.Send(request, context);
5146  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5147  Models::_detail::AcquireBlobContainerLeaseResult response;
5148  auto http_status_code
5149  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5150  httpResponse.GetStatusCode());
5151  if (!(http_status_code == 201))
5152  {
5153  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5154  }
5155  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
5156  response.LastModified = Azure::DateTime::Parse(
5157  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
5158  response.LeaseId = httpResponse.GetHeaders().at("x-ms-lease-id");
5159  return Azure::Response<Models::_detail::AcquireBlobContainerLeaseResult>(
5160  std::move(response), std::move(pHttpResponse));
5161  }
5162 
5163  struct RenewBlobContainerLeaseOptions final
5164  {
5165  Azure::Nullable<int32_t> Timeout;
5166  std::string LeaseId;
5167  Azure::Nullable<Azure::DateTime> IfModifiedSince;
5168  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
5169  }; // struct RenewBlobContainerLeaseOptions
5170 
5171  static Azure::Response<Models::_detail::RenewBlobContainerLeaseResult> RenewLease(
5172  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5173  const Azure::Core::Url& url,
5174  const RenewBlobContainerLeaseOptions& options,
5175  const Azure::Core::Context& context)
5176  {
5177  (void)options;
5178  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
5179  request.SetHeader("Content-Length", "0");
5180  request.SetHeader("x-ms-version", "2020-02-10");
5181  if (options.Timeout.HasValue())
5182  {
5183  request.GetUrl().AppendQueryParameter(
5184  "timeout", std::to_string(options.Timeout.Value()));
5185  }
5186  request.GetUrl().AppendQueryParameter("restype", "container");
5187  request.GetUrl().AppendQueryParameter("comp", "lease");
5188  request.SetHeader("x-ms-lease-action", "renew");
5189  request.SetHeader("x-ms-lease-id", options.LeaseId);
5190  if (options.IfModifiedSince.HasValue())
5191  {
5192  request.SetHeader(
5193  "If-Modified-Since",
5194  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5195  }
5196  if (options.IfUnmodifiedSince.HasValue())
5197  {
5198  request.SetHeader(
5199  "If-Unmodified-Since",
5200  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5201  }
5202  auto pHttpResponse = pipeline.Send(request, context);
5203  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5204  Models::_detail::RenewBlobContainerLeaseResult response;
5205  auto http_status_code
5206  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5207  httpResponse.GetStatusCode());
5208  if (!(http_status_code == 200))
5209  {
5210  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5211  }
5212  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
5213  response.LastModified = Azure::DateTime::Parse(
5214  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
5215  response.LeaseId = httpResponse.GetHeaders().at("x-ms-lease-id");
5216  return Azure::Response<Models::_detail::RenewBlobContainerLeaseResult>(
5217  std::move(response), std::move(pHttpResponse));
5218  }
5219 
5220  struct ChangeBlobContainerLeaseOptions final
5221  {
5222  Azure::Nullable<int32_t> Timeout;
5223  std::string LeaseId;
5224  std::string ProposedLeaseId;
5225  Azure::Nullable<Azure::DateTime> IfModifiedSince;
5226  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
5227  }; // struct ChangeBlobContainerLeaseOptions
5228 
5229  static Azure::Response<Models::_detail::ChangeBlobContainerLeaseResult> ChangeLease(
5230  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5231  const Azure::Core::Url& url,
5232  const ChangeBlobContainerLeaseOptions& options,
5233  const Azure::Core::Context& context)
5234  {
5235  (void)options;
5236  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
5237  request.SetHeader("Content-Length", "0");
5238  request.SetHeader("x-ms-version", "2020-02-10");
5239  if (options.Timeout.HasValue())
5240  {
5241  request.GetUrl().AppendQueryParameter(
5242  "timeout", std::to_string(options.Timeout.Value()));
5243  }
5244  request.GetUrl().AppendQueryParameter("restype", "container");
5245  request.GetUrl().AppendQueryParameter("comp", "lease");
5246  request.SetHeader("x-ms-lease-action", "change");
5247  request.SetHeader("x-ms-lease-id", options.LeaseId);
5248  request.SetHeader("x-ms-proposed-lease-id", options.ProposedLeaseId);
5249  if (options.IfModifiedSince.HasValue())
5250  {
5251  request.SetHeader(
5252  "If-Modified-Since",
5253  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5254  }
5255  if (options.IfUnmodifiedSince.HasValue())
5256  {
5257  request.SetHeader(
5258  "If-Unmodified-Since",
5259  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5260  }
5261  auto pHttpResponse = pipeline.Send(request, context);
5262  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5263  Models::_detail::ChangeBlobContainerLeaseResult response;
5264  auto http_status_code
5265  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5266  httpResponse.GetStatusCode());
5267  if (!(http_status_code == 200))
5268  {
5269  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5270  }
5271  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
5272  response.LastModified = Azure::DateTime::Parse(
5273  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
5274  response.LeaseId = httpResponse.GetHeaders().at("x-ms-lease-id");
5275  return Azure::Response<Models::_detail::ChangeBlobContainerLeaseResult>(
5276  std::move(response), std::move(pHttpResponse));
5277  }
5278 
5279  struct ReleaseBlobContainerLeaseOptions final
5280  {
5281  Azure::Nullable<int32_t> Timeout;
5282  std::string LeaseId;
5283  Azure::Nullable<Azure::DateTime> IfModifiedSince;
5284  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
5285  }; // struct ReleaseBlobContainerLeaseOptions
5286 
5287  static Azure::Response<Models::_detail::ReleaseBlobContainerLeaseResult> ReleaseLease(
5288  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5289  const Azure::Core::Url& url,
5290  const ReleaseBlobContainerLeaseOptions& options,
5291  const Azure::Core::Context& context)
5292  {
5293  (void)options;
5294  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
5295  request.SetHeader("Content-Length", "0");
5296  request.SetHeader("x-ms-version", "2020-02-10");
5297  if (options.Timeout.HasValue())
5298  {
5299  request.GetUrl().AppendQueryParameter(
5300  "timeout", std::to_string(options.Timeout.Value()));
5301  }
5302  request.GetUrl().AppendQueryParameter("restype", "container");
5303  request.GetUrl().AppendQueryParameter("comp", "lease");
5304  request.SetHeader("x-ms-lease-action", "release");
5305  request.SetHeader("x-ms-lease-id", options.LeaseId);
5306  if (options.IfModifiedSince.HasValue())
5307  {
5308  request.SetHeader(
5309  "If-Modified-Since",
5310  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5311  }
5312  if (options.IfUnmodifiedSince.HasValue())
5313  {
5314  request.SetHeader(
5315  "If-Unmodified-Since",
5316  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5317  }
5318  auto pHttpResponse = pipeline.Send(request, context);
5319  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5320  Models::_detail::ReleaseBlobContainerLeaseResult response;
5321  auto http_status_code
5322  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5323  httpResponse.GetStatusCode());
5324  if (!(http_status_code == 200))
5325  {
5326  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5327  }
5328  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
5329  response.LastModified = Azure::DateTime::Parse(
5330  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
5331  return Azure::Response<Models::_detail::ReleaseBlobContainerLeaseResult>(
5332  std::move(response), std::move(pHttpResponse));
5333  }
5334 
5335  struct BreakBlobContainerLeaseOptions final
5336  {
5337  Azure::Nullable<int32_t> Timeout;
5338  Azure::Nullable<std::chrono::seconds> BreakPeriod;
5339  Azure::Nullable<Azure::DateTime> IfModifiedSince;
5340  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
5341  }; // struct BreakBlobContainerLeaseOptions
5342 
5343  static Azure::Response<Models::_detail::BreakBlobContainerLeaseResult> BreakLease(
5344  Azure::Core::Http::_internal::HttpPipeline& pipeline,
5345  const Azure::Core::Url& url,
5346  const BreakBlobContainerLeaseOptions& options,
5347  const Azure::Core::Context& context)
5348  {
5349  (void)options;
5350  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
5351  request.SetHeader("Content-Length", "0");
5352  request.SetHeader("x-ms-version", "2020-02-10");
5353  if (options.Timeout.HasValue())
5354  {
5355  request.GetUrl().AppendQueryParameter(
5356  "timeout", std::to_string(options.Timeout.Value()));
5357  }
5358  request.GetUrl().AppendQueryParameter("restype", "container");
5359  request.GetUrl().AppendQueryParameter("comp", "lease");
5360  request.SetHeader("x-ms-lease-action", "break");
5361  if (options.BreakPeriod.HasValue())
5362  {
5363  request.SetHeader(
5364  "x-ms-lease-break-period", std::to_string(options.BreakPeriod.Value().count()));
5365  }
5366  if (options.IfModifiedSince.HasValue())
5367  {
5368  request.SetHeader(
5369  "If-Modified-Since",
5370  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5371  }
5372  if (options.IfUnmodifiedSince.HasValue())
5373  {
5374  request.SetHeader(
5375  "If-Unmodified-Since",
5376  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
5377  }
5378  auto pHttpResponse = pipeline.Send(request, context);
5379  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
5380  Models::_detail::BreakBlobContainerLeaseResult response;
5381  auto http_status_code
5382  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
5383  httpResponse.GetStatusCode());
5384  if (!(http_status_code == 202))
5385  {
5386  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
5387  }
5388  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
5389  response.LastModified = Azure::DateTime::Parse(
5390  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
5391  response.LeaseTime = std::stoi(httpResponse.GetHeaders().at("x-ms-lease-time"));
5392  return Azure::Response<Models::_detail::BreakBlobContainerLeaseResult>(
5393  std::move(response), std::move(pHttpResponse));
5394  }
5395 
5396  private:
5397  static BlobContainerAccessPolicy BlobContainerAccessPolicyFromXml(
5398  _internal::XmlReader& reader)
5399  {
5400  BlobContainerAccessPolicy ret;
5401  enum class XmlTagName
5402  {
5403  k_SignedIdentifiers,
5404  k_SignedIdentifier,
5405  k_Unknown,
5406  };
5407  std::vector<XmlTagName> path;
5408  while (true)
5409  {
5410  auto node = reader.Read();
5411  if (node.Type == _internal::XmlNodeType::End)
5412  {
5413  break;
5414  }
5415  else if (node.Type == _internal::XmlNodeType::EndTag)
5416  {
5417  if (path.size() > 0)
5418  {
5419  path.pop_back();
5420  }
5421  else
5422  {
5423  break;
5424  }
5425  }
5426  else if (node.Type == _internal::XmlNodeType::StartTag)
5427  {
5428  if (std::strcmp(node.Name, "SignedIdentifiers") == 0)
5429  {
5430  path.emplace_back(XmlTagName::k_SignedIdentifiers);
5431  }
5432  else if (std::strcmp(node.Name, "SignedIdentifier") == 0)
5433  {
5434  path.emplace_back(XmlTagName::k_SignedIdentifier);
5435  }
5436  else
5437  {
5438  path.emplace_back(XmlTagName::k_Unknown);
5439  }
5440  if (path.size() == 2 && path[0] == XmlTagName::k_SignedIdentifiers
5441  && path[1] == XmlTagName::k_SignedIdentifier)
5442  {
5443  ret.SignedIdentifiers.emplace_back(SignedIdentifierFromXml(reader));
5444  path.pop_back();
5445  }
5446  }
5447  else if (node.Type == _internal::XmlNodeType::Text)
5448  {
5449  }
5450  }
5451  return ret;
5452  }
5453 
5454  static Models::_detail::ListBlobsByHierarchyResult
5455  ListBlobsByHierarchyResultInternalFromXml(_internal::XmlReader& reader)
5456  {
5457  Models::_detail::ListBlobsByHierarchyResult ret;
5458  enum class XmlTagName
5459  {
5460  k_EnumerationResults,
5461  k_Prefix,
5462  k_Delimiter,
5463  k_NextMarker,
5464  k_Blobs,
5465  k_Blob,
5466  k_BlobPrefix,
5467  k_Name,
5468  k_Unknown,
5469  };
5470  std::vector<XmlTagName> path;
5471  while (true)
5472  {
5473  auto node = reader.Read();
5474  if (node.Type == _internal::XmlNodeType::End)
5475  {
5476  break;
5477  }
5478  else if (node.Type == _internal::XmlNodeType::EndTag)
5479  {
5480  if (path.size() > 0)
5481  {
5482  path.pop_back();
5483  }
5484  else
5485  {
5486  break;
5487  }
5488  }
5489  else if (node.Type == _internal::XmlNodeType::StartTag)
5490  {
5491  if (std::strcmp(node.Name, "EnumerationResults") == 0)
5492  {
5493  path.emplace_back(XmlTagName::k_EnumerationResults);
5494  }
5495  else if (std::strcmp(node.Name, "Prefix") == 0)
5496  {
5497  path.emplace_back(XmlTagName::k_Prefix);
5498  }
5499  else if (std::strcmp(node.Name, "Delimiter") == 0)
5500  {
5501  path.emplace_back(XmlTagName::k_Delimiter);
5502  }
5503  else if (std::strcmp(node.Name, "NextMarker") == 0)
5504  {
5505  path.emplace_back(XmlTagName::k_NextMarker);
5506  }
5507  else if (std::strcmp(node.Name, "Blobs") == 0)
5508  {
5509  path.emplace_back(XmlTagName::k_Blobs);
5510  }
5511  else if (std::strcmp(node.Name, "Blob") == 0)
5512  {
5513  path.emplace_back(XmlTagName::k_Blob);
5514  }
5515  else if (std::strcmp(node.Name, "BlobPrefix") == 0)
5516  {
5517  path.emplace_back(XmlTagName::k_BlobPrefix);
5518  }
5519  else if (std::strcmp(node.Name, "Name") == 0)
5520  {
5521  path.emplace_back(XmlTagName::k_Name);
5522  }
5523  else
5524  {
5525  path.emplace_back(XmlTagName::k_Unknown);
5526  }
5527  if (path.size() == 3 && path[0] == XmlTagName::k_EnumerationResults
5528  && path[1] == XmlTagName::k_Blobs && path[2] == XmlTagName::k_Blob)
5529  {
5530  ret.Items.emplace_back(BlobItemFromXml(reader));
5531  path.pop_back();
5532  }
5533  }
5534  else if (node.Type == _internal::XmlNodeType::Text)
5535  {
5536  if (path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
5537  && path[1] == XmlTagName::k_Prefix)
5538  {
5539  ret.Prefix = node.Value;
5540  }
5541  else if (
5542  path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
5543  && path[1] == XmlTagName::k_Delimiter)
5544  {
5545  ret.Delimiter = node.Value;
5546  }
5547  else if (
5548  path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
5549  && path[1] == XmlTagName::k_NextMarker)
5550  {
5551  ret.ContinuationToken = node.Value;
5552  }
5553  else if (
5554  path.size() == 4 && path[0] == XmlTagName::k_EnumerationResults
5555  && path[1] == XmlTagName::k_Blobs && path[2] == XmlTagName::k_BlobPrefix
5556  && path[3] == XmlTagName::k_Name)
5557  {
5558  ret.BlobPrefixes.emplace_back(node.Value);
5559  }
5560  }
5561  else if (node.Type == _internal::XmlNodeType::Attribute)
5562  {
5563  if (path.size() == 1 && path[0] == XmlTagName::k_EnumerationResults
5564  && std::strcmp(node.Name, "ServiceEndpoint") == 0)
5565  {
5566  ret.ServiceEndpoint = node.Value;
5567  }
5568  else if (
5569  path.size() == 1 && path[0] == XmlTagName::k_EnumerationResults
5570  && std::strcmp(node.Name, "ContainerName") == 0)
5571  {
5572  ret.BlobContainerName = node.Value;
5573  }
5574  }
5575  }
5576  return ret;
5577  }
5578 
5579  static Models::_detail::ListBlobsResult ListBlobsResultInternalFromXml(
5580  _internal::XmlReader& reader)
5581  {
5582  Models::_detail::ListBlobsResult ret;
5583  enum class XmlTagName
5584  {
5585  k_EnumerationResults,
5586  k_Prefix,
5587  k_NextMarker,
5588  k_Blobs,
5589  k_Blob,
5590  k_Unknown,
5591  };
5592  std::vector<XmlTagName> path;
5593  while (true)
5594  {
5595  auto node = reader.Read();
5596  if (node.Type == _internal::XmlNodeType::End)
5597  {
5598  break;
5599  }
5600  else if (node.Type == _internal::XmlNodeType::EndTag)
5601  {
5602  if (path.size() > 0)
5603  {
5604  path.pop_back();
5605  }
5606  else
5607  {
5608  break;
5609  }
5610  }
5611  else if (node.Type == _internal::XmlNodeType::StartTag)
5612  {
5613  if (std::strcmp(node.Name, "EnumerationResults") == 0)
5614  {
5615  path.emplace_back(XmlTagName::k_EnumerationResults);
5616  }
5617  else if (std::strcmp(node.Name, "Prefix") == 0)
5618  {
5619  path.emplace_back(XmlTagName::k_Prefix);
5620  }
5621  else if (std::strcmp(node.Name, "NextMarker") == 0)
5622  {
5623  path.emplace_back(XmlTagName::k_NextMarker);
5624  }
5625  else if (std::strcmp(node.Name, "Blobs") == 0)
5626  {
5627  path.emplace_back(XmlTagName::k_Blobs);
5628  }
5629  else if (std::strcmp(node.Name, "Blob") == 0)
5630  {
5631  path.emplace_back(XmlTagName::k_Blob);
5632  }
5633  else
5634  {
5635  path.emplace_back(XmlTagName::k_Unknown);
5636  }
5637  if (path.size() == 3 && path[0] == XmlTagName::k_EnumerationResults
5638  && path[1] == XmlTagName::k_Blobs && path[2] == XmlTagName::k_Blob)
5639  {
5640  ret.Items.emplace_back(BlobItemFromXml(reader));
5641  path.pop_back();
5642  }
5643  }
5644  else if (node.Type == _internal::XmlNodeType::Text)
5645  {
5646  if (path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
5647  && path[1] == XmlTagName::k_Prefix)
5648  {
5649  ret.Prefix = node.Value;
5650  }
5651  else if (
5652  path.size() == 2 && path[0] == XmlTagName::k_EnumerationResults
5653  && path[1] == XmlTagName::k_NextMarker)
5654  {
5655  ret.ContinuationToken = node.Value;
5656  }
5657  }
5658  else if (node.Type == _internal::XmlNodeType::Attribute)
5659  {
5660  if (path.size() == 1 && path[0] == XmlTagName::k_EnumerationResults
5661  && std::strcmp(node.Name, "ServiceEndpoint") == 0)
5662  {
5663  ret.ServiceEndpoint = node.Value;
5664  }
5665  else if (
5666  path.size() == 1 && path[0] == XmlTagName::k_EnumerationResults
5667  && std::strcmp(node.Name, "ContainerName") == 0)
5668  {
5669  ret.BlobContainerName = node.Value;
5670  }
5671  }
5672  }
5673  return ret;
5674  }
5675 
5676  static BlobItem BlobItemFromXml(_internal::XmlReader& reader)
5677  {
5678  BlobItem ret;
5679  enum class XmlTagName
5680  {
5681  k_Name,
5682  k_Deleted,
5683  k_Snapshot,
5684  k_VersionId,
5685  k_IsCurrentVersion,
5686  k_Properties,
5687  k_ContentType,
5688  k_ContentEncoding,
5689  k_ContentLanguage,
5690  k_ContentMD5,
5691  k_CacheControl,
5692  k_ContentDisposition,
5693  k_CreationTime,
5694  k_ExpiryTime,
5695  k_LastAccessTime,
5696  k_LastModified,
5697  k_Etag,
5698  k_ContentLength,
5699  k_BlobType,
5700  k_AccessTier,
5701  k_AccessTierInferred,
5702  k_LeaseStatus,
5703  k_LeaseState,
5704  k_LeaseDuration,
5705  k_ServerEncrypted,
5706  k_EncryptionKeySHA256,
5707  k_Sealed,
5708  k_xmsblobsequencenumber,
5709  k_Metadata,
5710  k_OrMetadata,
5711  k_Unknown,
5712  };
5713  std::vector<XmlTagName> path;
5714  while (true)
5715  {
5716  auto node = reader.Read();
5717  if (node.Type == _internal::XmlNodeType::End)
5718  {
5719  break;
5720  }
5721  else if (node.Type == _internal::XmlNodeType::EndTag)
5722  {
5723  if (path.size() > 0)
5724  {
5725  path.pop_back();
5726  }
5727  else
5728  {
5729  break;
5730  }
5731  }
5732  else if (node.Type == _internal::XmlNodeType::StartTag)
5733  {
5734  if (std::strcmp(node.Name, "Name") == 0)
5735  {
5736  path.emplace_back(XmlTagName::k_Name);
5737  }
5738  else if (std::strcmp(node.Name, "Deleted") == 0)
5739  {
5740  path.emplace_back(XmlTagName::k_Deleted);
5741  }
5742  else if (std::strcmp(node.Name, "Snapshot") == 0)
5743  {
5744  path.emplace_back(XmlTagName::k_Snapshot);
5745  }
5746  else if (std::strcmp(node.Name, "VersionId") == 0)
5747  {
5748  path.emplace_back(XmlTagName::k_VersionId);
5749  }
5750  else if (std::strcmp(node.Name, "IsCurrentVersion") == 0)
5751  {
5752  path.emplace_back(XmlTagName::k_IsCurrentVersion);
5753  }
5754  else if (std::strcmp(node.Name, "Properties") == 0)
5755  {
5756  path.emplace_back(XmlTagName::k_Properties);
5757  }
5758  else if (std::strcmp(node.Name, "Content-Type") == 0)
5759  {
5760  path.emplace_back(XmlTagName::k_ContentType);
5761  }
5762  else if (std::strcmp(node.Name, "Content-Encoding") == 0)
5763  {
5764  path.emplace_back(XmlTagName::k_ContentEncoding);
5765  }
5766  else if (std::strcmp(node.Name, "Content-Language") == 0)
5767  {
5768  path.emplace_back(XmlTagName::k_ContentLanguage);
5769  }
5770  else if (std::strcmp(node.Name, "Content-MD5") == 0)
5771  {
5772  path.emplace_back(XmlTagName::k_ContentMD5);
5773  }
5774  else if (std::strcmp(node.Name, "Cache-Control") == 0)
5775  {
5776  path.emplace_back(XmlTagName::k_CacheControl);
5777  }
5778  else if (std::strcmp(node.Name, "Content-Disposition") == 0)
5779  {
5780  path.emplace_back(XmlTagName::k_ContentDisposition);
5781  }
5782  else if (std::strcmp(node.Name, "Creation-Time") == 0)
5783  {
5784  path.emplace_back(XmlTagName::k_CreationTime);
5785  }
5786  else if (std::strcmp(node.Name, "Expiry-Time") == 0)
5787  {
5788  path.emplace_back(XmlTagName::k_ExpiryTime);
5789  }
5790  else if (std::strcmp(node.Name, "LastAccessTime") == 0)
5791  {
5792  path.emplace_back(XmlTagName::k_LastAccessTime);
5793  }
5794  else if (std::strcmp(node.Name, "Last-Modified") == 0)
5795  {
5796  path.emplace_back(XmlTagName::k_LastModified);
5797  }
5798  else if (std::strcmp(node.Name, "Etag") == 0)
5799  {
5800  path.emplace_back(XmlTagName::k_Etag);
5801  }
5802  else if (std::strcmp(node.Name, "Content-Length") == 0)
5803  {
5804  path.emplace_back(XmlTagName::k_ContentLength);
5805  }
5806  else if (std::strcmp(node.Name, "BlobType") == 0)
5807  {
5808  path.emplace_back(XmlTagName::k_BlobType);
5809  }
5810  else if (std::strcmp(node.Name, "AccessTier") == 0)
5811  {
5812  path.emplace_back(XmlTagName::k_AccessTier);
5813  }
5814  else if (std::strcmp(node.Name, "AccessTierInferred") == 0)
5815  {
5816  path.emplace_back(XmlTagName::k_AccessTierInferred);
5817  }
5818  else if (std::strcmp(node.Name, "LeaseStatus") == 0)
5819  {
5820  path.emplace_back(XmlTagName::k_LeaseStatus);
5821  }
5822  else if (std::strcmp(node.Name, "LeaseState") == 0)
5823  {
5824  path.emplace_back(XmlTagName::k_LeaseState);
5825  }
5826  else if (std::strcmp(node.Name, "LeaseDuration") == 0)
5827  {
5828  path.emplace_back(XmlTagName::k_LeaseDuration);
5829  }
5830  else if (std::strcmp(node.Name, "ServerEncrypted") == 0)
5831  {
5832  path.emplace_back(XmlTagName::k_ServerEncrypted);
5833  }
5834  else if (std::strcmp(node.Name, "EncryptionKeySHA256") == 0)
5835  {
5836  path.emplace_back(XmlTagName::k_EncryptionKeySHA256);
5837  }
5838  else if (std::strcmp(node.Name, "Sealed") == 0)
5839  {
5840  path.emplace_back(XmlTagName::k_Sealed);
5841  }
5842  else if (std::strcmp(node.Name, "x-ms-blob-sequence-number") == 0)
5843  {
5844  path.emplace_back(XmlTagName::k_xmsblobsequencenumber);
5845  }
5846  else if (std::strcmp(node.Name, "Metadata") == 0)
5847  {
5848  path.emplace_back(XmlTagName::k_Metadata);
5849  }
5850  else if (std::strcmp(node.Name, "OrMetadata") == 0)
5851  {
5852  path.emplace_back(XmlTagName::k_OrMetadata);
5853  }
5854  else
5855  {
5856  path.emplace_back(XmlTagName::k_Unknown);
5857  }
5858  if (path.size() == 1 && path[0] == XmlTagName::k_Metadata)
5859  {
5860  ret.Details.Metadata = MetadataFromXml(reader);
5861  path.pop_back();
5862  }
5863  else if (path.size() == 1 && path[0] == XmlTagName::k_OrMetadata)
5864  {
5865  ret.Details.ObjectReplicationSourceProperties
5866  = ObjectReplicationSourcePropertiesFromXml(reader);
5867  path.pop_back();
5868  }
5869  }
5870  else if (node.Type == _internal::XmlNodeType::Text)
5871  {
5872  if (path.size() == 1 && path[0] == XmlTagName::k_Name)
5873  {
5874  ret.Name = node.Value;
5875  }
5876  else if (path.size() == 1 && path[0] == XmlTagName::k_Deleted)
5877  {
5878  ret.IsDeleted = std::strcmp(node.Value, "true") == 0;
5879  }
5880  else if (path.size() == 1 && path[0] == XmlTagName::k_Snapshot)
5881  {
5882  ret.Snapshot = node.Value;
5883  }
5884  else if (path.size() == 1 && path[0] == XmlTagName::k_VersionId)
5885  {
5886  ret.VersionId = node.Value;
5887  }
5888  else if (path.size() == 1 && path[0] == XmlTagName::k_IsCurrentVersion)
5889  {
5890  ret.IsCurrentVersion = std::strcmp(node.Value, "true") == 0;
5891  }
5892  else if (
5893  path.size() == 2 && path[0] == XmlTagName::k_Properties
5894  && path[1] == XmlTagName::k_ContentType)
5895  {
5896  ret.Details.HttpHeaders.ContentType = node.Value;
5897  }
5898  else if (
5899  path.size() == 2 && path[0] == XmlTagName::k_Properties
5900  && path[1] == XmlTagName::k_ContentEncoding)
5901  {
5902  ret.Details.HttpHeaders.ContentEncoding = node.Value;
5903  }
5904  else if (
5905  path.size() == 2 && path[0] == XmlTagName::k_Properties
5906  && path[1] == XmlTagName::k_ContentLanguage)
5907  {
5908  ret.Details.HttpHeaders.ContentLanguage = node.Value;
5909  }
5910  else if (
5911  path.size() == 2 && path[0] == XmlTagName::k_Properties
5912  && path[1] == XmlTagName::k_ContentMD5)
5913  {
5914  ret.Details.HttpHeaders.ContentHash.Value
5915  = Azure::Core::Convert::Base64Decode(node.Value);
5916  }
5917  else if (
5918  path.size() == 2 && path[0] == XmlTagName::k_Properties
5919  && path[1] == XmlTagName::k_CacheControl)
5920  {
5921  ret.Details.HttpHeaders.CacheControl = node.Value;
5922  }
5923  else if (
5924  path.size() == 2 && path[0] == XmlTagName::k_Properties
5925  && path[1] == XmlTagName::k_ContentDisposition)
5926  {
5927  ret.Details.HttpHeaders.ContentDisposition = node.Value;
5928  }
5929  else if (
5930  path.size() == 2 && path[0] == XmlTagName::k_Properties
5931  && path[1] == XmlTagName::k_CreationTime)
5932  {
5933  ret.Details.CreatedOn
5934  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
5935  }
5936  else if (
5937  path.size() == 2 && path[0] == XmlTagName::k_Properties
5938  && path[1] == XmlTagName::k_ExpiryTime)
5939  {
5940  ret.Details.ExpiresOn
5941  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
5942  }
5943  else if (
5944  path.size() == 2 && path[0] == XmlTagName::k_Properties
5945  && path[1] == XmlTagName::k_LastAccessTime)
5946  {
5947  ret.Details.LastAccessedOn
5948  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
5949  }
5950  else if (
5951  path.size() == 2 && path[0] == XmlTagName::k_Properties
5952  && path[1] == XmlTagName::k_LastModified)
5953  {
5954  ret.Details.LastModified
5955  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
5956  }
5957  else if (
5958  path.size() == 2 && path[0] == XmlTagName::k_Properties
5959  && path[1] == XmlTagName::k_Etag)
5960  {
5961  ret.Details.ETag = Azure::ETag(node.Value);
5962  }
5963  else if (
5964  path.size() == 2 && path[0] == XmlTagName::k_Properties
5965  && path[1] == XmlTagName::k_ContentLength)
5966  {
5967  ret.BlobSize = std::stoll(node.Value);
5968  }
5969  else if (
5970  path.size() == 2 && path[0] == XmlTagName::k_Properties
5971  && path[1] == XmlTagName::k_BlobType)
5972  {
5973  ret.BlobType = BlobType(node.Value);
5974  }
5975  else if (
5976  path.size() == 2 && path[0] == XmlTagName::k_Properties
5977  && path[1] == XmlTagName::k_AccessTier)
5978  {
5979  ret.Details.AccessTier = AccessTier(node.Value);
5980  }
5981  else if (
5982  path.size() == 2 && path[0] == XmlTagName::k_Properties
5983  && path[1] == XmlTagName::k_AccessTierInferred)
5984  {
5985  ret.Details.IsAccessTierInferred = std::strcmp(node.Value, "true") == 0;
5986  }
5987  else if (
5988  path.size() == 2 && path[0] == XmlTagName::k_Properties
5989  && path[1] == XmlTagName::k_LeaseStatus)
5990  {
5991  ret.Details.LeaseStatus = LeaseStatus(node.Value);
5992  }
5993  else if (
5994  path.size() == 2 && path[0] == XmlTagName::k_Properties
5995  && path[1] == XmlTagName::k_LeaseState)
5996  {
5997  ret.Details.LeaseState = LeaseState(node.Value);
5998  }
5999  else if (
6000  path.size() == 2 && path[0] == XmlTagName::k_Properties
6001  && path[1] == XmlTagName::k_LeaseDuration)
6002  {
6003  ret.Details.LeaseDuration = LeaseDurationType(node.Value);
6004  }
6005  else if (
6006  path.size() == 2 && path[0] == XmlTagName::k_Properties
6007  && path[1] == XmlTagName::k_ServerEncrypted)
6008  {
6009  ret.Details.IsServerEncrypted = std::strcmp(node.Value, "true") == 0;
6010  }
6011  else if (
6012  path.size() == 2 && path[0] == XmlTagName::k_Properties
6013  && path[1] == XmlTagName::k_EncryptionKeySHA256)
6014  {
6015  ret.Details.EncryptionKeySha256 = Azure::Core::Convert::Base64Decode(node.Value);
6016  }
6017  else if (
6018  path.size() == 2 && path[0] == XmlTagName::k_Properties
6019  && path[1] == XmlTagName::k_Sealed)
6020  {
6021  ret.Details.IsSealed = std::strcmp(node.Value, "true") == 0;
6022  }
6023  else if (
6024  path.size() == 2 && path[0] == XmlTagName::k_Properties
6025  && path[1] == XmlTagName::k_xmsblobsequencenumber)
6026  {
6027  ret.Details.SequenceNumber = std::stoll(node.Value);
6028  }
6029  }
6030  }
6031  return ret;
6032  }
6033 
6034  static SignedIdentifier SignedIdentifierFromXml(_internal::XmlReader& reader)
6035  {
6036  SignedIdentifier ret;
6037  enum class XmlTagName
6038  {
6039  k_Id,
6040  k_AccessPolicy,
6041  k_Start,
6042  k_Expiry,
6043  k_Permission,
6044  k_Unknown,
6045  };
6046  std::vector<XmlTagName> path;
6047  while (true)
6048  {
6049  auto node = reader.Read();
6050  if (node.Type == _internal::XmlNodeType::End)
6051  {
6052  break;
6053  }
6054  else if (node.Type == _internal::XmlNodeType::EndTag)
6055  {
6056  if (path.size() > 0)
6057  {
6058  path.pop_back();
6059  }
6060  else
6061  {
6062  break;
6063  }
6064  }
6065  else if (node.Type == _internal::XmlNodeType::StartTag)
6066  {
6067  if (std::strcmp(node.Name, "Id") == 0)
6068  {
6069  path.emplace_back(XmlTagName::k_Id);
6070  }
6071  else if (std::strcmp(node.Name, "AccessPolicy") == 0)
6072  {
6073  path.emplace_back(XmlTagName::k_AccessPolicy);
6074  }
6075  else if (std::strcmp(node.Name, "Start") == 0)
6076  {
6077  path.emplace_back(XmlTagName::k_Start);
6078  }
6079  else if (std::strcmp(node.Name, "Expiry") == 0)
6080  {
6081  path.emplace_back(XmlTagName::k_Expiry);
6082  }
6083  else if (std::strcmp(node.Name, "Permission") == 0)
6084  {
6085  path.emplace_back(XmlTagName::k_Permission);
6086  }
6087  else
6088  {
6089  path.emplace_back(XmlTagName::k_Unknown);
6090  }
6091  }
6092  else if (node.Type == _internal::XmlNodeType::Text)
6093  {
6094  if (path.size() == 1 && path[0] == XmlTagName::k_Id)
6095  {
6096  ret.Id = node.Value;
6097  }
6098  else if (
6099  path.size() == 2 && path[0] == XmlTagName::k_AccessPolicy
6100  && path[1] == XmlTagName::k_Start)
6101  {
6102  ret.StartsOn
6103  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc3339);
6104  }
6105  else if (
6106  path.size() == 2 && path[0] == XmlTagName::k_AccessPolicy
6107  && path[1] == XmlTagName::k_Expiry)
6108  {
6109  ret.ExpiresOn
6110  = Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc3339);
6111  }
6112  else if (
6113  path.size() == 2 && path[0] == XmlTagName::k_AccessPolicy
6114  && path[1] == XmlTagName::k_Permission)
6115  {
6116  ret.Permissions = node.Value;
6117  }
6118  }
6119  }
6120  return ret;
6121  }
6122 
6123  static std::vector<ObjectReplicationPolicy> ObjectReplicationSourcePropertiesFromXml(
6124  _internal::XmlReader& reader)
6125  {
6126  int depth = 0;
6127  std::map<std::string, std::vector<ObjectReplicationRule>> orPropertiesMap;
6128  std::string policyId;
6129  std::string ruleId;
6130  while (true)
6131  {
6132  auto node = reader.Read();
6133  if (node.Type == _internal::XmlNodeType::End)
6134  {
6135  break;
6136  }
6137  else if (node.Type == _internal::XmlNodeType::StartTag)
6138  {
6139  ++depth;
6140  std::string startTagName = node.Name;
6141  if (startTagName.substr(0, 3) == "or-")
6142  {
6143  auto underscorePos = startTagName.find('_', 3);
6144  policyId
6145  = std::string(startTagName.begin() + 3, startTagName.begin() + underscorePos);
6146  ruleId = startTagName.substr(underscorePos + 1);
6147  }
6148  }
6149  else if (node.Type == _internal::XmlNodeType::EndTag)
6150  {
6151  if (depth-- == 0)
6152  {
6153  break;
6154  }
6155  }
6156  if (depth == 1 && node.Type == _internal::XmlNodeType::Text)
6157  {
6158  ObjectReplicationRule rule;
6159  rule.RuleId = std::move(ruleId);
6160  rule.ReplicationStatus = ObjectReplicationStatus(node.Value);
6161  orPropertiesMap[policyId].emplace_back(std::move(rule));
6162  }
6163  }
6164  std::vector<ObjectReplicationPolicy> ret;
6165  for (auto& property : orPropertiesMap)
6166  {
6167  ObjectReplicationPolicy policy;
6168  policy.PolicyId = property.first;
6169  policy.Rules = std::move(property.second);
6170  ret.emplace_back(std::move(policy));
6171  }
6172  return ret;
6173  }
6174 
6175  static Metadata MetadataFromXml(_internal::XmlReader& reader)
6176  {
6177  Metadata ret;
6178  int depth = 0;
6179  std::string key;
6180  while (true)
6181  {
6182  auto node = reader.Read();
6183  if (node.Type == _internal::XmlNodeType::End)
6184  {
6185  break;
6186  }
6187  else if (node.Type == _internal::XmlNodeType::StartTag)
6188  {
6189  if (depth++ == 0)
6190  {
6191  key = node.Name;
6192  }
6193  }
6194  else if (node.Type == _internal::XmlNodeType::EndTag)
6195  {
6196  if (depth-- == 0)
6197  {
6198  break;
6199  }
6200  }
6201  else if (depth == 1 && node.Type == _internal::XmlNodeType::Text)
6202  {
6203  ret.emplace(std::move(key), std::string(node.Value));
6204  }
6205  }
6206  return ret;
6207  }
6208 
6209  static void SetBlobContainerAccessPolicyOptionsToXml(
6210  _internal::XmlWriter& writer,
6211  const SetBlobContainerAccessPolicyOptions& options)
6212  {
6213  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "SignedIdentifiers"});
6214  for (const auto& i : options.SignedIdentifiers)
6215  {
6216  SignedIdentifierToXml(writer, i);
6217  }
6218  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6219  }
6220 
6221  static void SignedIdentifierToXml(
6222  _internal::XmlWriter& writer,
6223  const SignedIdentifier& options)
6224  {
6225  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "SignedIdentifier"});
6226  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Id"});
6227  writer.Write(
6228  _internal::XmlNode{_internal::XmlNodeType::Text, nullptr, options.Id.data()});
6229  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6230  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AccessPolicy"});
6231  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"});
6232  writer.Write(_internal::XmlNode{
6233  _internal::XmlNodeType::Text,
6234  nullptr,
6235  options.StartsOn
6236  .ToString(
6237  Azure::DateTime::DateFormat::Rfc3339,
6238  Azure::DateTime::TimeFractionFormat::AllDigits)
6239  .data()});
6240  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6241  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"});
6242  writer.Write(_internal::XmlNode{
6243  _internal::XmlNodeType::Text,
6244  nullptr,
6245  options.ExpiresOn
6246  .ToString(
6247  Azure::DateTime::DateFormat::Rfc3339,
6248  Azure::DateTime::TimeFractionFormat::AllDigits)
6249  .data()});
6250  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6251  writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Permission"});
6252  writer.Write(_internal::XmlNode{
6253  _internal::XmlNodeType::Text, nullptr, options.Permissions.data()});
6254  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6255  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6256  writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
6257  }
6258 
6259  }; // class BlobContainer
6260 
6261  class Blob final {
6262  public:
6263  struct DownloadBlobOptions final
6264  {
6265  Azure::Nullable<int32_t> Timeout;
6266  Azure::Nullable<Azure::Core::Http::HttpRange> Range;
6267  Azure::Nullable<HashAlgorithm> RangeHashAlgorithm;
6268  Azure::Nullable<std::string> EncryptionKey;
6269  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
6270  Azure::Nullable<EncryptionAlgorithmType> EncryptionAlgorithm;
6271  Azure::Nullable<std::string> LeaseId;
6272  Azure::Nullable<Azure::DateTime> IfModifiedSince;
6273  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
6274  Azure::ETag IfMatch;
6275  Azure::ETag IfNoneMatch;
6276  Azure::Nullable<std::string> IfTags;
6277  }; // struct DownloadBlobOptions
6278 
6279  static Azure::Response<DownloadBlobResult> Download(
6280  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6281  const Azure::Core::Url& url,
6282  const DownloadBlobOptions& options,
6283  const Azure::Core::Context& context)
6284  {
6285  (void)options;
6286  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url, false);
6287  request.SetHeader("x-ms-version", "2020-02-10");
6288  if (options.Timeout.HasValue())
6289  {
6290  request.GetUrl().AppendQueryParameter(
6291  "timeout", std::to_string(options.Timeout.Value()));
6292  }
6293  if (options.Range.HasValue())
6294  {
6295  std::string headerValue = "bytes=" + std::to_string(options.Range.Value().Offset) + "-";
6296  if (options.Range.Value().Length.HasValue())
6297  {
6298  headerValue += std::to_string(
6299  options.Range.Value().Offset + options.Range.Value().Length.Value() - 1);
6300  }
6301  request.SetHeader("x-ms-range", std::move(headerValue));
6302  }
6303  if (options.EncryptionKey.HasValue())
6304  {
6305  request.SetHeader("x-ms-encryption-key", options.EncryptionKey.Value());
6306  }
6307  if (options.EncryptionKeySha256.HasValue())
6308  {
6309  request.SetHeader(
6310  "x-ms-encryption-key-sha256",
6311  Azure::Core::Convert::Base64Encode(options.EncryptionKeySha256.Value()));
6312  }
6313  if (options.EncryptionAlgorithm.HasValue())
6314  {
6315  request.SetHeader(
6316  "x-ms-encryption-algorithm", options.EncryptionAlgorithm.Value().ToString());
6317  }
6318  if (options.IfModifiedSince.HasValue())
6319  {
6320  request.SetHeader(
6321  "If-Modified-Since",
6322  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
6323  }
6324  if (options.IfUnmodifiedSince.HasValue())
6325  {
6326  request.SetHeader(
6327  "If-Unmodified-Since",
6328  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
6329  }
6330  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
6331  {
6332  request.SetHeader("If-Match", options.IfMatch.ToString());
6333  }
6334  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
6335  {
6336  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
6337  }
6338  if (options.IfTags.HasValue())
6339  {
6340  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
6341  }
6342  if (options.LeaseId.HasValue())
6343  {
6344  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
6345  }
6346  if (options.RangeHashAlgorithm.HasValue())
6347  {
6348  if (options.RangeHashAlgorithm.Value() == HashAlgorithm::Md5)
6349  {
6350  request.SetHeader("x-ms-range-get-content-md5", "true");
6351  }
6352  else if (options.RangeHashAlgorithm.Value() == HashAlgorithm::Crc64)
6353  {
6354  request.SetHeader("x-ms-range-get-content-crc64", "true");
6355  }
6356  }
6357  auto pHttpResponse = pipeline.Send(request, context);
6358  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
6359  DownloadBlobResult response;
6360  auto http_status_code
6361  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
6362  httpResponse.GetStatusCode());
6363  if (!(http_status_code == 200 || http_status_code == 206))
6364  {
6365  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
6366  }
6367  response.BodyStream = httpResponse.ExtractBodyStream();
6368  {
6369  const auto& headers = httpResponse.GetHeaders();
6370  auto content_md5_iterator = headers.find("content-md5");
6371  if (content_md5_iterator != headers.end())
6372  {
6373  ContentHash hash;
6374  hash.Algorithm = HashAlgorithm::Md5;
6375  hash.Value = Azure::Core::Convert::Base64Decode(content_md5_iterator->second);
6376  response.TransactionalContentHash = std::move(hash);
6377  }
6378  auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
6379  if (x_ms_content_crc64_iterator != headers.end())
6380  {
6381  ContentHash hash;
6382  hash.Algorithm = HashAlgorithm::Crc64;
6383  hash.Value = Azure::Core::Convert::Base64Decode(x_ms_content_crc64_iterator->second);
6384  response.TransactionalContentHash = std::move(hash);
6385  }
6386  }
6387  response.BlobType = BlobType(httpResponse.GetHeaders().at("x-ms-blob-type"));
6388  auto content_range_iterator = httpResponse.GetHeaders().find("content-range");
6389  if (content_range_iterator != httpResponse.GetHeaders().end())
6390  {
6391  const std::string& content_range = content_range_iterator->second;
6392  auto bytes_pos = content_range.find("bytes ");
6393  auto dash_pos = content_range.find("-", bytes_pos + 6);
6394  auto slash_pos = content_range.find("/", dash_pos + 1);
6395  int64_t range_start_offset = std::stoll(std::string(
6396  content_range.begin() + bytes_pos + 6, content_range.begin() + dash_pos));
6397  int64_t range_end_offset = std::stoll(std::string(
6398  content_range.begin() + dash_pos + 1, content_range.begin() + slash_pos));
6399  response.ContentRange = Azure::Core::Http::HttpRange{
6400  range_start_offset, range_end_offset - range_start_offset + 1};
6401  }
6402  else
6403  {
6404  response.ContentRange = Azure::Core::Http::HttpRange{
6405  0, std::stoll(httpResponse.GetHeaders().at("content-length"))};
6406  }
6407  if (content_range_iterator != httpResponse.GetHeaders().end())
6408  {
6409  const std::string& content_range = content_range_iterator->second;
6410  auto slash_pos = content_range.find("/");
6411  response.BlobSize = std::stoll(content_range.substr(slash_pos + 1));
6412  }
6413  else
6414  {
6415  response.BlobSize = std::stoll(httpResponse.GetHeaders().at("content-length"));
6416  }
6417  response.Details.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
6418  response.Details.LastModified = Azure::DateTime::Parse(
6419  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
6420  auto content_type__iterator = httpResponse.GetHeaders().find("content-type");
6421  if (content_type__iterator != httpResponse.GetHeaders().end())
6422  {
6423  response.Details.HttpHeaders.ContentType = content_type__iterator->second;
6424  }
6425  auto content_encoding__iterator = httpResponse.GetHeaders().find("content-encoding");
6426  if (content_encoding__iterator != httpResponse.GetHeaders().end())
6427  {
6428  response.Details.HttpHeaders.ContentEncoding = content_encoding__iterator->second;
6429  }
6430  auto content_language__iterator = httpResponse.GetHeaders().find("content-language");
6431  if (content_language__iterator != httpResponse.GetHeaders().end())
6432  {
6433  response.Details.HttpHeaders.ContentLanguage = content_language__iterator->second;
6434  }
6435  auto cache_control__iterator = httpResponse.GetHeaders().find("cache-control");
6436  if (cache_control__iterator != httpResponse.GetHeaders().end())
6437  {
6438  response.Details.HttpHeaders.CacheControl = cache_control__iterator->second;
6439  }
6440  auto content_md5__iterator = httpResponse.GetHeaders().find("content-md5");
6441  if (content_md5__iterator != httpResponse.GetHeaders().end())
6442  {
6443  response.Details.HttpHeaders.ContentHash.Value
6444  = Azure::Core::Convert::Base64Decode(content_md5__iterator->second);
6445  }
6446  auto x_ms_blob_content_md5__iterator
6447  = httpResponse.GetHeaders().find("x-ms-blob-content-md5");
6448  if (x_ms_blob_content_md5__iterator != httpResponse.GetHeaders().end())
6449  {
6450  response.Details.HttpHeaders.ContentHash.Value
6451  = Azure::Core::Convert::Base64Decode(x_ms_blob_content_md5__iterator->second);
6452  }
6453  auto content_disposition__iterator
6454  = httpResponse.GetHeaders().find("content-disposition");
6455  if (content_disposition__iterator != httpResponse.GetHeaders().end())
6456  {
6457  response.Details.HttpHeaders.ContentDisposition = content_disposition__iterator->second;
6458  }
6459  for (auto i = httpResponse.GetHeaders().lower_bound("x-ms-meta-");
6460  i != httpResponse.GetHeaders().end() && i->first.substr(0, 10) == "x-ms-meta-";
6461  ++i)
6462  {
6463  response.Details.Metadata.emplace(i->first.substr(10), i->second);
6464  }
6465  response.Details.IsServerEncrypted
6466  = httpResponse.GetHeaders().at("x-ms-server-encrypted") == "true";
6467  auto x_ms_encryption_key_sha256__iterator
6468  = httpResponse.GetHeaders().find("x-ms-encryption-key-sha256");
6469  if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
6470  {
6471  response.Details.EncryptionKeySha256
6472  = Azure::Core::Convert::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
6473  }
6474  auto x_ms_encryption_scope__iterator
6475  = httpResponse.GetHeaders().find("x-ms-encryption-scope");
6476  if (x_ms_encryption_scope__iterator != httpResponse.GetHeaders().end())
6477  {
6478  response.Details.EncryptionScope = x_ms_encryption_scope__iterator->second;
6479  }
6480  auto x_ms_lease_status__iterator = httpResponse.GetHeaders().find("x-ms-lease-status");
6481  if (x_ms_lease_status__iterator != httpResponse.GetHeaders().end())
6482  {
6483  response.Details.LeaseStatus = LeaseStatus(x_ms_lease_status__iterator->second);
6484  }
6485  auto x_ms_lease_state__iterator = httpResponse.GetHeaders().find("x-ms-lease-state");
6486  if (x_ms_lease_state__iterator != httpResponse.GetHeaders().end())
6487  {
6488  response.Details.LeaseState = LeaseState(x_ms_lease_state__iterator->second);
6489  }
6490  auto x_ms_lease_duration__iterator
6491  = httpResponse.GetHeaders().find("x-ms-lease-duration");
6492  if (x_ms_lease_duration__iterator != httpResponse.GetHeaders().end())
6493  {
6494  response.Details.LeaseDuration
6495  = LeaseDurationType(x_ms_lease_duration__iterator->second);
6496  }
6497  response.Details.CreatedOn = Azure::DateTime::Parse(
6498  httpResponse.GetHeaders().at("x-ms-creation-time"),
6499  Azure::DateTime::DateFormat::Rfc1123);
6500  auto x_ms_expiry_time__iterator = httpResponse.GetHeaders().find("x-ms-expiry-time");
6501  if (x_ms_expiry_time__iterator != httpResponse.GetHeaders().end())
6502  {
6503  response.Details.ExpiresOn = Azure::DateTime::Parse(
6504  x_ms_expiry_time__iterator->second, Azure::DateTime::DateFormat::Rfc1123);
6505  }
6506  auto x_ms_last_access_time__iterator
6507  = httpResponse.GetHeaders().find("x-ms-last-access-time");
6508  if (x_ms_last_access_time__iterator != httpResponse.GetHeaders().end())
6509  {
6510  response.Details.LastAccessedOn = Azure::DateTime::Parse(
6511  x_ms_last_access_time__iterator->second, Azure::DateTime::DateFormat::Rfc1123);
6512  }
6513  auto x_ms_blob_sequence_number__iterator
6514  = httpResponse.GetHeaders().find("x-ms-blob-sequence-number");
6515  if (x_ms_blob_sequence_number__iterator != httpResponse.GetHeaders().end())
6516  {
6517  response.Details.SequenceNumber
6518  = std::stoll(x_ms_blob_sequence_number__iterator->second);
6519  }
6520  auto x_ms_blob_committed_block_count__iterator
6521  = httpResponse.GetHeaders().find("x-ms-blob-committed-block-count");
6522  if (x_ms_blob_committed_block_count__iterator != httpResponse.GetHeaders().end())
6523  {
6524  response.Details.CommittedBlockCount
6525  = std::stoi(x_ms_blob_committed_block_count__iterator->second);
6526  }
6527  auto x_ms_blob_sealed__iterator = httpResponse.GetHeaders().find("x-ms-blob-sealed");
6528  if (x_ms_blob_sealed__iterator != httpResponse.GetHeaders().end())
6529  {
6530  response.Details.IsSealed = x_ms_blob_sealed__iterator->second == "true";
6531  }
6532  auto x_ms_or_policy_id__iterator = httpResponse.GetHeaders().find("x-ms-or-policy-id");
6533  if (x_ms_or_policy_id__iterator != httpResponse.GetHeaders().end())
6534  {
6535  response.Details.ObjectReplicationDestinationPolicyId
6536  = x_ms_or_policy_id__iterator->second;
6537  }
6538  {
6539  std::map<std::string, std::vector<ObjectReplicationRule>> orPropertiesMap;
6540  for (auto i = httpResponse.GetHeaders().lower_bound("x-ms-or-");
6541  i != httpResponse.GetHeaders().end() && i->first.substr(0, 8) == "x-ms-or-";
6542  ++i)
6543  {
6544  const std::string& header = i->first;
6545  auto underscorePos = header.find('_', 8);
6546  if (underscorePos == std::string::npos)
6547  {
6548  continue;
6549  }
6550  std::string policyId
6551  = std::string(header.begin() + 8, header.begin() + underscorePos);
6552  std::string ruleId = header.substr(underscorePos + 1);
6553 
6554  ObjectReplicationRule rule;
6555  rule.RuleId = std::move(ruleId);
6556  rule.ReplicationStatus = ObjectReplicationStatus(i->second);
6557  orPropertiesMap[policyId].emplace_back(std::move(rule));
6558  }
6559  for (auto& property : orPropertiesMap)
6560  {
6561  ObjectReplicationPolicy policy;
6562  policy.PolicyId = property.first;
6563  policy.Rules = std::move(property.second);
6564  response.Details.ObjectReplicationSourceProperties.emplace_back(std::move(policy));
6565  }
6566  }
6567  auto x_ms_tag_count__iterator = httpResponse.GetHeaders().find("x-ms-tag-count");
6568  if (x_ms_tag_count__iterator != httpResponse.GetHeaders().end())
6569  {
6570  response.Details.TagCount = std::stoi(x_ms_tag_count__iterator->second);
6571  }
6572  auto x_ms_copy_id__iterator = httpResponse.GetHeaders().find("x-ms-copy-id");
6573  if (x_ms_copy_id__iterator != httpResponse.GetHeaders().end())
6574  {
6575  response.Details.CopyId = x_ms_copy_id__iterator->second;
6576  }
6577  auto x_ms_copy_source__iterator = httpResponse.GetHeaders().find("x-ms-copy-source");
6578  if (x_ms_copy_source__iterator != httpResponse.GetHeaders().end())
6579  {
6580  response.Details.CopySource = x_ms_copy_source__iterator->second;
6581  }
6582  auto x_ms_copy_status__iterator = httpResponse.GetHeaders().find("x-ms-copy-status");
6583  if (x_ms_copy_status__iterator != httpResponse.GetHeaders().end())
6584  {
6585  response.Details.CopyStatus = CopyStatus(x_ms_copy_status__iterator->second);
6586  }
6587  auto x_ms_copy_status_description__iterator
6588  = httpResponse.GetHeaders().find("x-ms-copy-status-description");
6589  if (x_ms_copy_status_description__iterator != httpResponse.GetHeaders().end())
6590  {
6591  response.Details.CopyStatusDescription = x_ms_copy_status_description__iterator->second;
6592  }
6593  auto x_ms_copy_progress__iterator = httpResponse.GetHeaders().find("x-ms-copy-progress");
6594  if (x_ms_copy_progress__iterator != httpResponse.GetHeaders().end())
6595  {
6596  response.Details.CopyProgress = x_ms_copy_progress__iterator->second;
6597  }
6598  auto x_ms_copy_completion_time__iterator
6599  = httpResponse.GetHeaders().find("x-ms-copy-completion-time");
6600  if (x_ms_copy_completion_time__iterator != httpResponse.GetHeaders().end())
6601  {
6602  response.Details.CopyCompletedOn = Azure::DateTime::Parse(
6603  x_ms_copy_completion_time__iterator->second, Azure::DateTime::DateFormat::Rfc1123);
6604  }
6605  auto x_ms_version_id__iterator = httpResponse.GetHeaders().find("x-ms-version-id");
6606  if (x_ms_version_id__iterator != httpResponse.GetHeaders().end())
6607  {
6608  response.Details.VersionId = x_ms_version_id__iterator->second;
6609  }
6610  auto x_ms_is_current_version__iterator
6611  = httpResponse.GetHeaders().find("x-ms-is-current-version");
6612  if (x_ms_is_current_version__iterator != httpResponse.GetHeaders().end())
6613  {
6614  response.Details.IsCurrentVersion = x_ms_is_current_version__iterator->second == "true";
6615  }
6616  return Azure::Response<DownloadBlobResult>(std::move(response), std::move(pHttpResponse));
6617  }
6618 
6619  struct DeleteBlobOptions final
6620  {
6621  Azure::Nullable<int32_t> Timeout;
6622  Azure::Nullable<DeleteSnapshotsOption> DeleteSnapshots;
6623  Azure::Nullable<std::string> LeaseId;
6624  Azure::Nullable<Azure::DateTime> IfModifiedSince;
6625  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
6626  Azure::ETag IfMatch;
6627  Azure::ETag IfNoneMatch;
6628  Azure::Nullable<std::string> IfTags;
6629  }; // struct DeleteBlobOptions
6630 
6631  static Azure::Core::Http::Request DeleteCreateMessage(
6632  const Azure::Core::Url& url,
6633  const DeleteBlobOptions& options)
6634  {
6635  (void)options;
6636  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Delete, url);
6637  request.SetHeader("x-ms-version", "2020-02-10");
6638  if (options.Timeout.HasValue())
6639  {
6640  request.GetUrl().AppendQueryParameter(
6641  "timeout", std::to_string(options.Timeout.Value()));
6642  }
6643  if (options.DeleteSnapshots.HasValue())
6644  {
6645  request.SetHeader("x-ms-delete-snapshots", options.DeleteSnapshots.Value().ToString());
6646  }
6647  if (options.LeaseId.HasValue())
6648  {
6649  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
6650  }
6651  if (options.IfModifiedSince.HasValue())
6652  {
6653  request.SetHeader(
6654  "If-Modified-Since",
6655  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
6656  }
6657  if (options.IfUnmodifiedSince.HasValue())
6658  {
6659  request.SetHeader(
6660  "If-Unmodified-Since",
6661  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
6662  }
6663  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
6664  {
6665  request.SetHeader("If-Match", options.IfMatch.ToString());
6666  }
6667  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
6668  {
6669  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
6670  }
6671  if (options.IfTags.HasValue())
6672  {
6673  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
6674  }
6675  return request;
6676  }
6677 
6678  static Azure::Response<DeleteBlobResult> DeleteCreateResponse(
6679  std::unique_ptr<Azure::Core::Http::RawResponse> pHttpResponse,
6680  const Azure::Core::Context& context)
6681  {
6682  (void)context;
6683  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
6684  DeleteBlobResult response;
6685  auto http_status_code
6686  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
6687  httpResponse.GetStatusCode());
6688  if (!(http_status_code == 202))
6689  {
6690  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
6691  }
6692  return Azure::Response<DeleteBlobResult>(std::move(response), std::move(pHttpResponse));
6693  }
6694 
6695  static Azure::Response<DeleteBlobResult> Delete(
6696  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6697  const Azure::Core::Url& url,
6698  const DeleteBlobOptions& options,
6699  const Azure::Core::Context& context)
6700  {
6701  auto request = DeleteCreateMessage(url, options);
6702  auto pHttpResponse = pipeline.Send(request, context);
6703  return DeleteCreateResponse(std::move(pHttpResponse), context);
6704  }
6705 
6706  struct SetBlobExpiryOptions final
6707  {
6708  Azure::Nullable<int32_t> Timeout;
6709  ScheduleBlobExpiryOriginType ExpiryOrigin;
6710  Azure::Nullable<std::string> ExpiryTime;
6711  }; // struct SetBlobExpiryOptions
6712 
6713  static Azure::Response<SetBlobExpiryResult> ScheduleDeletion(
6714  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6715  const Azure::Core::Url& url,
6716  const SetBlobExpiryOptions& options,
6717  const Azure::Core::Context& context)
6718  {
6719  (void)options;
6720  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
6721  request.SetHeader("Content-Length", "0");
6722  request.SetHeader("x-ms-version", "2020-02-10");
6723  if (options.Timeout.HasValue())
6724  {
6725  request.GetUrl().AppendQueryParameter(
6726  "timeout", std::to_string(options.Timeout.Value()));
6727  }
6728  request.GetUrl().AppendQueryParameter("comp", "expiry");
6729  request.SetHeader("x-ms-expiry-option", options.ExpiryOrigin.ToString());
6730  if (options.ExpiryTime.HasValue())
6731  {
6732  request.SetHeader("x-ms-expiry-time", options.ExpiryTime.Value());
6733  }
6734  auto pHttpResponse = pipeline.Send(request, context);
6735  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
6736  SetBlobExpiryResult response;
6737  auto http_status_code
6738  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
6739  httpResponse.GetStatusCode());
6740  if (!(http_status_code == 200))
6741  {
6742  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
6743  }
6744  return Azure::Response<SetBlobExpiryResult>(
6745  std::move(response), std::move(pHttpResponse));
6746  }
6747 
6748  struct UndeleteBlobOptions final
6749  {
6750  Azure::Nullable<int32_t> Timeout;
6751  }; // struct UndeleteBlobOptions
6752 
6753  static Azure::Response<UndeleteBlobResult> Undelete(
6754  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6755  const Azure::Core::Url& url,
6756  const UndeleteBlobOptions& options,
6757  const Azure::Core::Context& context)
6758  {
6759  (void)options;
6760  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
6761  request.SetHeader("Content-Length", "0");
6762  request.SetHeader("x-ms-version", "2020-02-10");
6763  if (options.Timeout.HasValue())
6764  {
6765  request.GetUrl().AppendQueryParameter(
6766  "timeout", std::to_string(options.Timeout.Value()));
6767  }
6768  request.GetUrl().AppendQueryParameter("comp", "undelete");
6769  auto pHttpResponse = pipeline.Send(request, context);
6770  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
6771  UndeleteBlobResult response;
6772  auto http_status_code
6773  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
6774  httpResponse.GetStatusCode());
6775  if (!(http_status_code == 200))
6776  {
6777  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
6778  }
6779  return Azure::Response<UndeleteBlobResult>(std::move(response), std::move(pHttpResponse));
6780  }
6781 
6782  struct GetBlobPropertiesOptions final
6783  {
6784  Azure::Nullable<int32_t> Timeout;
6785  Azure::Nullable<std::string> EncryptionKey;
6786  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
6787  Azure::Nullable<EncryptionAlgorithmType> EncryptionAlgorithm;
6788  Azure::Nullable<std::string> LeaseId;
6789  Azure::Nullable<Azure::DateTime> IfModifiedSince;
6790  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
6791  Azure::ETag IfMatch;
6792  Azure::ETag IfNoneMatch;
6793  Azure::Nullable<std::string> IfTags;
6794  }; // struct GetBlobPropertiesOptions
6795 
6796  static Azure::Response<BlobProperties> GetProperties(
6797  Azure::Core::Http::_internal::HttpPipeline& pipeline,
6798  const Azure::Core::Url& url,
6799  const GetBlobPropertiesOptions& options,
6800  const Azure::Core::Context& context)
6801  {
6802  (void)options;
6803  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Head, url);
6804  request.SetHeader("x-ms-version", "2020-02-10");
6805  if (options.Timeout.HasValue())
6806  {
6807  request.GetUrl().AppendQueryParameter(
6808  "timeout", std::to_string(options.Timeout.Value()));
6809  }
6810  if (options.EncryptionKey.HasValue())
6811  {
6812  request.SetHeader("x-ms-encryption-key", options.EncryptionKey.Value());
6813  }
6814  if (options.EncryptionKeySha256.HasValue())
6815  {
6816  request.SetHeader(
6817  "x-ms-encryption-key-sha256",
6818  Azure::Core::Convert::Base64Encode(options.EncryptionKeySha256.Value()));
6819  }
6820  if (options.EncryptionAlgorithm.HasValue())
6821  {
6822  request.SetHeader(
6823  "x-ms-encryption-algorithm", options.EncryptionAlgorithm.Value().ToString());
6824  }
6825  if (options.LeaseId.HasValue())
6826  {
6827  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
6828  }
6829  if (options.IfModifiedSince.HasValue())
6830  {
6831  request.SetHeader(
6832  "If-Modified-Since",
6833  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
6834  }
6835  if (options.IfUnmodifiedSince.HasValue())
6836  {
6837  request.SetHeader(
6838  "If-Unmodified-Since",
6839  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
6840  }
6841  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
6842  {
6843  request.SetHeader("If-Match", options.IfMatch.ToString());
6844  }
6845  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
6846  {
6847  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
6848  }
6849  if (options.IfTags.HasValue())
6850  {
6851  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
6852  }
6853  auto pHttpResponse = pipeline.Send(request, context);
6854  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
6855  BlobProperties response;
6856  auto http_status_code
6857  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
6858  httpResponse.GetStatusCode());
6859  if (!(http_status_code == 200))
6860  {
6861  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
6862  }
6863  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
6864  response.LastModified = Azure::DateTime::Parse(
6865  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
6866  response.CreatedOn = Azure::DateTime::Parse(
6867  httpResponse.GetHeaders().at("x-ms-creation-time"),
6868  Azure::DateTime::DateFormat::Rfc1123);
6869  auto x_ms_expiry_time__iterator = httpResponse.GetHeaders().find("x-ms-expiry-time");
6870  if (x_ms_expiry_time__iterator != httpResponse.GetHeaders().end())
6871  {
6872  response.ExpiresOn = Azure::DateTime::Parse(
6873  x_ms_expiry_time__iterator->second, Azure::DateTime::DateFormat::Rfc1123);
6874  }
6875  auto x_ms_last_access_time__iterator
6876  = httpResponse.GetHeaders().find("x-ms-last-access-time");
6877  if (x_ms_last_access_time__iterator != httpResponse.GetHeaders().end())
6878  {
6879  response.LastAccessedOn = Azure::DateTime::Parse(
6880  x_ms_last_access_time__iterator->second, Azure::DateTime::DateFormat::Rfc1123);
6881  }
6882  for (auto i = httpResponse.GetHeaders().lower_bound("x-ms-meta-");
6883  i != httpResponse.GetHeaders().end() && i->first.substr(0, 10) == "x-ms-meta-";
6884  ++i)
6885  {
6886  response.Metadata.emplace(i->first.substr(10), i->second);
6887  }
6888  response.BlobType = BlobType(httpResponse.GetHeaders().at("x-ms-blob-type"));
6889  auto x_ms_lease_status__iterator = httpResponse.GetHeaders().find("x-ms-lease-status");
6890  if (x_ms_lease_status__iterator != httpResponse.GetHeaders().end())
6891  {
6892  response.LeaseStatus = LeaseStatus(x_ms_lease_status__iterator->second);
6893  }
6894  auto x_ms_lease_state__iterator = httpResponse.GetHeaders().find("x-ms-lease-state");
6895  if (x_ms_lease_state__iterator != httpResponse.GetHeaders().end())
6896  {
6897  response.LeaseState = LeaseState(x_ms_lease_state__iterator->second);
6898  }
6899  auto x_ms_lease_duration__iterator
6900  = httpResponse.GetHeaders().find("x-ms-lease-duration");
6901  if (x_ms_lease_duration__iterator != httpResponse.GetHeaders().end())
6902  {
6903  response.LeaseDuration = LeaseDurationType(x_ms_lease_duration__iterator->second);
6904  }
6905  response.BlobSize = std::stoll(httpResponse.GetHeaders().at("content-length"));
6906  auto content_type__iterator = httpResponse.GetHeaders().find("content-type");
6907  if (content_type__iterator != httpResponse.GetHeaders().end())
6908  {
6909  response.HttpHeaders.ContentType = content_type__iterator->second;
6910  }
6911  auto content_encoding__iterator = httpResponse.GetHeaders().find("content-encoding");
6912  if (content_encoding__iterator != httpResponse.GetHeaders().end())
6913  {
6914  response.HttpHeaders.ContentEncoding = content_encoding__iterator->second;
6915  }
6916  auto content_language__iterator = httpResponse.GetHeaders().find("content-language");
6917  if (content_language__iterator != httpResponse.GetHeaders().end())
6918  {
6919  response.HttpHeaders.ContentLanguage = content_language__iterator->second;
6920  }
6921  auto cache_control__iterator = httpResponse.GetHeaders().find("cache-control");
6922  if (cache_control__iterator != httpResponse.GetHeaders().end())
6923  {
6924  response.HttpHeaders.CacheControl = cache_control__iterator->second;
6925  }
6926  auto content_md5__iterator = httpResponse.GetHeaders().find("content-md5");
6927  if (content_md5__iterator != httpResponse.GetHeaders().end())
6928  {
6929  response.HttpHeaders.ContentHash.Value
6930  = Azure::Core::Convert::Base64Decode(content_md5__iterator->second);
6931  }
6932  auto x_ms_blob_content_md5__iterator
6933  = httpResponse.GetHeaders().find("x-ms-blob-content-md5");
6934  if (x_ms_blob_content_md5__iterator != httpResponse.GetHeaders().end())
6935  {
6936  response.HttpHeaders.ContentHash.Value
6937  = Azure::Core::Convert::Base64Decode(x_ms_blob_content_md5__iterator->second);
6938  }
6939  auto content_disposition__iterator
6940  = httpResponse.GetHeaders().find("content-disposition");
6941  if (content_disposition__iterator != httpResponse.GetHeaders().end())
6942  {
6943  response.HttpHeaders.ContentDisposition = content_disposition__iterator->second;
6944  }
6945  auto x_ms_blob_sequence_number__iterator
6946  = httpResponse.GetHeaders().find("x-ms-blob-sequence-number");
6947  if (x_ms_blob_sequence_number__iterator != httpResponse.GetHeaders().end())
6948  {
6949  response.SequenceNumber = std::stoll(x_ms_blob_sequence_number__iterator->second);
6950  }
6951  auto x_ms_blob_committed_block_count__iterator
6952  = httpResponse.GetHeaders().find("x-ms-blob-committed-block-count");
6953  if (x_ms_blob_committed_block_count__iterator != httpResponse.GetHeaders().end())
6954  {
6955  response.CommittedBlockCount
6956  = std::stoi(x_ms_blob_committed_block_count__iterator->second);
6957  }
6958  auto x_ms_blob_sealed__iterator = httpResponse.GetHeaders().find("x-ms-blob-sealed");
6959  if (x_ms_blob_sealed__iterator != httpResponse.GetHeaders().end())
6960  {
6961  response.IsSealed = x_ms_blob_sealed__iterator->second == "true";
6962  }
6963  response.IsServerEncrypted
6964  = httpResponse.GetHeaders().at("x-ms-server-encrypted") == "true";
6965  auto x_ms_encryption_key_sha256__iterator
6966  = httpResponse.GetHeaders().find("x-ms-encryption-key-sha256");
6967  if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
6968  {
6969  response.EncryptionKeySha256
6970  = Azure::Core::Convert::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
6971  }
6972  auto x_ms_encryption_scope__iterator
6973  = httpResponse.GetHeaders().find("x-ms-encryption-scope");
6974  if (x_ms_encryption_scope__iterator != httpResponse.GetHeaders().end())
6975  {
6976  response.EncryptionScope = x_ms_encryption_scope__iterator->second;
6977  }
6978  auto x_ms_access_tier__iterator = httpResponse.GetHeaders().find("x-ms-access-tier");
6979  if (x_ms_access_tier__iterator != httpResponse.GetHeaders().end())
6980  {
6981  response.AccessTier = AccessTier(x_ms_access_tier__iterator->second);
6982  }
6983  auto x_ms_access_tier_inferred__iterator
6984  = httpResponse.GetHeaders().find("x-ms-access-tier-inferred");
6985  if (x_ms_access_tier_inferred__iterator != httpResponse.GetHeaders().end())
6986  {
6987  response.IsAccessTierInferred = x_ms_access_tier_inferred__iterator->second == "true";
6988  }
6989  auto x_ms_archive_status__iterator
6990  = httpResponse.GetHeaders().find("x-ms-archive-status");
6991  if (x_ms_archive_status__iterator != httpResponse.GetHeaders().end())
6992  {
6993  response.ArchiveStatus = ArchiveStatus(x_ms_archive_status__iterator->second);
6994  }
6995  auto x_ms_rehydrate_priority__iterator
6996  = httpResponse.GetHeaders().find("x-ms-rehydrate-priority");
6997  if (x_ms_rehydrate_priority__iterator != httpResponse.GetHeaders().end())
6998  {
6999  response.RehydratePriority
7000  = RehydratePriority(x_ms_rehydrate_priority__iterator->second);
7001  }
7002  auto x_ms_access_tier_change_time__iterator
7003  = httpResponse.GetHeaders().find("x-ms-access-tier-change-time");
7004  if (x_ms_access_tier_change_time__iterator != httpResponse.GetHeaders().end())
7005  {
7006  response.AccessTierChangedOn = Azure::DateTime::Parse(
7007  x_ms_access_tier_change_time__iterator->second,
7008  Azure::DateTime::DateFormat::Rfc1123);
7009  }
7010  auto x_ms_copy_id__iterator = httpResponse.GetHeaders().find("x-ms-copy-id");
7011  if (x_ms_copy_id__iterator != httpResponse.GetHeaders().end())
7012  {
7013  response.CopyId = x_ms_copy_id__iterator->second;
7014  }
7015  auto x_ms_copy_source__iterator = httpResponse.GetHeaders().find("x-ms-copy-source");
7016  if (x_ms_copy_source__iterator != httpResponse.GetHeaders().end())
7017  {
7018  response.CopySource = x_ms_copy_source__iterator->second;
7019  }
7020  auto x_ms_copy_status__iterator = httpResponse.GetHeaders().find("x-ms-copy-status");
7021  if (x_ms_copy_status__iterator != httpResponse.GetHeaders().end())
7022  {
7023  response.CopyStatus = CopyStatus(x_ms_copy_status__iterator->second);
7024  }
7025  auto x_ms_copy_status_description__iterator
7026  = httpResponse.GetHeaders().find("x-ms-copy-status-description");
7027  if (x_ms_copy_status_description__iterator != httpResponse.GetHeaders().end())
7028  {
7029  response.CopyStatusDescription = x_ms_copy_status_description__iterator->second;
7030  }
7031  auto x_ms_incremental_copy__iterator
7032  = httpResponse.GetHeaders().find("x-ms-incremental-copy");
7033  if (x_ms_incremental_copy__iterator != httpResponse.GetHeaders().end())
7034  {
7035  response.IsIncrementalCopy = x_ms_incremental_copy__iterator->second == "true";
7036  }
7037  auto x_ms_copy_destination_snapshot__iterator
7038  = httpResponse.GetHeaders().find("x-ms-copy-destination-snapshot");
7039  if (x_ms_copy_destination_snapshot__iterator != httpResponse.GetHeaders().end())
7040  {
7041  response.IncrementalCopyDestinationSnapshot
7042  = x_ms_copy_destination_snapshot__iterator->second;
7043  }
7044  auto x_ms_copy_progress__iterator = httpResponse.GetHeaders().find("x-ms-copy-progress");
7045  if (x_ms_copy_progress__iterator != httpResponse.GetHeaders().end())
7046  {
7047  response.CopyProgress = x_ms_copy_progress__iterator->second;
7048  }
7049  auto x_ms_copy_completion_time__iterator
7050  = httpResponse.GetHeaders().find("x-ms-copy-completion-time");
7051  if (x_ms_copy_completion_time__iterator != httpResponse.GetHeaders().end())
7052  {
7053  response.CopyCompletedOn = Azure::DateTime::Parse(
7054  x_ms_copy_completion_time__iterator->second, Azure::DateTime::DateFormat::Rfc1123);
7055  }
7056  auto x_ms_or_policy_id__iterator = httpResponse.GetHeaders().find("x-ms-or-policy-id");
7057  if (x_ms_or_policy_id__iterator != httpResponse.GetHeaders().end())
7058  {
7059  response.ObjectReplicationDestinationPolicyId = x_ms_or_policy_id__iterator->second;
7060  }
7061  {
7062  std::map<std::string, std::vector<ObjectReplicationRule>> orPropertiesMap;
7063  for (auto i = httpResponse.GetHeaders().lower_bound("x-ms-or-");
7064  i != httpResponse.GetHeaders().end() && i->first.substr(0, 8) == "x-ms-or-";
7065  ++i)
7066  {
7067  const std::string& header = i->first;
7068  auto underscorePos = header.find('_', 8);
7069  if (underscorePos == std::string::npos)
7070  {
7071  continue;
7072  }
7073  std::string policyId
7074  = std::string(header.begin() + 8, header.begin() + underscorePos);
7075  std::string ruleId = header.substr(underscorePos + 1);
7076 
7077  ObjectReplicationRule rule;
7078  rule.RuleId = std::move(ruleId);
7079  rule.ReplicationStatus = ObjectReplicationStatus(i->second);
7080  orPropertiesMap[policyId].emplace_back(std::move(rule));
7081  }
7082  for (auto& property : orPropertiesMap)
7083  {
7084  ObjectReplicationPolicy policy;
7085  policy.PolicyId = property.first;
7086  policy.Rules = std::move(property.second);
7087  response.ObjectReplicationSourceProperties.emplace_back(std::move(policy));
7088  }
7089  }
7090  auto x_ms_tag_count__iterator = httpResponse.GetHeaders().find("x-ms-tag-count");
7091  if (x_ms_tag_count__iterator != httpResponse.GetHeaders().end())
7092  {
7093  response.TagCount = std::stoi(x_ms_tag_count__iterator->second);
7094  }
7095  auto x_ms_version_id__iterator = httpResponse.GetHeaders().find("x-ms-version-id");
7096  if (x_ms_version_id__iterator != httpResponse.GetHeaders().end())
7097  {
7098  response.VersionId = x_ms_version_id__iterator->second;
7099  }
7100  auto x_ms_is_current_version__iterator
7101  = httpResponse.GetHeaders().find("x-ms-is-current-version");
7102  if (x_ms_is_current_version__iterator != httpResponse.GetHeaders().end())
7103  {
7104  response.IsCurrentVersion = x_ms_is_current_version__iterator->second == "true";
7105  }
7106  return Azure::Response<BlobProperties>(std::move(response), std::move(pHttpResponse));
7107  }
7108 
7109  struct SetBlobHttpHeadersOptions final
7110  {
7111  Azure::Nullable<int32_t> Timeout;
7112  BlobHttpHeaders HttpHeaders;
7113  Azure::Nullable<std::string> LeaseId;
7114  Azure::Nullable<Azure::DateTime> IfModifiedSince;
7115  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
7116  Azure::ETag IfMatch;
7117  Azure::ETag IfNoneMatch;
7118  Azure::Nullable<std::string> IfTags;
7119  }; // struct SetBlobHttpHeadersOptions
7120 
7121  static Azure::Response<SetBlobHttpHeadersResult> SetHttpHeaders(
7122  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7123  const Azure::Core::Url& url,
7124  const SetBlobHttpHeadersOptions& options,
7125  const Azure::Core::Context& context)
7126  {
7127  (void)options;
7128  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7129  request.SetHeader("Content-Length", "0");
7130  request.GetUrl().AppendQueryParameter("comp", "properties");
7131  request.SetHeader("x-ms-version", "2020-02-10");
7132  if (options.Timeout.HasValue())
7133  {
7134  request.GetUrl().AppendQueryParameter(
7135  "timeout", std::to_string(options.Timeout.Value()));
7136  }
7137  if (!options.HttpHeaders.ContentType.empty())
7138  {
7139  request.SetHeader("x-ms-blob-content-type", options.HttpHeaders.ContentType);
7140  }
7141  if (!options.HttpHeaders.ContentEncoding.empty())
7142  {
7143  request.SetHeader("x-ms-blob-content-encoding", options.HttpHeaders.ContentEncoding);
7144  }
7145  if (!options.HttpHeaders.ContentLanguage.empty())
7146  {
7147  request.SetHeader("x-ms-blob-content-language", options.HttpHeaders.ContentLanguage);
7148  }
7149  if (!options.HttpHeaders.CacheControl.empty())
7150  {
7151  request.SetHeader("x-ms-blob-cache-control", options.HttpHeaders.CacheControl);
7152  }
7153  if (!Azure::Core::Convert::Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
7154  {
7155  request.SetHeader(
7156  "x-ms-blob-content-md5",
7157  Azure::Core::Convert::Base64Encode(options.HttpHeaders.ContentHash.Value));
7158  }
7159  if (!options.HttpHeaders.ContentDisposition.empty())
7160  {
7161  request.SetHeader(
7162  "x-ms-blob-content-disposition", options.HttpHeaders.ContentDisposition);
7163  }
7164  if (options.LeaseId.HasValue())
7165  {
7166  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
7167  }
7168  if (options.IfModifiedSince.HasValue())
7169  {
7170  request.SetHeader(
7171  "If-Modified-Since",
7172  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7173  }
7174  if (options.IfUnmodifiedSince.HasValue())
7175  {
7176  request.SetHeader(
7177  "If-Unmodified-Since",
7178  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7179  }
7180  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
7181  {
7182  request.SetHeader("If-Match", options.IfMatch.ToString());
7183  }
7184  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
7185  {
7186  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
7187  }
7188  if (options.IfTags.HasValue())
7189  {
7190  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7191  }
7192  auto pHttpResponse = pipeline.Send(request, context);
7193  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7194  SetBlobHttpHeadersResult response;
7195  auto http_status_code
7196  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7197  httpResponse.GetStatusCode());
7198  if (!(http_status_code == 200))
7199  {
7200  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7201  }
7202  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
7203  response.LastModified = Azure::DateTime::Parse(
7204  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
7205  auto x_ms_blob_sequence_number__iterator
7206  = httpResponse.GetHeaders().find("x-ms-blob-sequence-number");
7207  if (x_ms_blob_sequence_number__iterator != httpResponse.GetHeaders().end())
7208  {
7209  response.SequenceNumber = std::stoll(x_ms_blob_sequence_number__iterator->second);
7210  }
7211  return Azure::Response<SetBlobHttpHeadersResult>(
7212  std::move(response), std::move(pHttpResponse));
7213  }
7214 
7215  struct SetBlobMetadataOptions final
7216  {
7217  Azure::Nullable<int32_t> Timeout;
7218  Storage::Metadata Metadata;
7219  Azure::Nullable<std::string> EncryptionKey;
7220  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
7221  Azure::Nullable<EncryptionAlgorithmType> EncryptionAlgorithm;
7222  Azure::Nullable<std::string> EncryptionScope;
7223  Azure::Nullable<std::string> LeaseId;
7224  Azure::Nullable<Azure::DateTime> IfModifiedSince;
7225  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
7226  Azure::ETag IfMatch;
7227  Azure::ETag IfNoneMatch;
7228  Azure::Nullable<std::string> IfTags;
7229  }; // struct SetBlobMetadataOptions
7230 
7231  static Azure::Response<SetBlobMetadataResult> SetMetadata(
7232  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7233  const Azure::Core::Url& url,
7234  const SetBlobMetadataOptions& options,
7235  const Azure::Core::Context& context)
7236  {
7237  (void)options;
7238  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7239  request.SetHeader("Content-Length", "0");
7240  request.GetUrl().AppendQueryParameter("comp", "metadata");
7241  request.SetHeader("x-ms-version", "2020-02-10");
7242  if (options.Timeout.HasValue())
7243  {
7244  request.GetUrl().AppendQueryParameter(
7245  "timeout", std::to_string(options.Timeout.Value()));
7246  }
7247  for (const auto& pair : options.Metadata)
7248  {
7249  request.SetHeader("x-ms-meta-" + pair.first, pair.second);
7250  }
7251  if (options.EncryptionKey.HasValue())
7252  {
7253  request.SetHeader("x-ms-encryption-key", options.EncryptionKey.Value());
7254  }
7255  if (options.EncryptionKeySha256.HasValue())
7256  {
7257  request.SetHeader(
7258  "x-ms-encryption-key-sha256",
7259  Azure::Core::Convert::Base64Encode(options.EncryptionKeySha256.Value()));
7260  }
7261  if (options.EncryptionAlgorithm.HasValue())
7262  {
7263  request.SetHeader(
7264  "x-ms-encryption-algorithm", options.EncryptionAlgorithm.Value().ToString());
7265  }
7266  if (options.EncryptionScope.HasValue())
7267  {
7268  request.SetHeader("x-ms-encryption-scope", options.EncryptionScope.Value());
7269  }
7270  if (options.LeaseId.HasValue())
7271  {
7272  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
7273  }
7274  if (options.IfModifiedSince.HasValue())
7275  {
7276  request.SetHeader(
7277  "If-Modified-Since",
7278  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7279  }
7280  if (options.IfUnmodifiedSince.HasValue())
7281  {
7282  request.SetHeader(
7283  "If-Unmodified-Since",
7284  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7285  }
7286  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
7287  {
7288  request.SetHeader("If-Match", options.IfMatch.ToString());
7289  }
7290  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
7291  {
7292  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
7293  }
7294  if (options.IfTags.HasValue())
7295  {
7296  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7297  }
7298  auto pHttpResponse = pipeline.Send(request, context);
7299  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7300  SetBlobMetadataResult response;
7301  auto http_status_code
7302  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7303  httpResponse.GetStatusCode());
7304  if (!(http_status_code == 200))
7305  {
7306  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7307  }
7308  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
7309  response.LastModified = Azure::DateTime::Parse(
7310  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
7311  return Azure::Response<SetBlobMetadataResult>(
7312  std::move(response), std::move(pHttpResponse));
7313  }
7314 
7315  struct SetBlobAccessTierOptions final
7316  {
7317  Azure::Nullable<int32_t> Timeout;
7318  Models::AccessTier AccessTier;
7319  Azure::Nullable<Models::RehydratePriority> RehydratePriority;
7320  Azure::Nullable<std::string> IfTags;
7321  }; // struct SetBlobAccessTierOptions
7322 
7323  static Azure::Core::Http::Request SetAccessTierCreateMessage(
7324  const Azure::Core::Url& url,
7325  const SetBlobAccessTierOptions& options)
7326  {
7327  (void)options;
7328  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7329  request.SetHeader("Content-Length", "0");
7330  request.GetUrl().AppendQueryParameter("comp", "tier");
7331  request.SetHeader("x-ms-version", "2020-02-10");
7332  if (options.Timeout.HasValue())
7333  {
7334  request.GetUrl().AppendQueryParameter(
7335  "timeout", std::to_string(options.Timeout.Value()));
7336  }
7337  request.SetHeader("x-ms-access-tier", options.AccessTier.ToString());
7338  if (options.RehydratePriority.HasValue())
7339  {
7340  request.SetHeader(
7341  "x-ms-rehydrate-priority", options.RehydratePriority.Value().ToString());
7342  }
7343  if (options.IfTags.HasValue())
7344  {
7345  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7346  }
7347  return request;
7348  }
7349 
7350  static Azure::Response<SetBlobAccessTierResult> SetAccessTierCreateResponse(
7351  std::unique_ptr<Azure::Core::Http::RawResponse> pHttpResponse,
7352  const Azure::Core::Context& context)
7353  {
7354  (void)context;
7355  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7356  SetBlobAccessTierResult response;
7357  auto http_status_code
7358  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7359  httpResponse.GetStatusCode());
7360  if (!(http_status_code == 200 || http_status_code == 202))
7361  {
7362  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7363  }
7364  return Azure::Response<SetBlobAccessTierResult>(
7365  std::move(response), std::move(pHttpResponse));
7366  }
7367 
7368  static Azure::Response<SetBlobAccessTierResult> SetAccessTier(
7369  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7370  const Azure::Core::Url& url,
7371  const SetBlobAccessTierOptions& options,
7372  const Azure::Core::Context& context)
7373  {
7374  auto request = SetAccessTierCreateMessage(url, options);
7375  auto pHttpResponse = pipeline.Send(request, context);
7376  return SetAccessTierCreateResponse(std::move(pHttpResponse), context);
7377  }
7378 
7379  struct StartBlobCopyFromUriOptions final
7380  {
7381  Azure::Nullable<int32_t> Timeout;
7382  Storage::Metadata Metadata;
7383  std::string SourceUri;
7384  Azure::Nullable<std::string> LeaseId;
7385  Azure::Nullable<std::string> SourceLeaseId;
7386  Azure::Nullable<Models::AccessTier> AccessTier;
7387  Azure::Nullable<Models::RehydratePriority> RehydratePriority;
7388  Azure::Nullable<Azure::DateTime> IfModifiedSince;
7389  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
7390  Azure::ETag IfMatch;
7391  Azure::ETag IfNoneMatch;
7392  Azure::Nullable<std::string> IfTags;
7393  Azure::Nullable<Azure::DateTime> SourceIfModifiedSince;
7394  Azure::Nullable<Azure::DateTime> SourceIfUnmodifiedSince;
7395  Azure::ETag SourceIfMatch;
7396  Azure::ETag SourceIfNoneMatch;
7397  Azure::Nullable<std::string> SourceIfTags;
7398  Azure::Nullable<bool> ShouldSealDestination;
7399  }; // struct StartBlobCopyFromUriOptions
7400 
7401  static Azure::Response<Models::_detail::StartBlobCopyFromUriResult> StartCopyFromUri(
7402  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7403  const Azure::Core::Url& url,
7404  const StartBlobCopyFromUriOptions& options,
7405  const Azure::Core::Context& context)
7406  {
7407  (void)options;
7408  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7409  request.SetHeader("Content-Length", "0");
7410  request.SetHeader("x-ms-version", "2020-02-10");
7411  if (options.Timeout.HasValue())
7412  {
7413  request.GetUrl().AppendQueryParameter(
7414  "timeout", std::to_string(options.Timeout.Value()));
7415  }
7416  for (const auto& pair : options.Metadata)
7417  {
7418  request.SetHeader("x-ms-meta-" + pair.first, pair.second);
7419  }
7420  request.SetHeader("x-ms-copy-source", options.SourceUri);
7421  if (options.LeaseId.HasValue())
7422  {
7423  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
7424  }
7425  if (options.SourceLeaseId.HasValue())
7426  {
7427  request.SetHeader("x-ms-source-lease-id", options.SourceLeaseId.Value());
7428  }
7429  if (options.AccessTier.HasValue())
7430  {
7431  request.SetHeader("x-ms-access-tier", options.AccessTier.Value().ToString());
7432  }
7433  if (options.RehydratePriority.HasValue())
7434  {
7435  request.SetHeader(
7436  "x-ms-rehydrate-priority", options.RehydratePriority.Value().ToString());
7437  }
7438  if (options.ShouldSealDestination.HasValue())
7439  {
7440  request.SetHeader(
7441  "x-ms-seal-blob", options.ShouldSealDestination.Value() ? "true" : "false");
7442  }
7443  if (options.IfModifiedSince.HasValue())
7444  {
7445  request.SetHeader(
7446  "If-Modified-Since",
7447  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7448  }
7449  if (options.IfUnmodifiedSince.HasValue())
7450  {
7451  request.SetHeader(
7452  "If-Unmodified-Since",
7453  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7454  }
7455  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
7456  {
7457  request.SetHeader("If-Match", options.IfMatch.ToString());
7458  }
7459  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
7460  {
7461  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
7462  }
7463  if (options.IfTags.HasValue())
7464  {
7465  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7466  }
7467  if (options.SourceIfModifiedSince.HasValue())
7468  {
7469  request.SetHeader(
7470  "x-ms-source-if-modified-since",
7471  options.SourceIfModifiedSince.Value().ToString(
7472  Azure::DateTime::DateFormat::Rfc1123));
7473  }
7474  if (options.SourceIfUnmodifiedSince.HasValue())
7475  {
7476  request.SetHeader(
7477  "x-ms-source-if-unmodified-since",
7478  options.SourceIfUnmodifiedSince.Value().ToString(
7479  Azure::DateTime::DateFormat::Rfc1123));
7480  }
7481  if (options.SourceIfMatch.HasValue() && !options.SourceIfMatch.ToString().empty())
7482  {
7483  request.SetHeader("x-ms-source-if-match", options.SourceIfMatch.ToString());
7484  }
7485  if (options.SourceIfNoneMatch.HasValue() && !options.SourceIfNoneMatch.ToString().empty())
7486  {
7487  request.SetHeader("x-ms-source-if-none-match", options.SourceIfNoneMatch.ToString());
7488  }
7489  if (options.SourceIfTags.HasValue())
7490  {
7491  request.SetHeader("x-ms-source-if-tags", options.SourceIfTags.Value());
7492  }
7493  auto pHttpResponse = pipeline.Send(request, context);
7494  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7495  Models::_detail::StartBlobCopyFromUriResult response;
7496  auto http_status_code
7497  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7498  httpResponse.GetStatusCode());
7499  if (!(http_status_code == 202))
7500  {
7501  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7502  }
7503  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
7504  response.LastModified = Azure::DateTime::Parse(
7505  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
7506  response.CopyId = httpResponse.GetHeaders().at("x-ms-copy-id");
7507  response.CopyStatus = CopyStatus(httpResponse.GetHeaders().at("x-ms-copy-status"));
7508  auto x_ms_version_id__iterator = httpResponse.GetHeaders().find("x-ms-version-id");
7509  if (x_ms_version_id__iterator != httpResponse.GetHeaders().end())
7510  {
7511  response.VersionId = x_ms_version_id__iterator->second;
7512  }
7513  return Azure::Response<Models::_detail::StartBlobCopyFromUriResult>(
7514  std::move(response), std::move(pHttpResponse));
7515  }
7516 
7517  struct AbortBlobCopyFromUriOptions final
7518  {
7519  Azure::Nullable<int32_t> Timeout;
7520  std::string CopyId;
7521  Azure::Nullable<std::string> LeaseId;
7522  }; // struct AbortBlobCopyFromUriOptions
7523 
7524  static Azure::Response<AbortBlobCopyFromUriResult> AbortCopyFromUri(
7525  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7526  const Azure::Core::Url& url,
7527  const AbortBlobCopyFromUriOptions& options,
7528  const Azure::Core::Context& context)
7529  {
7530  (void)options;
7531  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7532  request.SetHeader("Content-Length", "0");
7533  request.SetHeader("x-ms-version", "2020-02-10");
7534  if (options.Timeout.HasValue())
7535  {
7536  request.GetUrl().AppendQueryParameter(
7537  "timeout", std::to_string(options.Timeout.Value()));
7538  }
7539  request.GetUrl().AppendQueryParameter("comp", "copy");
7540  request.GetUrl().AppendQueryParameter(
7541  "copyid", _internal::UrlEncodeQueryParameter(options.CopyId));
7542  request.SetHeader("x-ms-copy-action", "abort");
7543  if (options.LeaseId.HasValue())
7544  {
7545  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
7546  }
7547  auto pHttpResponse = pipeline.Send(request, context);
7548  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7549  AbortBlobCopyFromUriResult response;
7550  auto http_status_code
7551  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7552  httpResponse.GetStatusCode());
7553  if (!(http_status_code == 204))
7554  {
7555  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7556  }
7557  return Azure::Response<AbortBlobCopyFromUriResult>(
7558  std::move(response), std::move(pHttpResponse));
7559  }
7560 
7561  struct CreateBlobSnapshotOptions final
7562  {
7563  Azure::Nullable<int32_t> Timeout;
7564  Storage::Metadata Metadata;
7565  Azure::Nullable<std::string> LeaseId;
7566  Azure::Nullable<std::string> EncryptionKey;
7567  Azure::Nullable<std::vector<uint8_t>> EncryptionKeySha256;
7568  Azure::Nullable<EncryptionAlgorithmType> EncryptionAlgorithm;
7569  Azure::Nullable<std::string> EncryptionScope;
7570  Azure::Nullable<Azure::DateTime> IfModifiedSince;
7571  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
7572  Azure::ETag IfMatch;
7573  Azure::ETag IfNoneMatch;
7574  Azure::Nullable<std::string> IfTags;
7575  }; // struct CreateBlobSnapshotOptions
7576 
7577  static Azure::Response<CreateBlobSnapshotResult> CreateSnapshot(
7578  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7579  const Azure::Core::Url& url,
7580  const CreateBlobSnapshotOptions& options,
7581  const Azure::Core::Context& context)
7582  {
7583  (void)options;
7584  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7585  request.SetHeader("Content-Length", "0");
7586  request.GetUrl().AppendQueryParameter("comp", "snapshot");
7587  request.SetHeader("x-ms-version", "2020-02-10");
7588  if (options.Timeout.HasValue())
7589  {
7590  request.GetUrl().AppendQueryParameter(
7591  "timeout", std::to_string(options.Timeout.Value()));
7592  }
7593  if (options.EncryptionKey.HasValue())
7594  {
7595  request.SetHeader("x-ms-encryption-key", options.EncryptionKey.Value());
7596  }
7597  if (options.EncryptionKeySha256.HasValue())
7598  {
7599  request.SetHeader(
7600  "x-ms-encryption-key-sha256",
7601  Azure::Core::Convert::Base64Encode(options.EncryptionKeySha256.Value()));
7602  }
7603  if (options.EncryptionAlgorithm.HasValue())
7604  {
7605  request.SetHeader(
7606  "x-ms-encryption-algorithm", options.EncryptionAlgorithm.Value().ToString());
7607  }
7608  if (options.EncryptionScope.HasValue())
7609  {
7610  request.SetHeader("x-ms-encryption-scope", options.EncryptionScope.Value());
7611  }
7612  for (const auto& pair : options.Metadata)
7613  {
7614  request.SetHeader("x-ms-meta-" + pair.first, pair.second);
7615  }
7616  if (options.LeaseId.HasValue())
7617  {
7618  request.SetHeader("x-ms-lease-id", options.LeaseId.Value());
7619  }
7620  if (options.IfModifiedSince.HasValue())
7621  {
7622  request.SetHeader(
7623  "If-Modified-Since",
7624  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7625  }
7626  if (options.IfUnmodifiedSince.HasValue())
7627  {
7628  request.SetHeader(
7629  "If-Unmodified-Since",
7630  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7631  }
7632  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
7633  {
7634  request.SetHeader("If-Match", options.IfMatch.ToString());
7635  }
7636  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
7637  {
7638  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
7639  }
7640  if (options.IfTags.HasValue())
7641  {
7642  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7643  }
7644  auto pHttpResponse = pipeline.Send(request, context);
7645  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7646  CreateBlobSnapshotResult response;
7647  auto http_status_code
7648  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7649  httpResponse.GetStatusCode());
7650  if (!(http_status_code == 201))
7651  {
7652  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7653  }
7654  response.ETag = Azure::ETag(httpResponse.GetHeaders().at("etag"));
7655  response.LastModified = Azure::DateTime::Parse(
7656  httpResponse.GetHeaders().at("last-modified"), Azure::DateTime::DateFormat::Rfc1123);
7657  response.IsServerEncrypted
7658  = httpResponse.GetHeaders().at("x-ms-request-server-encrypted") == "true";
7659  auto x_ms_encryption_key_sha256__iterator
7660  = httpResponse.GetHeaders().find("x-ms-encryption-key-sha256");
7661  if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
7662  {
7663  response.EncryptionKeySha256
7664  = Azure::Core::Convert::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
7665  }
7666  auto x_ms_encryption_scope__iterator
7667  = httpResponse.GetHeaders().find("x-ms-encryption-scope");
7668  if (x_ms_encryption_scope__iterator != httpResponse.GetHeaders().end())
7669  {
7670  response.EncryptionScope = x_ms_encryption_scope__iterator->second;
7671  }
7672  response.Snapshot = httpResponse.GetHeaders().at("x-ms-snapshot");
7673  auto x_ms_version_id__iterator = httpResponse.GetHeaders().find("x-ms-version-id");
7674  if (x_ms_version_id__iterator != httpResponse.GetHeaders().end())
7675  {
7676  response.VersionId = x_ms_version_id__iterator->second;
7677  }
7678  return Azure::Response<CreateBlobSnapshotResult>(
7679  std::move(response), std::move(pHttpResponse));
7680  }
7681 
7682  struct GetBlobTagsOptions final
7683  {
7684  Azure::Nullable<int32_t> Timeout;
7685  Azure::Nullable<std::string> IfTags;
7686  }; // struct GetBlobTagsOptions
7687 
7688  static Azure::Response<Models::_detail::GetBlobTagsResult> GetTags(
7689  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7690  const Azure::Core::Url& url,
7691  const GetBlobTagsOptions& options,
7692  const Azure::Core::Context& context)
7693  {
7694  (void)options;
7695  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, url);
7696  request.SetHeader("x-ms-version", "2020-02-10");
7697  if (options.Timeout.HasValue())
7698  {
7699  request.GetUrl().AppendQueryParameter(
7700  "timeout", std::to_string(options.Timeout.Value()));
7701  }
7702  request.GetUrl().AppendQueryParameter("comp", "tags");
7703  if (options.IfTags.HasValue())
7704  {
7705  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7706  }
7707  auto pHttpResponse = pipeline.Send(request, context);
7708  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7709  Models::_detail::GetBlobTagsResult response;
7710  auto http_status_code
7711  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7712  httpResponse.GetStatusCode());
7713  if (!(http_status_code == 200))
7714  {
7715  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7716  }
7717  {
7718  const auto& httpResponseBody = httpResponse.GetBody();
7719  _internal::XmlReader reader(
7720  reinterpret_cast<const char*>(httpResponseBody.data()), httpResponseBody.size());
7721  response = GetBlobTagsResultInternalFromXml(reader);
7722  }
7723  return Azure::Response<Models::_detail::GetBlobTagsResult>(
7724  std::move(response), std::move(pHttpResponse));
7725  }
7726 
7727  struct SetBlobTagsOptions final
7728  {
7729  Azure::Nullable<int32_t> Timeout;
7730  std::map<std::string, std::string> Tags;
7731  Azure::Nullable<std::string> IfTags;
7732  }; // struct SetBlobTagsOptions
7733 
7734  static Azure::Response<SetBlobTagsResult> SetTags(
7735  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7736  const Azure::Core::Url& url,
7737  const SetBlobTagsOptions& options,
7738  const Azure::Core::Context& context)
7739  {
7740  (void)options;
7741  std::string xml_body;
7742  {
7743  _internal::XmlWriter writer;
7744  SetBlobTagsOptionsToXml(writer, options);
7745  xml_body = writer.GetDocument();
7746  writer.Write(_internal::XmlNode{_internal::XmlNodeType::End});
7747  }
7748  Azure::Core::IO::MemoryBodyStream xml_body_stream(
7749  reinterpret_cast<const uint8_t*>(xml_body.data()), xml_body.length());
7750  auto request = Azure::Core::Http::Request(
7751  Azure::Core::Http::HttpMethod::Put, url, &xml_body_stream);
7752  request.SetHeader("Content-Length", std::to_string(xml_body_stream.Length()));
7753  request.SetHeader("x-ms-version", "2020-02-10");
7754  if (options.Timeout.HasValue())
7755  {
7756  request.GetUrl().AppendQueryParameter(
7757  "timeout", std::to_string(options.Timeout.Value()));
7758  }
7759  request.GetUrl().AppendQueryParameter("comp", "tags");
7760  request.SetHeader("Content-Type", "application/xml; charset=UTF-8");
7761  if (options.IfTags.HasValue())
7762  {
7763  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7764  }
7765  auto pHttpResponse = pipeline.Send(request, context);
7766  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7767  SetBlobTagsResult response;
7768  auto http_status_code
7769  = static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
7770  httpResponse.GetStatusCode());
7771  if (!(http_status_code == 204))
7772  {
7773  throw StorageException::CreateFromResponse(std::move(pHttpResponse));
7774  }
7775  return Azure::Response<SetBlobTagsResult>(std::move(response), std::move(pHttpResponse));
7776  }
7777 
7778  struct AcquireBlobLeaseOptions final
7779  {
7780  Azure::Nullable<int32_t> Timeout;
7781  std::chrono::seconds LeaseDuration;
7782  Azure::Nullable<std::string> ProposedLeaseId;
7783  Azure::Nullable<Azure::DateTime> IfModifiedSince;
7784  Azure::Nullable<Azure::DateTime> IfUnmodifiedSince;
7785  Azure::ETag IfMatch;
7786  Azure::ETag IfNoneMatch;
7787  Azure::Nullable<std::string> IfTags;
7788  }; // struct AcquireBlobLeaseOptions
7789 
7790  static Azure::Response<Models::_detail::AcquireBlobLeaseResult> AcquireLease(
7791  Azure::Core::Http::_internal::HttpPipeline& pipeline,
7792  const Azure::Core::Url& url,
7793  const AcquireBlobLeaseOptions& options,
7794  const Azure::Core::Context& context)
7795  {
7796  (void)options;
7797  auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, url);
7798  request.SetHeader("Content-Length", "0");
7799  request.SetHeader("x-ms-version", "2020-02-10");
7800  if (options.Timeout.HasValue())
7801  {
7802  request.GetUrl().AppendQueryParameter(
7803  "timeout", std::to_string(options.Timeout.Value()));
7804  }
7805  request.GetUrl().AppendQueryParameter("comp", "lease");
7806  request.SetHeader("x-ms-lease-action", "acquire");
7807  request.SetHeader("x-ms-lease-duration", std::to_string(options.LeaseDuration.count()));
7808  if (options.ProposedLeaseId.HasValue())
7809  {
7810  request.SetHeader("x-ms-proposed-lease-id", options.ProposedLeaseId.Value());
7811  }
7812  if (options.IfModifiedSince.HasValue())
7813  {
7814  request.SetHeader(
7815  "If-Modified-Since",
7816  options.IfModifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7817  }
7818  if (options.IfUnmodifiedSince.HasValue())
7819  {
7820  request.SetHeader(
7821  "If-Unmodified-Since",
7822  options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
7823  }
7824  if (options.IfMatch.HasValue() && !options.IfMatch.ToString().empty())
7825  {
7826  request.SetHeader("If-Match", options.IfMatch.ToString());
7827  }
7828  if (options.IfNoneMatch.HasValue() && !options.IfNoneMatch.ToString().empty())
7829  {
7830  request.SetHeader("If-None-Match", options.IfNoneMatch.ToString());
7831  }
7832  if (options.IfTags.HasValue())
7833  {
7834  request.SetHeader("x-ms-if-tags", options.IfTags.Value());
7835  }
7836  auto pHttpResponse = pipeline.Send(request, context);
7837  Azure::Core::Http::RawResponse& httpResponse = *pHttpResponse;
7838  Models::_detail::AcquireBlobLeaseResult response;
7839  auto http_status_code
7840