mirror of
https://github.com/rclone/rclone.git
synced 2025-01-05 05:49:33 +01:00
add env auth to drive provider
This change provides the ability to pass `env_auth` as a parameter to the drive provider. This enables the provider to pull IAM credentials from the environment or instance metadata. Previously if no auth method was given it would default to requesting oauth.
This commit is contained in:
parent
19e8c8d42a
commit
91dee03406
@ -202,7 +202,7 @@ func init() {
|
|||||||
m.Set("root_folder_id", "appDataFolder")
|
m.Set("root_folder_id", "appDataFolder")
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.ServiceAccountFile == "" && opt.ServiceAccountCredentials == "" {
|
if opt.ServiceAccountFile == "" && opt.ServiceAccountCredentials == "" && !opt.EnvAuth {
|
||||||
return oauthutil.ConfigOut("teamdrive", &oauthutil.Options{
|
return oauthutil.ConfigOut("teamdrive", &oauthutil.Options{
|
||||||
OAuth2Config: driveConfig,
|
OAuth2Config: driveConfig,
|
||||||
})
|
})
|
||||||
@ -598,6 +598,18 @@ resource key is no needed.
|
|||||||
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
// Don't encode / as it's a valid name character in drive.
|
// Don't encode / as it's a valid name character in drive.
|
||||||
Default: encoder.EncodeInvalidUtf8,
|
Default: encoder.EncodeInvalidUtf8,
|
||||||
|
}, {
|
||||||
|
Name: "env_auth",
|
||||||
|
Help: "Get IAM credentials from runtime (environment variables or instance meta data if no env vars).\n\nOnly applies if service_account_file and service_account_credentials is blank.",
|
||||||
|
Default: false,
|
||||||
|
Advanced: true,
|
||||||
|
Examples: []fs.OptionExample{{
|
||||||
|
Value: "false",
|
||||||
|
Help: "Enter AWS credentials in the next step.",
|
||||||
|
}, {
|
||||||
|
Value: "true",
|
||||||
|
Help: "Get GCP IAM credentials from the environment (env vars or IAM).",
|
||||||
|
}},
|
||||||
}}...),
|
}}...),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -654,6 +666,7 @@ type Options struct {
|
|||||||
SkipDanglingShortcuts bool `config:"skip_dangling_shortcuts"`
|
SkipDanglingShortcuts bool `config:"skip_dangling_shortcuts"`
|
||||||
ResourceKey string `config:"resource_key"`
|
ResourceKey string `config:"resource_key"`
|
||||||
Enc encoder.MultiEncoder `config:"encoding"`
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
|
EnvAuth bool `config:"env_auth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote drive server
|
// Fs represents a remote drive server
|
||||||
@ -1122,6 +1135,12 @@ func createOAuthClient(ctx context.Context, opt *Options, name string, m configm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create oauth client from service account: %w", err)
|
return nil, fmt.Errorf("failed to create oauth client from service account: %w", err)
|
||||||
}
|
}
|
||||||
|
} else if opt.EnvAuth {
|
||||||
|
scopes := driveScopes(opt.Scope)
|
||||||
|
oAuthClient, err = google.DefaultClient(ctx, scopes...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create client from environment: %w", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
oAuthClient, _, err = oauthutil.NewClientWithBaseClient(ctx, name, m, driveConfig, getClient(ctx, opt))
|
oAuthClient, _, err = oauthutil.NewClientWithBaseClient(ctx, name, m, driveConfig, getClient(ctx, opt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user