@@ -24,28 +24,11 @@ import (
2424 "errors"
2525 "strings"
2626
27+ "github.com/Azure/azure-storage-azcopy/v10/azcopy"
2728 "github.com/Azure/azure-storage-azcopy/v10/common"
2829 "github.com/spf13/cobra"
2930)
3031
31- type LoginOptions struct {
32- TenantID string
33- AADEndpoint string
34- LoginType common.AutoLoginType
35-
36- IdentityClientID string
37- IdentityResourceID string
38-
39- ApplicationID string
40- CertificatePath string
41-
42- certificatePassword string
43- clientSecret string
44- persistToken bool
45-
46- identityObjectID string
47- }
48-
4932var loginCmdArg = rawLoginArgs {tenantID : common .DefaultTenantID }
5033
5134var lgCmd = & cobra.Command {
@@ -91,19 +74,6 @@ var lgCmd = &cobra.Command{
9174 },
9275}
9376
94- func RunLogin (args LoginOptions ) error {
95- args .certificatePassword = common .GetEnvironmentVariable (common .EEnvironmentVariable .CertificatePassword ())
96- args .clientSecret = common .GetEnvironmentVariable (common .EEnvironmentVariable .ClientSecret ())
97- args .persistToken = true
98-
99- if args .certificatePassword != "" || args .clientSecret != "" {
100- glcm .Info (environmentVariableNotice )
101- }
102-
103- return args .process ()
104-
105- }
106-
10777func init () {
10878
10979 rootCmd .AddCommand (lgCmd )
@@ -161,70 +131,55 @@ type rawLoginArgs struct {
161131 certPath string
162132}
163133
164- func (args rawLoginArgs ) toOptions () (LoginOptions , error ) {
134+ func (args rawLoginArgs ) toOptions () (azcopy. LoginOptions , error ) {
165135 var loginType common.AutoLoginType
166136 err := loginType .Parse (loginCmdArg .loginType )
167137 if err != nil {
168- return LoginOptions {}, err
138+ return azcopy. LoginOptions {}, err
169139 }
170- return LoginOptions {
171- TenantID : args .tenantID ,
172- AADEndpoint : args .aadEndpoint ,
173- LoginType : loginType ,
174- IdentityClientID : args .identityClientID ,
175- identityObjectID : args .identityObjectID ,
176- IdentityResourceID : args .identityResourceID ,
177- ApplicationID : args .applicationID ,
178- CertificatePath : args .certPath ,
140+ certificatePassword := common .GetEnvironmentVariable (common .EEnvironmentVariable .CertificatePassword ())
141+ clientSecret := common .GetEnvironmentVariable (common .EEnvironmentVariable .ClientSecret ())
142+
143+ if certificatePassword != "" || clientSecret != "" {
144+ glcm .Info (environmentVariableNotice )
145+ }
146+ return azcopy.LoginOptions {
147+ TenantID : args .tenantID ,
148+ AADEndpoint : args .aadEndpoint ,
149+ LoginType : loginType ,
150+ IdentityClientID : args .identityClientID ,
151+ IdentityObjectID : args .identityObjectID ,
152+ IdentityResourceID : args .identityResourceID ,
153+ ApplicationID : args .applicationID ,
154+ CertificatePath : args .certPath ,
155+ PersistToken : true ,
156+ CertificatePassword : certificatePassword ,
157+ ClientSecret : clientSecret ,
179158 }, nil
180159}
181160
182- func (options LoginOptions ) process () error {
183- uotm := Client .GetUserOAuthTokenManagerInstance ()
184- // Persist the token to cache, if login fulfilled successfully.
185-
161+ func RunLogin (options azcopy.LoginOptions ) error {
162+ _ , err := Client .Login (options )
163+ if err != nil {
164+ return err
165+ }
186166 switch options .LoginType {
187167 case common .EAutoLoginType .SPN ():
188168 if options .CertificatePath != "" {
189- if err := uotm .CertLogin (options .TenantID , options .AADEndpoint , options .CertificatePath , options .certificatePassword , options .ApplicationID , options .persistToken ); err != nil {
190- return err
191- }
192169 glcm .Info ("SPN Auth via cert succeeded." )
193170 } else {
194- if err := uotm .SecretLogin (options .TenantID , options .AADEndpoint , options .clientSecret , options .ApplicationID , options .persistToken ); err != nil {
195- return err
196- }
197171 glcm .Info ("SPN Auth via secret succeeded." )
198172 }
199173 case common .EAutoLoginType .MSI ():
200- if err := uotm .MSILogin (common.IdentityInfo {
201- ClientID : options .IdentityClientID ,
202- ObjectID : options .identityObjectID ,
203- MSIResID : options .IdentityResourceID ,
204- }, options .persistToken ); err != nil {
205- return err
206- }
207174 // For MSI login, info success message to user.
208175 glcm .Info ("Login with identity succeeded." )
209176 case common .EAutoLoginType .AzCLI ():
210- if err := uotm .AzCliLogin (options .TenantID , options .persistToken ); err != nil {
211- return err
212- }
213177 glcm .Info ("Login with AzCliCreds succeeded" )
214178 case common .EAutoLoginType .PsCred ():
215- if err := uotm .PSContextToken (options .TenantID , options .persistToken ); err != nil {
216- return err
217- }
218179 glcm .Info ("Login with Powershell context succeeded" )
219180 case common .EAutoLoginType .Workload ():
220- if err := uotm .WorkloadIdentityLogin (options .persistToken ); err != nil {
221- return err
222- }
223181 glcm .Info ("Login with Workload Identity succeeded" )
224182 default :
225- if err := uotm .UserLogin (options .TenantID , options .AADEndpoint , options .persistToken ); err != nil {
226- return err
227- }
228183 // User fulfills login in browser, and there would be message in browser indicating whether login fulfilled successfully.
229184 glcm .Info ("Login succeeded." )
230185 }
0 commit comments