@@ -30,36 +30,45 @@ public class NewAzureProfileCommand : AzurePSCmdlet
30
30
{
31
31
private const string CertificateParameterSet = "Certificate" ;
32
32
private const string CredentialsParameterSet = "Credentials" ;
33
+ private const string ServicePrincipalParameterSet = "ServicePrincipal" ;
33
34
private const string AccessTokenParameterSet = "Token" ;
34
35
private const string FileParameterSet = "File" ;
35
36
36
37
[ Parameter ( Mandatory = false , Position = 0 , ValueFromPipelineByPropertyName = true , ParameterSetName = CertificateParameterSet ) ]
38
+ [ Parameter ( Mandatory = false , Position = 0 , ValueFromPipelineByPropertyName = true , ParameterSetName = ServicePrincipalParameterSet ) ]
39
+ [ Parameter ( Mandatory = false , Position = 0 , ValueFromPipelineByPropertyName = true , ParameterSetName = AccessTokenParameterSet ) ]
37
40
[ Parameter ( Mandatory = false , Position = 0 , ValueFromPipelineByPropertyName = true , ParameterSetName = CredentialsParameterSet ) ]
38
41
public AzureEnvironment Environment { get ; set ; }
39
42
40
43
[ Parameter ( Mandatory = true , Position = 1 , ValueFromPipelineByPropertyName = true , ParameterSetName = CertificateParameterSet ) ]
44
+ [ Parameter ( Mandatory = true , Position = 1 , ValueFromPipelineByPropertyName = true , ParameterSetName = ServicePrincipalParameterSet ) ]
45
+ [ Parameter ( Mandatory = true , Position = 1 , ValueFromPipelineByPropertyName = true , ParameterSetName = AccessTokenParameterSet ) ]
41
46
[ Parameter ( Mandatory = true , Position = 1 , ValueFromPipelineByPropertyName = true , ParameterSetName = CredentialsParameterSet ) ]
42
47
public string SubscriptionId { get ; set ; }
43
48
44
49
[ Parameter ( Mandatory = false , Position = 2 , ValueFromPipelineByPropertyName = true , ParameterSetName = CertificateParameterSet ) ]
50
+ [ Parameter ( Mandatory = false , Position = 2 , ValueFromPipelineByPropertyName = true , ParameterSetName = ServicePrincipalParameterSet ) ]
51
+ [ Parameter ( Mandatory = false , Position = 2 , ValueFromPipelineByPropertyName = true , ParameterSetName = AccessTokenParameterSet ) ]
45
52
[ Parameter ( Mandatory = false , Position = 2 , ValueFromPipelineByPropertyName = true , ParameterSetName = CredentialsParameterSet ) ]
46
53
public string StorageAccount { get ; set ; }
47
54
48
55
[ Parameter ( Mandatory = true , Position = 3 , ValueFromPipelineByPropertyName = true , ParameterSetName = CertificateParameterSet ) ]
49
56
public X509Certificate2 Certificate { get ; set ; }
50
57
51
58
[ Parameter ( Mandatory = true , Position = 3 , ValueFromPipelineByPropertyName = true , ParameterSetName = CredentialsParameterSet ) ]
59
+ [ Parameter ( Mandatory = true , Position = 3 , ValueFromPipelineByPropertyName = true , ParameterSetName = ServicePrincipalParameterSet ) ]
52
60
public PSCredential Credential { get ; set ; }
53
61
54
62
[ Parameter ( Mandatory = true , Position = 4 , ValueFromPipelineByPropertyName = true , ParameterSetName = CredentialsParameterSet ) ]
63
+ [ Parameter ( Mandatory = true , Position = 4 , ValueFromPipelineByPropertyName = true , ParameterSetName = ServicePrincipalParameterSet ) ]
55
64
public string Tenant { get ; set ; }
56
65
66
+ [ Parameter ( Mandatory = true , Position = 5 , ValueFromPipelineByPropertyName = true , ParameterSetName = ServicePrincipalParameterSet ) ]
67
+ public SwitchParameter ServicePrincipal { get ; set ; }
68
+
57
69
[ Parameter ( Mandatory = true , Position = 3 , ValueFromPipelineByPropertyName = true , ParameterSetName = AccessTokenParameterSet ) ]
58
70
public string AccessToken { get ; set ; }
59
71
60
- [ Parameter ( Mandatory = true , Position = 4 , ValueFromPipelineByPropertyName = true , ParameterSetName = AccessTokenParameterSet ) ]
61
- public string AccountId { get ; set ; }
62
-
63
72
[ Parameter ( Mandatory = true , Position = 0 , ValueFromPipelineByPropertyName = true , ParameterSetName = FileParameterSet ) ]
64
73
public string Path { get ; set ; }
65
74
@@ -82,11 +91,30 @@ public override void ExecuteCmdlet()
82
91
case CredentialsParameterSet :
83
92
AzureAccount userAccount = new AzureAccount
84
93
{
85
- Id = Credential . UserName
94
+ Id = Credential . UserName ,
95
+ Type = AzureAccount . AccountType . User
86
96
} ;
87
97
profileClient . InitializeProfile ( Environment , new Guid ( SubscriptionId ) , userAccount ,
88
98
Credential . Password , StorageAccount ) ;
89
99
break ;
100
+ case AccessTokenParameterSet :
101
+ AzureAccount tokenAccount = new AzureAccount
102
+ {
103
+ Id = AccessToken ,
104
+ Type = AzureAccount . AccountType . AccessToken
105
+ } ;
106
+ profileClient . InitializeProfile ( Environment , new Guid ( SubscriptionId ) , tokenAccount ,
107
+ null , StorageAccount ) ;
108
+ break ;
109
+ case ServicePrincipalParameterSet :
110
+ AzureAccount servicePrincipalAccount = new AzureAccount
111
+ {
112
+ Id = Credential . UserName ,
113
+ Type = AzureAccount . AccountType . ServicePrincipal
114
+ } ;
115
+ profileClient . InitializeProfile ( Environment , new Guid ( SubscriptionId ) , servicePrincipalAccount ,
116
+ Credential . Password , StorageAccount ) ;
117
+ break ;
90
118
}
91
119
92
120
WriteObject ( azureProfile ) ;
0 commit comments