25
25
using Microsoft . Azure . Commands . Automation . Properties ;
26
26
using Microsoft . Azure . Management . Automation ;
27
27
using Microsoft . Azure . Management . Automation . Models ;
28
- using Microsoft . WindowsAzure ;
29
- using Microsoft . WindowsAzure . Commands . Common ;
30
- using Microsoft . Azure . Common . Extensions . Models ;
31
28
using Newtonsoft . Json ;
32
29
33
30
using Runbook = Microsoft . Azure . Commands . Automation . Model . Runbook ;
@@ -179,7 +176,7 @@ public IEnumerable<Runbook> ListRunbooks(string automationAccountName)
179
176
}
180
177
181
178
public Runbook CreateRunbookByName ( string automationAccountName , string runbookName , string description ,
182
- IDictionary < string , string > tags )
179
+ IDictionary tags )
183
180
{
184
181
var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
185
182
if ( runbookModel != null )
@@ -195,16 +192,17 @@ public Runbook CreateRunbookByName(string automationAccountName, string runbookN
195
192
Draft = new RunbookDraft ( )
196
193
} ;
197
194
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 } ;
199
196
200
197
this . automationManagementClient . Runbooks . CreateWithDraft ( automationAccountName , rdcparam ) ;
201
198
202
199
return this . GetRunbook ( automationAccountName , runbookName ) ;
203
200
}
204
201
205
202
public Runbook CreateRunbookByPath ( string automationAccountName , string runbookPath , string description ,
206
- IDictionary < string , string > tags )
203
+ IDictionary tags )
207
204
{
205
+
208
206
var runbookName = Path . GetFileNameWithoutExtension ( runbookPath ) ;
209
207
210
208
var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
@@ -233,18 +231,26 @@ public void DeleteRunbook(string automationAccountName, string runbookName)
233
231
}
234
232
235
233
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 )
237
235
{
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
+
238
243
var runbookUpdateParameters = new RunbookUpdateParameters ( ) ;
239
244
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 ;
241
248
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 ;
245
252
246
- var runbook =
247
- this . automationManagementClient . Runbooks . Update ( automationAccountName , runbookUpdateParameters ) . Runbook ;
253
+ var runbook = this . automationManagementClient . Runbooks . Update ( automationAccountName , runbookUpdateParameters ) . Runbook ;
248
254
249
255
return new Runbook ( automationAccountName , runbook ) ;
250
256
}
@@ -333,8 +339,7 @@ public Job StartRunbook(string automationAccountName, string runbookName, IDicti
333
339
Name = runbookName
334
340
} ,
335
341
Parameters = processedParameters ?? null
336
- } ,
337
- Location = ""
342
+ }
338
343
} ) . Job ;
339
344
340
345
return new Job ( automationAccountName , job ) ;
@@ -1032,43 +1037,38 @@ public Certificate CreateCertificate(string automationAccountName, string name,
1032
1037
string . Format ( CultureInfo . CurrentCulture , Resources . CertificateAlreadyExists , name ) ) ;
1033
1038
}
1034
1039
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 ) ;
1052
1041
}
1053
1042
1054
-
1043
+
1055
1044
public Certificate UpdateCertificate ( string automationAccountName , string name , string path , SecureString password ,
1056
- string description , bool exportable )
1045
+ string description , bool ? exportable )
1057
1046
{
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
+ }
1061
1053
1054
+ var createOrUpdateDescription = description ?? certificateModel . Properties . Description ;
1055
+ var createOrUpdateIsExportable = ( exportable . HasValue ) ? exportable . Value : certificateModel . Properties . IsExportable ;
1056
+
1062
1057
if ( path != null )
1063
1058
{
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 ) ;
1067
1061
}
1068
1062
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
+ } ;
1072
1072
1073
1073
this . automationManagementClient . Certificates . Update ( automationAccountName , cuparam ) ;
1074
1074
@@ -1455,6 +1455,28 @@ private Schedule UpdateScheduleHelper(string automationAccountName,
1455
1455
return this . GetSchedule ( automationAccountName , schedule . Name ) ;
1456
1456
}
1457
1457
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
+
1458
1480
#endregion
1459
1481
}
1460
1482
}
0 commit comments