コード例 #1
0
        public void NewAzureAutomationVariableByPathSuccessfull()
        {
            // Setup
            string resourceGroupName = "resourceGroup";
            string accountName = "automation";
            string variableName = "variable";
            string value = "value";
            string description = "desc";

            var variable = new Variable();
            variable.ResourceGroupName = resourceGroupName;
            variable.Name = variableName;
            variable.Value = value;
            variable.Description = description;
            variable.Encrypted = true;
            variable.AutomationAccountName = accountName;

            this.mockAutomationClient.Setup(
                f => f.CreateVariable(variable));

            this.cmdlet.ResourceGroupName = resourceGroupName;
            this.cmdlet.AutomationAccountName = accountName;
            this.cmdlet.Name = variableName;
            this.cmdlet.Description = description;
            this.cmdlet.Value = value;
            this.cmdlet.Encrypted = true;
            this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByName);
            this.cmdlet.ExecuteCmdlet();

            // Assert
            this.mockAutomationClient.Verify(f => f.CreateVariable(variable), Times.Once());
        }
コード例 #2
0
ファイル: AutomationClient.cs プロジェクト: elvg/ASCTest
        public Variable CreateVariable(string automationAccountName, Variable variable)
        {
            bool variableExists = true;

            try
            {
                this.GetVariable(automationAccountName, variable.Name);
            }
            catch (ResourceNotFoundException)
            {
                variableExists = false;
            }

            if (variableExists)
            {
                throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                          Resources.VariableAlreadyExists, variable.Name));
            }

            if (variable.Encrypted)
            {
                var createParams = new AutomationManagement.Models.EncryptedVariableCreateParameters()
                {
                    Name       = variable.Name,
                    Properties = new AutomationManagement.Models.EncryptedVariableCreateProperties()
                    {
                        Value       = variable.Value,
                        Description = variable.Description
                    }
                };

                var sdkCreatedVariable =
                    this.automationManagementClient.EncryptedVariables.Create(automationAccountName, createParams)
                    .EncryptedVariable;

                return(new Variable(sdkCreatedVariable, automationAccountName));
            }
            else
            {
                var createParams = new AutomationManagement.Models.VariableCreateParameters()
                {
                    Name       = variable.Name,
                    Properties = new AutomationManagement.Models.VariableCreateProperties()
                    {
                        Value       = variable.Value,
                        Description = variable.Description
                    }
                };

                var sdkCreatedVariable =
                    this.automationManagementClient.Variables.Create(automationAccountName, createParams).Variable;

                return(new Variable(sdkCreatedVariable, automationAccountName));
            }
        }
コード例 #3
0
        protected override void AutomationExecuteCmdlet()
        {
            Variable variable = new Variable()
            {
                Name = this.Name,
                Description = this.Description,
                Value = this.Value
            };

            var ret = this.AutomationClient.UpdateVariable(this.AutomationAccountName, variable);
            
            this.GenerateCmdletOutput(ret);
        }
コード例 #4
0
        protected override void AutomationProcessRecord()
        {
            Variable variable = new Variable()
            {
                Name = this.Name,
                Encrypted = this.Encrypted,
                Description = this.Description,
                Value = this.Value,
                AutomationAccountName = this.AutomationAccountName,
                ResourceGroupName = this.ResourceGroupName
            };

            var ret = this.AutomationClient.CreateVariable(variable);

            this.GenerateCmdletOutput(ret);
        }
コード例 #5
0
        protected override void AutomationExecuteCmdlet()
        {
            Variable variable = new Variable()
            {
                Name = this.Name,
                Description = this.Description,
                Encrypted = this.Encrypted,
                Value = this.Value,
                AutomationAccountName = this.AutomationAccountName
            };

            Variable ret;
            if (ParameterSetName == AutomationCmdletParameterSets.UpdateVariableValue)
            { 
                ret = this.AutomationClient.UpdateVariable(variable, VariableUpdateFields.OnlyValue);
            }
            else
            {
                ret = this.AutomationClient.UpdateVariable(variable, VariableUpdateFields.OnlyDescription);
            }
            this.GenerateCmdletOutput(ret);
        }
コード例 #6
0
ファイル: AutomationClient.cs プロジェクト: elvg/ASCTest
        public Variable UpdateVariable(string automationAccountName, Variable variable)
        {
            var existingVarible = this.GetVariable(automationAccountName, variable.Name);

            variable.Encrypted = existingVarible.Encrypted;

            if (variable.Encrypted)
            {
                var updateParams = new AutomationManagement.Models.EncryptedVariableUpdateParameters()
                {
                    Name       = variable.Name,
                    Properties = new AutomationManagement.Models.EncryptedVariableUpdateProperties()
                    {
                        Value       = variable.Value,
                        Description = variable.Description
                    }
                };

                this.automationManagementClient.EncryptedVariables.Update(automationAccountName, updateParams);
            }
            else
            {
                var updateParams = new AutomationManagement.Models.VariableUpdateParameters()
                {
                    Name       = variable.Name,
                    Properties = new AutomationManagement.Models.VariableUpdateProperties()
                    {
                        Value       = variable.Value,
                        Description = variable.Description
                    }
                };

                this.automationManagementClient.Variables.Update(automationAccountName, updateParams);
            }

            return(this.GetVariable(automationAccountName, variable.Name));
        }
コード例 #7
0
        public Variable UpdateVariable(Variable variable, VariableUpdateFields updateFields)
        {
            var existingVariable = this.GetVariable(variable.AutomationAccountName, variable.Name);

            if (existingVariable.Encrypted != variable.Encrypted)
            {
                throw new ResourceNotFoundException(typeof(Variable),
                    string.Format(CultureInfo.CurrentCulture, Resources.VariableEncryptionCannotBeChanged, variable.Name, existingVariable.Encrypted));
            }

            var updateParams = new AutomationManagement.Models.VariableUpdateParameters()
            {
                Name = variable.Name,
            };

            if (updateFields == VariableUpdateFields.OnlyDescription)
            {
                updateParams.Properties = new AutomationManagement.Models.VariableUpdateProperties()
                {
                    Description = variable.Description
                };
            }
            else
            {
                updateParams.Properties = new AutomationManagement.Models.VariableUpdateProperties()
                {
                    Value = PowerShellJsonConverter.Serialize(variable.Value)
                };
            }

            this.automationManagementClient.Variables.Update(variable.AutomationAccountName, updateParams);
            
            return this.GetVariable(variable.AutomationAccountName, variable.Name);
        }
コード例 #8
0
        public Variable CreateVariable(Variable variable)
        {
            bool variableExists = true;

            try
            {
                this.GetVariable(variable.AutomationAccountName, variable.Name);
            }
            catch (ResourceNotFoundException)
            {
                variableExists = false;
            }

            if (variableExists)
            {
                throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture,
                    Resources.VariableAlreadyExists, variable.Name));
            }

            var createParams = new AutomationManagement.Models.VariableCreateParameters()
            {
                Name = variable.Name,
                Properties = new AutomationManagement.Models.VariableCreateProperties()
                {
                    Value = PowerShellJsonConverter.Serialize(variable.Value),
                    Description = variable.Description,
                    IsEncrypted = variable.Encrypted
                }
            };

            var sdkCreatedVariable =
                this.automationManagementClient.Variables.Create(variable.AutomationAccountName, createParams).Variable;

            return new Variable(sdkCreatedVariable, variable.AutomationAccountName);
        }