storage_credentials parse_query(const web::http::uri& uri, bool require_signed_resource)
    {
        // Order of the strings in the sas_parameters vector is per MSDN's
        // definition of Shared Access Signatures.
        const utility::string_t sas_parameters[] = {
            protocol::uri_query_sas_version,
            protocol::uri_query_sas_resource,
            protocol::uri_query_sas_table_name,
            protocol::uri_query_sas_start,
            protocol::uri_query_sas_expiry,
            protocol::uri_query_sas_permissions,
            protocol::uri_query_sas_start_partition_key,
            protocol::uri_query_sas_start_row_key,
            protocol::uri_query_sas_end_partition_key,
            protocol::uri_query_sas_end_row_key,
            protocol::uri_query_sas_identifier,
            protocol::uri_query_sas_cache_control,
            protocol::uri_query_sas_content_disposition,
            protocol::uri_query_sas_content_encoding,
            protocol::uri_query_sas_content_language,
            protocol::uri_query_sas_content_type,
            protocol::uri_query_sas_signature,
        };

        const int sas_parameters_size = (int) (sizeof(sas_parameters) / sizeof(sas_parameters[0]));

        auto splitted_query = web::http::uri::split_query(uri.query());

        bool params_found = false;
        web::http::uri_builder builder;
        for (int i = 0; i < sas_parameters_size; ++i)
        {
            auto param = splitted_query.find(sas_parameters[i]);
            if (param != splitted_query.end())
            {
                params_found = true;
                add_query_if_not_empty(builder, param->first, param->second, /* do_encoding */ false);
            }
        }

        if (!params_found)
        {
            return storage_credentials();
        }

        auto signature = splitted_query.find(protocol::uri_query_sas_signature);
        auto signed_resource = splitted_query.find(protocol::uri_query_sas_resource);
        if ((signature == splitted_query.end()) || (require_signed_resource && (signed_resource == splitted_query.end())))
        {
            throw std::invalid_argument(protocol::error_missing_params_for_sas);
        }

        return storage_credentials(builder.query());
    }
    storage_credentials get_credentials(std::map<utility::string_t, utility::string_t>& settings)
    {
        utility::string_t account_name;
        utility::string_t account_key;
        utility::string_t shared_access_signature;

        get_setting(settings, account_name_setting_string, account_name);
        get_setting(settings, account_key_setting_string, account_key);
        get_setting(settings, shared_access_signature_setting_string, shared_access_signature);

        if (!account_name.empty() && !account_key.empty() && shared_access_signature.empty())
        {
            return storage_credentials(account_name, account_key);
        }

        if (account_name.empty() && account_key.empty() && !shared_access_signature.empty())
        {
            return storage_credentials(shared_access_signature);
        }

        return storage_credentials();
    }
    cloud_storage_account cloud_storage_account::get_development_storage_account(const web::http::uri& proxy_uri)
    {
        web::http::uri_builder builder;
        if (!proxy_uri.is_empty())
        {
            builder.set_scheme(proxy_uri.scheme());
            builder.set_host(proxy_uri.host());
        }
        else
        {
            builder.set_scheme(U("http"));
            builder.set_host(U("127.0.0.1"));
        }

        builder.set_path(devstore_account_name);

        builder.set_port(10000);
        auto blob_endpoint = storage_uri(builder.to_uri());

        builder.set_port(10001);
        auto queue_endpoint = storage_uri(builder.to_uri());

        builder.set_port(10002);
        auto table_endpoint = storage_uri(builder.to_uri());

        auto credentials = storage_credentials(devstore_account_name, devstore_account_key);
        auto account = cloud_storage_account(credentials, blob_endpoint, queue_endpoint, table_endpoint);
        
        account.m_is_development_storage_account = true;
        account.m_settings.insert(std::make_pair(use_development_storage_setting_string, use_development_storage_setting_value));
        if (!proxy_uri.is_empty())
        {
            account.m_settings.insert(std::make_pair(development_storage_proxy_uri_setting_string, proxy_uri.to_string()));
        }
        
        return account;
    }
    cloud_storage_account cloud_storage_account::parse_defaults_settings(std::map<utility::string_t, utility::string_t> settings)
    {
        utility::string_t scheme;
        utility::string_t account_name;
        utility::string_t account_key;

        if (get_setting(settings, default_endpoints_protocol_setting_string, scheme) &&
            get_setting(settings, account_name_setting_string, account_name) &&
            get_setting(settings, account_key_setting_string, account_key))
        {
            utility::string_t endpoint_suffix;
            if (!get_setting(settings, endpoint_suffix_setting_string, endpoint_suffix))
            {
                endpoint_suffix = default_endpoint_suffix;
            }

            utility::string_t blob_endpoint;
            utility::string_t queue_endpoint;
            utility::string_t table_endpoint;
            get_setting(settings, blob_endpoint_setting_string, blob_endpoint);
            get_setting(settings, queue_endpoint_setting_string, queue_endpoint);
            get_setting(settings, table_endpoint_setting_string, table_endpoint);

            if (settings.empty())
            {
                cloud_storage_account account(storage_credentials(account_name, account_key),
                    blob_endpoint.empty() ? construct_default_endpoint(scheme, account_name, default_blob_hostname_prefix, endpoint_suffix) : storage_uri(web::http::uri(blob_endpoint)),
                    queue_endpoint.empty() ? construct_default_endpoint(scheme, account_name, default_queue_hostname_prefix, endpoint_suffix) : storage_uri(web::http::uri(queue_endpoint)),
                    table_endpoint.empty() ? construct_default_endpoint(scheme, account_name, default_table_hostname_prefix, endpoint_suffix) : storage_uri(web::http::uri(table_endpoint)));

                account.m_endpoint_suffix = endpoint_suffix;
                return account;
            }
        }

        return cloud_storage_account();
    }
Ejemplo n.º 5
0
 cloud_queue::cloud_queue(const storage_uri& uri)
     : m_client(create_service_client(uri, storage_credentials())), m_name(read_queue_name(uri)), m_uri(create_uri(uri)), m_approximate_message_count(-1)
 {
 }
 cloud_table::cloud_table(const storage_uri& uri)
     : m_client(create_service_client(uri, storage_credentials())), m_name(read_table_name(uri)), m_uri(create_uri(uri))
 {
 }