Skip to content

Commit b671ca1

Browse files
saving changes before pull
1 parent b5625c3 commit b671ca1

File tree

7 files changed

+89
-65
lines changed

7 files changed

+89
-65
lines changed

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public override void ExecuteCmdlet()
8585
}
8686
}
8787

88-
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
88+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
8989
{
90-
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.AutomationAccountNotFound), cloudException);
90+
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ResourceNotFound), cloudException);
9191
}
9292

9393
throw;
@@ -131,19 +131,17 @@ protected bool GenerateCmdletOutput(IEnumerable<object> results)
131131
private string ParseErrorMessage(string errorMessage)
132132
{
133133
// The errorMessage is expected to be the error details in JSON format.
134-
// e.g. <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
135-
// {"odata.error":{"code":"","message":{"lang":"en-US","value":"Runbook definition is invalid. Missing closing '}' in statement block."}}}
136-
// </string>
134+
// e.g. <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">{"code":"NotFound","message":"Certificate not found."}</string>
137135
try
138136
{
139137
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(XDocument.Load(new StringReader(errorMessage)).Root.Value)))
140138
{
141139
var serializer = new DataContractJsonSerializer(typeof(ErrorResponse));
142140
var errorResponse = (ErrorResponse)serializer.ReadObject(memoryStream);
143141

144-
if (!string.IsNullOrWhiteSpace(errorResponse.OdataError.Message.Value))
142+
if (!string.IsNullOrWhiteSpace(errorResponse.Message))
145143
{
146-
return errorResponse.OdataError.Message.Value;
144+
return errorResponse.Message;
147145
}
148146
}
149147
}

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationRunbook.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
15+
using System.Collections;
1716
using System.Management.Automation;
1817
using System.Security.Permissions;
1918
using Microsoft.Azure.Commands.Automation.Common;
@@ -56,7 +55,7 @@ public class NewAzureAutomationRunbook : AzureAutomationBaseCmdlet
5655
/// </summary>
5756
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook tags.")]
5857
[Alias("Tag")]
59-
public IDictionary<string, string> Tags { get; set; }
58+
public IDictionary Tags { get; set; }
6059

6160
/// <summary>
6261
/// Execute this cmdlet.

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationCertificate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class SetAzureAutomationCertificate : AzureAutomationBaseCmdlet
6262
/// Gets or sets the certificate exportable Property.
6363
/// </summary>
6464
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The exportable property of the variable.")]
65-
public SwitchParameter Exportable { get; set; }
65+
public bool? Exportable { get; set; }
6666

6767
/// <summary>
6868
/// Execute this cmdlet.
@@ -71,7 +71,7 @@ public class SetAzureAutomationCertificate : AzureAutomationBaseCmdlet
7171
protected override void AutomationExecuteCmdlet()
7272
{
7373

74-
var updateddCertificate = this.AutomationClient.UpdateCertificate(this.AutomationAccountName, this.Name, this.Path, this.Password, this.Description, this.Exportable.IsPresent);
74+
var updateddCertificate = this.AutomationClient.UpdateCertificate(this.AutomationAccountName, this.Name, this.Path, this.Password, this.Description, this.Exportable);
7575

7676
this.WriteObject(updateddCertificate);
7777
}

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationRunbook.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
15+
using System.Collections;
1716
using System.Management.Automation;
1817
using System.Security.Permissions;
1918
using Microsoft.Azure.Commands.Automation.Common;
@@ -46,7 +45,7 @@ public class SetAzureAutomationRunbook : AzureAutomationBaseCmdlet
4645
/// Gets or sets the runbook tags.
4746
/// </summary>
4847
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook tags.")]
49-
public IDictionary<string, string> Tags { get; set; }
48+
public IDictionary Tags { get; set; }
5049

5150
/// <summary>
5251
/// Gets or sets a value indicating whether progress logging should be turned on or off.

src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
using Microsoft.Azure.Commands.Automation.Properties;
2626
using Microsoft.Azure.Management.Automation;
2727
using Microsoft.Azure.Management.Automation.Models;
28-
using Microsoft.WindowsAzure;
29-
using Microsoft.WindowsAzure.Commands.Common;
30-
using Microsoft.Azure.Common.Extensions.Models;
3128
using Newtonsoft.Json;
3229

3330
using Runbook = Microsoft.Azure.Commands.Automation.Model.Runbook;
@@ -179,7 +176,7 @@ public IEnumerable<Runbook> ListRunbooks(string automationAccountName)
179176
}
180177

181178
public Runbook CreateRunbookByName(string automationAccountName, string runbookName, string description,
182-
IDictionary<string, string> tags)
179+
IDictionary tags)
183180
{
184181
var runbookModel = this.TryGetRunbookModel(automationAccountName, runbookName);
185182
if (runbookModel != null)
@@ -195,16 +192,17 @@ public Runbook CreateRunbookByName(string automationAccountName, string runbookN
195192
Draft = new RunbookDraft()
196193
};
197194

198-
var rdcparam = new RunbookCreateDraftParameters() { Name = runbookName, Properties = rdcprop, Tags = tags };
195+
var rdcparam = new RunbookCreateDraftParameters() { Name = runbookName, Properties = rdcprop, Tags = (tags != null) ? tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString()) : null };
199196

200197
this.automationManagementClient.Runbooks.CreateWithDraft(automationAccountName, rdcparam);
201198

202199
return this.GetRunbook(automationAccountName, runbookName);
203200
}
204201

205202
public Runbook CreateRunbookByPath(string automationAccountName, string runbookPath, string description,
206-
IDictionary<string, string> tags)
203+
IDictionary tags)
207204
{
205+
208206
var runbookName = Path.GetFileNameWithoutExtension(runbookPath);
209207

210208
var runbookModel = this.TryGetRunbookModel(automationAccountName, runbookName);
@@ -233,18 +231,26 @@ public void DeleteRunbook(string automationAccountName, string runbookName)
233231
}
234232

235233
public Runbook UpdateRunbook(string automationAccountName, string runbookName, string description,
236-
IDictionary<string, string> tags, bool? logProgress, bool? logVerbose)
234+
IDictionary tags, bool? logProgress, bool? logVerbose)
237235
{
236+
var runbookModel = this.TryGetRunbookModel(automationAccountName, runbookName);
237+
if (runbookModel == null)
238+
{
239+
throw new ResourceCommonException(typeof(Runbook),
240+
string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, runbookName));
241+
}
242+
238243
var runbookUpdateParameters = new RunbookUpdateParameters();
239244
runbookUpdateParameters.Name = runbookName;
240-
if (tags != null) runbookUpdateParameters.Tags = tags;
245+
runbookUpdateParameters.Tags = (tags != null)
246+
? tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString())
247+
: runbookModel.Tags;
241248
runbookUpdateParameters.Properties = new RunbookUpdateProperties();
242-
if (description != null) runbookUpdateParameters.Properties.Description = description;
243-
if (logProgress.HasValue) runbookUpdateParameters.Properties.LogProgress = logProgress.Value;
244-
if (logVerbose.HasValue) runbookUpdateParameters.Properties.LogVerbose = logVerbose.Value;
249+
runbookUpdateParameters.Properties.Description = description ?? runbookModel.Properties.Description;
250+
runbookUpdateParameters.Properties.LogProgress = (logProgress.HasValue) ? logProgress.Value : runbookModel.Properties.LogProgress;
251+
runbookUpdateParameters.Properties.LogVerbose = (logProgress.HasValue) ? logProgress.Value : runbookModel.Properties.LogVerbose;
245252

246-
var runbook =
247-
this.automationManagementClient.Runbooks.Update(automationAccountName, runbookUpdateParameters).Runbook;
253+
var runbook = this.automationManagementClient.Runbooks.Update(automationAccountName, runbookUpdateParameters).Runbook;
248254

249255
return new Runbook(automationAccountName, runbook);
250256
}
@@ -333,8 +339,7 @@ public Job StartRunbook(string automationAccountName, string runbookName, IDicti
333339
Name = runbookName
334340
},
335341
Parameters = processedParameters ?? null
336-
},
337-
Location = ""
342+
}
338343
}).Job;
339344

340345
return new Job(automationAccountName, job);
@@ -1032,43 +1037,38 @@ public Certificate CreateCertificate(string automationAccountName, string name,
10321037
string.Format(CultureInfo.CurrentCulture, Resources.CertificateAlreadyExists, name));
10331038
}
10341039

1035-
var cert = (password == null)
1036-
? new X509Certificate2(path)
1037-
: new X509Certificate2(path, password);
1038-
1039-
var ccprop = new CertificateCreateProperties()
1040-
{
1041-
Description = description,
1042-
Base64Value = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12)),
1043-
Thumbprint = cert.Thumbprint,
1044-
IsExportable = exportable
1045-
};
1046-
1047-
var ccparam = new CertificateCreateParameters() { Name = name, Properties = ccprop };
1048-
1049-
var certificate = this.automationManagementClient.Certificates.Create(automationAccountName, ccparam).Certificate;
1050-
1051-
return new Certificate(automationAccountName, certificate);
1040+
return CreateCertificateInternal(automationAccountName, name, path, password, description, exportable);
10521041
}
10531042

1054-
1043+
10551044
public Certificate UpdateCertificate(string automationAccountName, string name, string path, SecureString password,
1056-
string description, bool exportable)
1045+
string description, bool? exportable)
10571046
{
1058-
var cuprop = new CertificateUpdateProperties();
1059-
1060-
if (description != null) cuprop.Description = description;
1047+
var certificateModel = this.TryGetCertificateModel(automationAccountName, name);
1048+
if (certificateModel == null)
1049+
{
1050+
throw new ResourceCommonException(typeof(Certificate),
1051+
string.Format(CultureInfo.CurrentCulture, Resources.CertificateNotFound, name));
1052+
}
10611053

1054+
var createOrUpdateDescription = description ?? certificateModel.Properties.Description;
1055+
var createOrUpdateIsExportable = (exportable.HasValue) ? exportable.Value : certificateModel.Properties.IsExportable;
1056+
10621057
if (path != null)
10631058
{
1064-
var cert = (password == null) ? new X509Certificate2(path) : new X509Certificate2(path, password);
1065-
cuprop.Base64Value = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12));
1066-
cuprop.Thumbprint = cert.Thumbprint;
1059+
return this.CreateCertificateInternal(automationAccountName, name, path, password, createOrUpdateDescription,
1060+
createOrUpdateIsExportable);
10671061
}
10681062

1069-
if (exportable) cuprop.IsExportable = true;
1070-
1071-
var cuparam = new CertificateUpdateParameters() { Name = name, Properties = cuprop };
1063+
var cuparam = new CertificateUpdateParameters()
1064+
{
1065+
Name = name,
1066+
Properties = new CertificateUpdateProperties()
1067+
{
1068+
Description = createOrUpdateDescription,
1069+
IsExportable = createOrUpdateIsExportable
1070+
}
1071+
};
10721072

10731073
this.automationManagementClient.Certificates.Update(automationAccountName, cuparam);
10741074

@@ -1455,6 +1455,28 @@ private Schedule UpdateScheduleHelper(string automationAccountName,
14551455
return this.GetSchedule(automationAccountName, schedule.Name);
14561456
}
14571457

1458+
private Certificate CreateCertificateInternal(string automationAccountName, string name, string path,
1459+
SecureString password, string description, bool exportable)
1460+
{
1461+
var cert = (password == null)
1462+
? new X509Certificate2(path)
1463+
: new X509Certificate2(path, password);
1464+
1465+
var ccprop = new CertificateCreateProperties()
1466+
{
1467+
Description = description,
1468+
Base64Value = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12)),
1469+
Thumbprint = cert.Thumbprint,
1470+
IsExportable = exportable
1471+
};
1472+
1473+
var ccparam = new CertificateCreateParameters() { Name = name, Properties = ccprop };
1474+
1475+
var certificate = this.automationManagementClient.Certificates.Create(automationAccountName, ccparam).Certificate;
1476+
1477+
return new Certificate(automationAccountName, certificate);
1478+
}
1479+
14581480
#endregion
14591481
}
14601482
}

src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public interface IAutomationClient
6565

6666
IEnumerable<Runbook> ListRunbooks(string automationAccountName);
6767

68-
Runbook CreateRunbookByName(string automationAccountName, string runbookName, string description, IDictionary<string, string> tags);
68+
Runbook CreateRunbookByName(string automationAccountName, string runbookName, string description, IDictionary tags);
6969

70-
Runbook CreateRunbookByPath(string automationAccountName, string runbookPath, string description, IDictionary<string, string> tags);
70+
Runbook CreateRunbookByPath(string automationAccountName, string runbookPath, string description, IDictionary tags);
7171

7272
void DeleteRunbook(string automationAccountName, string runbookName);
7373

7474
Runbook PublishRunbook(string automationAccountName, string runbookName);
7575

76-
Runbook UpdateRunbook(string automationAccountName, string runbookName, string description, IDictionary<string, string> tags, bool? logProgress, bool? logVerbose);
76+
Runbook UpdateRunbook(string automationAccountName, string runbookName, string description, IDictionary tags, bool? logProgress, bool? logVerbose);
7777

7878
RunbookDefinition UpdateRunbookDefinition(string automationAccountName, string runbookName, string runbookPath, bool overwrite);
7979

@@ -141,7 +141,7 @@ public interface IAutomationClient
141141

142142
Certificate CreateCertificate(string automationAccountName, string name, string path, SecureString password, string description, bool exportable);
143143

144-
Certificate UpdateCertificate(string automationAccountName, string name, string path, SecureString password, string description, bool exportable);
144+
Certificate UpdateCertificate(string automationAccountName, string name, string path, SecureString password, string description, bool? exportable);
145145

146146
Certificate GetCertificate(string automationAccountName, string name);
147147

src/ServiceManagement/Automation/Commands.Automation/DataContract/ErrorResponse.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ namespace Microsoft.Azure.Commands.Automation.DataContract
2323
public class ErrorResponse
2424
{
2525
/// <summary>
26-
/// Gets or sets the odata error.
26+
/// Gets or sets the code.
2727
/// </summary>
28-
[DataMember(Name = "odata.error")]
29-
public OdataError OdataError { get; set; }
28+
[DataMember(Name = "code")]
29+
public string Code { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets the message.
33+
/// </summary>
34+
[DataMember(Name = "message")]
35+
public string Message { get; set; }
3036
}
3137
}

0 commit comments

Comments
 (0)