コード例 #1
0
        private string GetStorageAccountKey(string resourceGroupName, string clusterName)
        {
            string       storageAccountKey       = null;
            string       errorMessage            = "Fails to retrieve storage account key. Please specify DefaultStorageAccountKey explicitly.";
            const string AuthorizationFailedCode = "AuthorizationFailed";

            try
            {
                IDictionary <string, string> coreSiteClusterConfiguration;
                HDInsightManagementClient.ListConfigurations(resourceGroupName, clusterName).Configurations.TryGetValue(ConfigurationKey.CoreSite, out coreSiteClusterConfiguration);
                coreSiteClusterConfiguration?.TryGetValue(Constants.ClusterConfiguration.StorageAccountKeyPrefix + DefaultStorageAccountName, out storageAccountKey);
            }
            catch (CloudException cloudEx)
            {
                if (cloudEx.Error.Code == AuthorizationFailedCode)
                {
                    errorMessage = "Insufficient permissions to retrieve storage account key. Please specify DefaultStorageAccountKey explicitly.";
                }
            }
            catch (Exception ex)
            {
                errorMessage = errorMessage + " Reason: " + ex.Message;
            }

            if (storageAccountKey == null)
            {
                throw new CloudException(errorMessage);
            }

            return(storageAccountKey);
        }