how to get shared access signature of Azure container by C++ -
i want use c++ azure api generate shared access signature container on azure , access string. cannot find example. examples in c#. found this, https://docs.microsoft.com/en-us/azure/storage/files/storage-c-plus-plus-how-to-use-files
here did,
// retrieve reference created container. azure::storage::cloud_blob_container container = blob_client.get_container_reference(s2ws(eventid)); // create container if doesn't exist. container.create_if_not_exists(); // current permissions event. auto blobpermissions = container.download_permissions(); // create , assign policy utility::string_t policy_name = s2ws("signature" + eventid); azure::storage::blob_shared_access_policy policy = azure::storage::blob_shared_access_policy(); // set expire date policy.set_expiry(utility::datetime::utc_now() + utility::datetime::from_days(10)); //give read , write permissions policy.set_permissions(azure::storage::blob_shared_access_policy::permissions::read); azure::storage::shared_access_policies<azure::storage::blob_shared_access_policy> policies; //add new shared policy policies.insert(std::make_pair(policy_name, policy)); blobpermissions.set_policies(policies); blobpermissions.set_public_access(azure::storage::blob_container_public_access_type::off); container.upload_permissions(blobpermissions); auto token = container.get_shared_access_signature(policy, policy_name);
after run this, can see policy set on container, token got last line not right. , there exception when exiting function, breakpoint locates in _deallocate().
could tell me what's wrong code? or examples this? thank much.
edited
the token got looks like,
"sv=2016-05-31&si=signature11111122222222&sig=jdw33j1gzv00reffr8xjz5kavh18wme8e7vz%2ffquj3y%3d&spr=https%2chttp&se=2027-09-09t05%3a54%3a29z&sp=r&sr=c"
by token, couldn't access blobs. right token created "microsoft azure storage explorer" using policy looks like,
?sv=2016-05-31&si=signature11111122222222&sr=c&sig=9ts91duk7nkilifzdmdadlnefn2hyybvhc10iimp1sk%3d
about exception, put these code in function. if without last line, okay. if added last line, while exiting function, throw exception , said breakpoint triggered. stopped @ last line of _deallocate() in "c:\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xmemory0",
::operator delete(_ptr);
have no idea why exception being thrown , how debug because seems cannot caught code.
edited
after changed last line to,
auto token = container.get_shared_access_signature(azure::storage::blob_shared_access_policy(), policy_name);
the returned token right, can access blobs using it. annoying exception still there :-(
edited
just found exception happened when building in debug. if in release, ok. maybe it's related compiling environment.
when creating shared access signature (sas)
, there few permissions set: sas start/expiry, permissions, ip acling, protocol restrictions etc. create access policy on blob container these things, create ad-hoc sas (i.e. without access policy) these things or combine these 2 create sas token.
one key thing keep in mind if defined in access policy, can't redefine them when creating sas. example, let's create access policy read
permission , nothing else, can't provide permissions when creating sas token while using access policy. can define things not there in access policy (for example, can define sas expiry if not defined in access policy).
if @ code (before edit), you're doing creating access policy permissions , creating sas token using same permissions , access policy. that's why did not work. when created sas token microsoft's storage explorer, notice included access policy (si=signature11111122222222
) , none of other parameters , that's why worked.
in code after edit did not include permissions used access policy (in way did storage explorer doing) , that's why things worked after edit.
i hope explains mystery behind not working/working sas tokens.
Comments
Post a Comment