Exemple #1
0
        public override void ExecuteCmdlet()
        {
            var currentAccount = DataLakeStoreClient.GetAccount(ResourceGroupName, Name);
            var location       = currentAccount.Location;

            if (string.IsNullOrEmpty(DefaultGroup))
            {
                DefaultGroup = currentAccount.Properties.DefaultGroup;
            }

            if (Tags == null)
            {
                Tags = TagsConversionHelper.CreateTagHashtable(currentAccount.Tags);
            }

            // validation of encryption parameters
            if (Encryption != null)
            {
                var identity = new EncryptionIdentity
                {
                    Type = EncryptionIdentityType.SystemAssigned,
                };
                var config = new EncryptionConfig
                {
                    Type = Encryption.Value,
                };

                if (Encryption.Value == EncryptionConfigType.UserManaged)
                {
                    if (string.IsNullOrEmpty(KeyVaultId) ||
                        string.IsNullOrEmpty(KeyName) ||
                        string.IsNullOrEmpty(KeyVersion))
                    {
                        throw new PSArgumentException(Resources.MissingKeyVaultParams);
                    }

                    config.KeyVaultMetaInfo = new KeyVaultMetaInfo
                    {
                        KeyVaultResourceId   = KeyVaultId,
                        EncryptionKeyName    = KeyName,
                        EncryptionKeyVersion = KeyVersion
                    };
                }
                else
                {
                    if (!string.IsNullOrEmpty(KeyVaultId) ||
                        !string.IsNullOrEmpty(KeyName) ||
                        !string.IsNullOrEmpty(KeyVersion))
                    {
                        WriteWarning(Resources.IgnoredKeyVaultParams);
                    }
                }

                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, location, Tags, identity, config));
            }
            else
            {
                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, location, Tags));
            }
        }
 internal Encryption(EncryptionServices services, KeySource keySource, bool?requireInfrastructureEncryption, KeyVaultProperties keyVaultProperties, EncryptionIdentity encryptionIdentity)
 {
     Services  = services;
     KeySource = keySource;
     RequireInfrastructureEncryption = requireInfrastructureEncryption;
     KeyVaultProperties = keyVaultProperties;
     EncryptionIdentity = encryptionIdentity;
 }
Exemple #3
0
        public DataLakeStoreAccount CreateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup,
            string location,
            Hashtable customTags        = null,
            EncryptionIdentity identity = null,
            EncryptionConfig config     = null,
            IList <TrustedIdProvider> trustedProviders = null,
            IList <FirewallRule> firewallRules         = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Location     = location,
                DefaultGroup = defaultGroup,
                Tags         = tags ?? new Dictionary <string, string>()
            };

            if (identity != null)
            {
                parameters.EncryptionState  = EncryptionState.Enabled;
                parameters.Identity         = identity;
                parameters.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.TrustedIdProviders     = trustedProviders;
                parameters.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.FirewallRules = firewallRules;
                parameters.FirewallState = FirewallState.Enabled;
            }

            return(_client.Account.Create(resourceGroupName, accountName, parameters));
        }
        public DataLakeStoreAccount CreateOrUpdateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup, 
            string location, 
            Hashtable customTags = null, 
            EncryptionIdentity identity = null, 
            EncryptionConfig config = null, 
            IList<TrustedIdProvider> trustedProviders = null,
            IList<FirewallRule> firewallRules = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Name = accountName,
                Location = location,
                Properties = new DataLakeStoreAccountProperties
                {
                    DefaultGroup = defaultGroup,
                },
                Tags = tags ?? new Dictionary<string, string>()
            };

            if (identity != null)
            {
                parameters.Properties.EncryptionState = EncryptionState.Enabled;
                parameters.Identity = identity;
                parameters.Properties.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.Properties.TrustedIdProviders = trustedProviders;
                parameters.Properties.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.Properties.FirewallRules = firewallRules;
                parameters.Properties.FirewallState = FirewallState.Enabled;
            }

            var accountExists = false;
            try
            {
                if (GetAccount(resourceGroupName, accountName) != null)
                {
                    accountExists = true;
                }
            }
            catch
            {
                // intentionally empty since if there is any exception attempting to 
                // get the account we know it doesn't exist and we will attempt to create it fresh.
            }

            return accountExists
                ? _client.Account.Update(resourceGroupName, accountName, parameters)
                : _client.Account.Create(resourceGroupName, accountName, parameters);
        }
        public DataLakeStoreAccount CreateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup,
            string location,
            Hashtable customTags        = null,
            EncryptionIdentity identity = null,
            EncryptionConfig config     = null,
            IList <TrustedIdProvider> trustedProviders = null,
            IList <FirewallRule> firewallRules         = null,
            EncryptionConfigType?encryptionType        = null,
            TierType?tier = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Location     = location,
                DefaultGroup = defaultGroup,
                Tags         = tags ?? new Dictionary <string, string>()
            };

            if (identity != null)
            {
                parameters.EncryptionState  = EncryptionState.Enabled;
                parameters.Identity         = identity;
                parameters.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.TrustedIdProviders     = trustedProviders;
                parameters.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.FirewallRules = firewallRules;
                parameters.FirewallState = FirewallState.Enabled;
            }

            // if there is no encryption value, then it was not set by the cmdlet which means encryption was explicitly disabled.
            if (!encryptionType.HasValue)
            {
                parameters.EncryptionState  = EncryptionState.Disabled;
                parameters.Identity         = null;
                parameters.EncryptionConfig = null;
            }

            if (tier.HasValue)
            {
                parameters.NewTier = tier;
            }

            var toReturn = _client.Account.Create(resourceGroupName, accountName, parameters);

            return(toReturn);
        }
Exemple #6
0
        public override void ExecuteCmdlet()
        {
            try
            {
                if (DataLakeStoreClient.GetAccount(ResourceGroupName, Name) != null)
                {
                    throw new CloudException(string.Format(Resources.DataLakeStoreAccountExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" ||
                    ex.Message.Contains("ResourceNotFound"))
                {
                    // account does not exists so go ahead and create one
                }
                else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) &&
                         ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            // validation of encryption parameters
            if (Encryption != null)
            {
                var identity = new EncryptionIdentity
                {
                    Type = EncryptionIdentityType.SystemAssigned,
                };
                var config = new EncryptionConfig
                {
                    Type = Encryption.Value,
                };

                if (Encryption.Value == EncryptionConfigType.UserManaged)
                {
                    if (string.IsNullOrEmpty(KeyVaultId) ||
                        string.IsNullOrEmpty(KeyName) ||
                        string.IsNullOrEmpty(KeyVersion))
                    {
                        throw new PSArgumentException(Resources.MissingKeyVaultParams);
                    }

                    config.KeyVaultMetaInfo = new KeyVaultMetaInfo
                    {
                        KeyVaultResourceId   = KeyVaultId,
                        EncryptionKeyName    = KeyName,
                        EncryptionKeyVersion = KeyVersion
                    };
                }
                else
                {
                    if (!string.IsNullOrEmpty(KeyVaultId) ||
                        !string.IsNullOrEmpty(KeyName) ||
                        !string.IsNullOrEmpty(KeyVersion))
                    {
                        WriteWarning(Resources.IgnoredKeyVaultParams);
                    }
                }

                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, Location, Tags, identity, config));
            }
            else
            {
                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, Location, Tags));
            }
        }
        public override void ExecuteCmdlet()
        {
            var currentAccount = DataLakeStoreClient.GetAccount(ResourceGroupName, Name);
            var location = currentAccount.Location;

            if (string.IsNullOrEmpty(DefaultGroup))
            {
                DefaultGroup = currentAccount.Properties.DefaultGroup;
            }

            if (Tags == null)
            {
                Tags = TagsConversionHelper.CreateTagHashtable(currentAccount.Tags);
            }

            // validation of encryption parameters
            if (Encryption != null)
            {
                var identity = new EncryptionIdentity
                {
                    Type = EncryptionIdentityType.SystemAssigned,
                };
                var config = new EncryptionConfig
                {
                    Type = Encryption.Value,
                };

                if (Encryption.Value == EncryptionConfigType.UserManaged)
                {
                    if (string.IsNullOrEmpty(KeyVaultId) ||
                    string.IsNullOrEmpty(KeyName) ||
                    string.IsNullOrEmpty(KeyVersion))
                    {
                        throw new PSArgumentException(Resources.MissingKeyVaultParams);
                    }

                    config.KeyVaultMetaInfo = new KeyVaultMetaInfo
                    {
                        KeyVaultResourceId = KeyVaultId,
                        EncryptionKeyName = KeyName,
                        EncryptionKeyVersion = KeyVersion
                    };
                }
                else
                {
                    if (!string.IsNullOrEmpty(KeyVaultId) ||
                    !string.IsNullOrEmpty(KeyName) ||
                    !string.IsNullOrEmpty(KeyVersion))
                    {
                        WriteWarning(Resources.IgnoredKeyVaultParams);
                    }
                }

                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, location, Tags, identity, config));
            }
            else
            {
                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, location, Tags));
            }
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                if (DataLakeStoreClient.GetAccount(ResourceGroupName, Name) != null)
                {
                    throw new CloudException(string.Format(Resources.DataLakeStoreAccountExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" ||
                    ex.Message.Contains("ResourceNotFound"))
                {
                    // account does not exists so go ahead and create one
                }
                else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) &&
                         ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            // validation of encryption parameters
            if (Encryption != null)
            {
                var identity = new EncryptionIdentity
                {
                    Type = EncryptionIdentityType.SystemAssigned,
                };
                var config = new EncryptionConfig
                {
                    Type = Encryption.Value,
                };

                if (Encryption.Value == EncryptionConfigType.UserManaged)
                {
                    if (string.IsNullOrEmpty(KeyVaultId) ||
                    string.IsNullOrEmpty(KeyName) ||
                    string.IsNullOrEmpty(KeyVersion))
                    {
                        throw new PSArgumentException(Resources.MissingKeyVaultParams);
                    }

                    config.KeyVaultMetaInfo = new KeyVaultMetaInfo
                    {
                        KeyVaultResourceId = KeyVaultId,
                        EncryptionKeyName = KeyName,
                        EncryptionKeyVersion = KeyVersion
                    };
                }
                else
                {
                    if (!string.IsNullOrEmpty(KeyVaultId) ||
                    !string.IsNullOrEmpty(KeyName) ||
                    !string.IsNullOrEmpty(KeyVersion))
                    {
                        WriteWarning(Resources.IgnoredKeyVaultParams);
                    }
                }

                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, Location, Tags, identity, config));
            }
            else
            {
                WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, Location, Tags));
            }
        }
        public DataLakeStoreAccount CreateOrUpdateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup,
            string location,
            Hashtable customTags        = null,
            EncryptionIdentity identity = null,
            EncryptionConfig config     = null,
            IList <TrustedIdProvider> trustedProviders = null,
            IList <FirewallRule> firewallRules         = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Name       = accountName,
                Location   = location,
                Properties = new DataLakeStoreAccountProperties
                {
                    DefaultGroup = defaultGroup,
                },
                Tags = tags ?? new Dictionary <string, string>()
            };

            if (identity != null)
            {
                parameters.Properties.EncryptionState = EncryptionState.Enabled;
                parameters.Identity = identity;
                parameters.Properties.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.Properties.TrustedIdProviders     = trustedProviders;
                parameters.Properties.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.Properties.FirewallRules = firewallRules;
                parameters.Properties.FirewallState = FirewallState.Enabled;
            }

            var accountExists = false;

            try
            {
                if (GetAccount(resourceGroupName, accountName) != null)
                {
                    accountExists = true;
                }
            }
            catch
            {
                // intentionally empty since if there is any exception attempting to
                // get the account we know it doesn't exist and we will attempt to create it fresh.
            }

            return(accountExists
                ? _client.Account.Update(resourceGroupName, accountName, parameters)
                : _client.Account.Create(resourceGroupName, accountName, parameters));
        }