20
20
using System . IO ;
21
21
using System . Net ;
22
22
using System . Security ;
23
- using System . Security . Cryptography ;
24
23
using System . Security . Cryptography . X509Certificates ;
25
- using System . Text ;
26
24
using Microsoft . Azure . Commands . Automation . Model ;
27
25
using Microsoft . Azure . Commands . Automation . Properties ;
28
26
using Microsoft . Azure . Management . Automation ;
@@ -131,7 +129,7 @@ public IEnumerable<Schedule> ListSchedules(string automationAccountName)
131
129
skipToken =>
132
130
{
133
131
var response = this . automationManagementClient . Schedules . List (
134
- automationAccountName , skipToken ) ;
132
+ automationAccountName ) ;
135
133
136
134
return new ResponseWithSkipToken < AutomationManagement . Models . Schedule > (
137
135
response , response . Schedules ) ;
@@ -170,7 +168,7 @@ public IEnumerable<Runbook> ListRunbooks(string automationAccountName)
170
168
skipToken =>
171
169
{
172
170
var response = this . automationManagementClient . Runbooks . List (
173
- automationAccountName , skipToken ) ;
171
+ automationAccountName ) ;
174
172
return new ResponseWithSkipToken < AutomationManagement . Models . Runbook > (
175
173
response , response . Runbooks ) ;
176
174
} ) . Select ( c => new Runbook ( automationAccountName , c ) ) ;
@@ -195,7 +193,7 @@ public Runbook CreateRunbookByName(string automationAccountName, string runbookN
195
193
196
194
var rdcparam = new RunbookCreateDraftParameters ( ) { Name = runbookName , Properties = rdcprop , Tags = tags } ;
197
195
198
- this . automationManagementClient . Runbooks . CreateWithDraftParameters ( automationAccountName , rdcparam ) ;
196
+ this . automationManagementClient . Runbooks . CreateWithDraft ( automationAccountName , rdcparam ) ;
199
197
200
198
return this . GetRunbook ( automationAccountName , runbookName ) ;
201
199
}
@@ -1007,37 +1005,21 @@ public void DeleteAutomationAccount(string automationAccountName)
1007
1005
{
1008
1006
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNull ( ) ;
1009
1007
1010
- string location = string . Empty ;
1008
+ var csName = string . Empty ;
1011
1009
1012
- var cloudServices = new List < CloudService > ( this . automationManagementClient . CloudServices . List ( ) . CloudServices ) ;
1010
+ var cloudServices = this . automationManagementClient . CloudServices . List ( ) . CloudServices ;
1013
1011
1014
1012
foreach ( var cloudService in cloudServices )
1015
1013
{
1016
1014
if ( cloudService . Resources . Any ( resource => 0 == String . Compare ( resource . Name , automationAccountName , CultureInfo . InvariantCulture ,
1017
1015
CompareOptions . IgnoreCase ) ) )
1018
1016
{
1019
- location = cloudService . GeoRegion ;
1017
+ csName = cloudService . Name ;
1020
1018
break ;
1021
1019
}
1022
1020
}
1023
1021
1024
- try
1025
- {
1026
- this . automationManagementClient . DeleteAutomationAccount ( automationAccountName , location ) ;
1027
- }
1028
- catch ( CloudException e )
1029
- {
1030
- if ( e . Response . StatusCode == HttpStatusCode . NotFound )
1031
- {
1032
- // Try with SHA encoded cloud Service name
1033
- var generatedCsName = GetCloudServiceName ( automationAccountName , location ) ;
1034
- this . automationManagementClient . AutomationAccounts . Delete ( generatedCsName , automationAccountName ) ;
1035
- }
1036
- else
1037
- {
1038
- throw ;
1039
- }
1040
- }
1022
+ this . automationManagementClient . AutomationAccounts . Delete ( csName , automationAccountName ) ;
1041
1023
}
1042
1024
1043
1025
#endregion
@@ -1077,17 +1059,18 @@ public Certificate CreateCertificate(string automationAccountName, string name,
1077
1059
public Certificate UpdateCertificate ( string automationAccountName , string name , string path , SecureString password ,
1078
1060
string description , bool exportable )
1079
1061
{
1080
- var cert = ( password == null )
1081
- ? new X509Certificate2 ( path )
1082
- : new X509Certificate2 ( path , password ) ;
1083
-
1084
- var cuprop = new CertificateUpdateProperties ( )
1062
+ var cuprop = new CertificateUpdateProperties ( ) ;
1063
+
1064
+ if ( description != null ) cuprop . Description = description ;
1065
+
1066
+ if ( path != null )
1085
1067
{
1086
- Description = description ,
1087
- Base64Value = Convert . ToBase64String ( cert . Export ( X509ContentType . Pkcs12 ) ) ,
1088
- Thumbprint = cert . Thumbprint ,
1089
- IsExportable = exportable
1090
- } ;
1068
+ var cert = ( password == null ) ? new X509Certificate2 ( path ) : new X509Certificate2 ( path , password ) ;
1069
+ cuprop . Base64Value = Convert . ToBase64String ( cert . Export ( X509ContentType . Pkcs12 ) ) ;
1070
+ cuprop . Thumbprint = cert . Thumbprint ;
1071
+ }
1072
+
1073
+ if ( exportable ) cuprop . IsExportable = true ;
1091
1074
1092
1075
var cuparam = new CertificateUpdateParameters ( ) { Name = name , Properties = cuprop } ;
1093
1076
@@ -1187,7 +1170,7 @@ public IEnumerable<JobSchedule> ListJobSchedules(string automationAccountName)
1187
1170
skipToken =>
1188
1171
{
1189
1172
var response = this . automationManagementClient . JobSchedules . List (
1190
- automationAccountName , skipToken ) ;
1173
+ automationAccountName ) ;
1191
1174
1192
1175
return new ResponseWithSkipToken < AutomationManagement . Models . JobSchedule > (
1193
1176
response , response . JobSchedules ) ;
@@ -1394,46 +1377,6 @@ private IDictionary<string, string> ProcessRunbookParameters(string automationAc
1394
1377
return filteredParameters ;
1395
1378
}
1396
1379
1397
- private string GetCloudServiceName ( string subscriptionId , string region )
1398
- {
1399
- string hashedSubId = string . Empty ;
1400
- using ( SHA256 sha256 = SHA256Managed . Create ( ) )
1401
- {
1402
- hashedSubId = Base32NoPaddingEncode ( sha256 . ComputeHash ( UTF8Encoding . UTF8 . GetBytes ( subscriptionId ) ) ) ;
1403
- }
1404
-
1405
- return string . Format ( CultureInfo . InvariantCulture , "{0}{1}-{2}" , Constants . AutomationServicePrefix , hashedSubId , region . Replace ( ' ' , '-' ) ) ;
1406
- }
1407
-
1408
- private string Base32NoPaddingEncode ( byte [ ] data )
1409
- {
1410
- const string base32StandardAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" ;
1411
-
1412
- StringBuilder result = new StringBuilder ( Math . Max ( ( int ) Math . Ceiling ( data . Length * 8 / 5.0 ) , 1 ) ) ;
1413
-
1414
- byte [ ] emptyBuffer = new byte [ ] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
1415
- byte [ ] workingBuffer = new byte [ 8 ] ;
1416
-
1417
- // Process input 5 bytes at a time
1418
- for ( int i = 0 ; i < data . Length ; i += 5 )
1419
- {
1420
- int bytes = Math . Min ( data . Length - i , 5 ) ;
1421
- Array . Copy ( emptyBuffer , workingBuffer , emptyBuffer . Length ) ;
1422
- Array . Copy ( data , i , workingBuffer , workingBuffer . Length - ( bytes + 1 ) , bytes ) ;
1423
- Array . Reverse ( workingBuffer ) ;
1424
- ulong val = BitConverter . ToUInt64 ( workingBuffer , 0 ) ;
1425
-
1426
- for ( int bitOffset = ( ( bytes + 1 ) * 8 ) - 5 ; bitOffset > 3 ; bitOffset -= 5 )
1427
- {
1428
- result . Append ( base32StandardAlphabet [ ( int ) ( ( val >> bitOffset ) & 0x1f ) ] ) ;
1429
- }
1430
- }
1431
-
1432
- return result . ToString ( ) ;
1433
- }
1434
-
1435
-
1436
-
1437
1380
private JobStream CreateJobStreamFromJobStreamModel ( AutomationManagement . Models . JobStream jobStream , string automationAccountName , Guid jobId )
1438
1381
{
1439
1382
Requires . Argument ( "jobStream" , jobStream ) . NotNull ( ) ;
0 commit comments