|
|
@ -18,12 +18,13 @@ |
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"context" |
|
|
|
"flag" |
|
|
|
"flag" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
|
|
|
|
|
|
|
|
miniogo "github.com/minio/minio-go/v7" |
|
|
|
"github.com/minio/minio-go/v7" |
|
|
|
cr "github.com/minio/minio-go/v7/pkg/credentials" |
|
|
|
cr "github.com/minio/minio-go/v7/pkg/credentials" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -53,39 +54,34 @@ func main() { |
|
|
|
// LDAP STS API.
|
|
|
|
// LDAP STS API.
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize LDAP credentials
|
|
|
|
// Initialize LDAP credentials
|
|
|
|
li, err := cr.NewLDAPIdentity(stsEndpoint, ldapUsername, ldapPassword) |
|
|
|
li, _ := cr.NewLDAPIdentity(stsEndpoint, ldapUsername, ldapPassword) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatalf("INIT Err: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate temporary STS credentials
|
|
|
|
stsEndpointURL, err := url.Parse(stsEndpoint) |
|
|
|
v, err := li.Get() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatalf("GET Err: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fmt.Printf("%#v\n", v) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stsEndpointUrl, err := url.Parse(stsEndpoint) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("Err: %v", err) |
|
|
|
log.Fatalf("Err: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
secure := false |
|
|
|
opts := &minio.Options{ |
|
|
|
if stsEndpointUrl.Scheme == "https" { |
|
|
|
Creds: li, |
|
|
|
secure = true |
|
|
|
Secure: stsEndpointURL.Scheme == "https", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println(li.Get()) |
|
|
|
// Use generated credentials to authenticate with MinIO server
|
|
|
|
// Use generated credentials to authenticate with MinIO server
|
|
|
|
minioClient, err := miniogo.NewWithCredentials(stsEndpointUrl.Host, li, secure, "") |
|
|
|
minioClient, err := minio.New(stsEndpointURL.Host, opts) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalln(err) |
|
|
|
log.Fatalln(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Use minIO Client object normally like the regular client.
|
|
|
|
// Use minIO Client object normally like the regular client.
|
|
|
|
fmt.Println("Calling list buckets with temp creds:") |
|
|
|
fmt.Println("Calling list objects with temp creds: ") |
|
|
|
b, err := minioClient.ListBuckets() |
|
|
|
objCh := minioClient.ListObjects(context.Background(), ldapUsername, minio.ListObjectsOptions{}) |
|
|
|
|
|
|
|
for obj := range objCh { |
|
|
|
|
|
|
|
if obj.Err != nil { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalln(err) |
|
|
|
log.Fatalln(err) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println(b) |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Println(obj) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|