Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minio_session_token configuration #362

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ provider minio {
minio_secret_key = "..."

// optional
minio_region = "..."
minio_api_version = "..."
minio_ssl = "..."
minio_insecure = "..."
minio_session_token = "..."
minio_region = "..."
minio_api_version = "..."
minio_ssl = "..."
minio_insecure = "..."
}
```

Expand Down Expand Up @@ -79,6 +80,9 @@ The following arguments are supported in the `provider` block:
- `minio_secret_key` - (Required) Minio Secret Key. It must be provided, but
it can also be sourced from the `MINIO_SECRET_KEY` environment variable

- `minio_session_token` - (Optional) Minio Session Token. It can also be sourced from
the `MINIO_SESSION_TOKEN` environment variable

- `minio_region` - (Optional) Minio Region (`default: us-east-1`).

- `minio_api_version` - (Optional) Minio API Version (type: string, options: `v2` or `v4`, default: `v4`).
Expand Down
1 change: 1 addition & 0 deletions minio/check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewConfig(d *schema.ResourceData) *S3MinioConfig {
S3Region: d.Get("minio_region").(string),
S3UserAccess: d.Get("minio_access_key").(string),
S3UserSecret: d.Get("minio_secret_key").(string),
S3SessionToken: d.Get("minio_session_token").(string),
S3APISignature: d.Get("minio_api_version").(string),
S3SSL: d.Get("minio_ssl").(bool),
S3SSLCACertFile: d.Get("minio_cert_file").(string),
Expand Down
12 changes: 9 additions & 3 deletions minio/new_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func (config *S3MinioConfig) NewClient() (client interface{}, err error) {

var minioClient *minio.Client
var minioCredentials *credentials.Credentials

tr, err := config.customTransport()
if err != nil {
Expand All @@ -26,14 +27,16 @@ func (config *S3MinioConfig) NewClient() (client interface{}, err error) {
}

if config.S3APISignature == "v2" {
minioCredentials = credentials.NewStaticV2(config.S3UserAccess, config.S3UserSecret, config.S3SessionToken)
minioClient, err = minio.New(config.S3HostPort, &minio.Options{
Creds: credentials.NewStaticV2(config.S3UserAccess, config.S3UserSecret, ""),
Creds: minioCredentials,
Secure: config.S3SSL,
Transport: tr,
})
} else if config.S3APISignature == "v4" {
minioCredentials = credentials.NewStaticV4(config.S3UserAccess, config.S3UserSecret, config.S3SessionToken)
minioClient, err = minio.New(config.S3HostPort, &minio.Options{
Creds: credentials.NewStaticV4(config.S3UserAccess, config.S3UserSecret, ""),
Creds: minioCredentials,
Secure: config.S3SSL,
Transport: tr,
})
Expand All @@ -45,7 +48,10 @@ func (config *S3MinioConfig) NewClient() (client interface{}, err error) {
return nil, err
}

minioAdmin, err := madmin.New(config.S3HostPort, config.S3UserAccess, config.S3UserSecret, config.S3SSL)
minioAdmin, err := madmin.NewWithOptions(config.S3HostPort, &madmin.Options{
Creds: minioCredentials,
Secure: config.S3SSL,
})
//minioAdmin.TraceOn(nil)
if err != nil {
log.Println("[FATAL] Error building admin client for S3 server.")
Expand Down
1 change: 1 addition & 0 deletions minio/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type S3MinioConfig struct {
S3UserAccess string
S3UserSecret string
S3Region string
S3SessionToken string
S3APISignature string
S3SSL bool
S3SSLCACertFile string
Expand Down
8 changes: 8 additions & 0 deletions minio/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func Provider() *schema.Provider {
"MINIO_SECRET_KEY",
}, nil),
},
"minio_session_token": {
Type: schema.TypeString,
Optional: true,
Description: "Minio Session Token",
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"MINIO_SESSION_TOKEN",
}, ""),
},
"minio_api_version": {
Type: schema.TypeString,
Optional: true,
Expand Down