示例#1
0
        public DataLakeClientOptions GetFaultyDataLakeConnectionOptions(
            int raiseAt     = default,
            Exception raise = default,
            Action onFault  = default)
        {
            raise = raise ?? new IOException("Simulated connection fault");
            DataLakeClientOptions options = GetOptions();

            options.AddPolicy(new FaultyDownloadPipelinePolicy(raiseAt, raise, onFault), HttpPipelinePosition.PerCall);
            return(options);
        }
        public void Ctor_CPK_Http()
        {
            // Arrange
            DataLakeCustomerProvidedKey customerProvidedKey   = GetCustomerProvidedKey();
            DataLakeClientOptions       dataLakeClientOptions = new DataLakeClientOptions
            {
                CustomerProvidedKey = customerProvidedKey
            };
            Uri httpUri = new Uri(TestConfigHierarchicalNamespace.BlobServiceEndpoint).ToHttp();

            // Act
            TestHelper.AssertExpectedException(
                () => new DataLakeServiceClient(httpUri, dataLakeClientOptions),
                new ArgumentException("Cannot use client-provided key without HTTPS."));
        }
示例#3
0
        public DataLakeClientOptions GetOptions(bool parallelRange = false)
        {
            var options = new DataLakeClientOptions
            {
                Diagnostics = { IsLoggingEnabled = true },
                Retry       =
                {
                    Mode       = RetryMode.Exponential,
                    MaxRetries = Constants.MaxReliabilityRetries,
                    Delay      = TimeSpan.FromSeconds(Mode == RecordedTestMode.Playback ? 0.01 : 0.5),
                    MaxDelay   = TimeSpan.FromSeconds(Mode == RecordedTestMode.Playback ? 0.1 : 10)
                }
            };

            if (Mode != RecordedTestMode.Live)
            {
                options.AddPolicy(new RecordedClientRequestIdPolicy(Recording, parallelRange), HttpPipelinePosition.PerCall);
            }

            return(Recording.InstrumentClientOptions(options));
        }
示例#4
0
        /// <summary>
        /// Get SAS string for DatalakeGen2
        /// </summary>
        public static string GetDatalakeGen2SharedAccessSignature(AzureStorageContext context, DataLakeSasBuilder sasBuilder, bool generateUserDelegationSas, DataLakeClientOptions clientOptions, CancellationToken cancelToken)
        {
            if (context != null && context.StorageAccount.Credentials.IsSharedKey)
            {
                return(sasBuilder.ToSasQueryParameters(new StorageSharedKeyCredential(context.StorageAccountName, context.StorageAccount.Credentials.ExportBase64EncodedKey())).ToString());
            }
            if (generateUserDelegationSas)
            {
                global::Azure.Storage.Files.DataLake.Models.UserDelegationKey userDelegationKey = null;
                DataLakeServiceClient oauthService = new DataLakeServiceClient(context.StorageAccount.BlobEndpoint, context.Track2OauthToken, clientOptions);

                Util.ValidateUserDelegationKeyStartEndTime(sasBuilder.StartsOn, sasBuilder.ExpiresOn);

                userDelegationKey = oauthService.GetUserDelegationKey(
                    startsOn: sasBuilder.StartsOn == DateTimeOffset.MinValue || sasBuilder.StartsOn == null ? DateTimeOffset.UtcNow : sasBuilder.StartsOn.ToUniversalTime(),
                    expiresOn: sasBuilder.ExpiresOn.ToUniversalTime(),
                    cancellationToken: cancelToken);

                return(sasBuilder.ToSasQueryParameters(userDelegationKey, context.StorageAccountName).ToString());
            }
            else
            {
                throw new InvalidOperationException("Create SAS only supported with SharedKey or Oauth credentail.");
            }
        }
示例#5
0
        /// <summary>
        /// Get a service client for ADLS Gen2 and use AAD token for authorization
        /// </summary>
        public DataLakeServiceClient GetDataLakeServiceClient(string accountName, string clientID,
                                                              string clientSecret, string tenantID, DataLakeClientOptions options = null)
        {
            TokenCredential credential = new ClientSecretCredential(
                tenantID, clientID, clientSecret, new TokenCredentialOptions());

            string dfsUri = "https://" + accountName + ".dfs.core.windows.net";

            if (options == null)
            {
                return(new DataLakeServiceClient(new Uri(dfsUri), credential));
            }
            else
            {
                return(new DataLakeServiceClient(new Uri(dfsUri), credential, options));
            }
        }