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

feat: support Application Default Credentials in googlecloud #18

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
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
18 changes: 15 additions & 3 deletions googlecloud/googlecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"strings"

"cloud.google.com/go/storage"
"github.com/casdoor/oss"
"golang.org/x/oauth2/google"
"google.golang.org/api/iterator"
"google.golang.org/api/option"

"github.com/casdoor/oss"
hsluoyz marked this conversation as resolved.
Show resolved Hide resolved
)

// Client Google Cloud Storage
Expand All @@ -44,8 +45,19 @@ type Config struct {

// New initializes Google Cloud Storage
func New(config *Config) (*Client, error) {
ctx := context.Background()
credentials, err := google.CredentialsFromJSON(ctx, []byte(config.ServiceAccountJson), "https://www.googleapis.com/auth/cloud-platform")
var (
ctx = context.Background()
scope = "https://www.googleapis.com/auth/cloud-platform"

credentials *google.Credentials
err error
)

if config.ServiceAccountJson != "" {
credentials, err = google.CredentialsFromJSON(ctx, []byte(config.ServiceAccountJson), scope)
} else {
credentials, err = google.FindDefaultCredentials(ctx, scope)
}
if err != nil {
return nil, err
}
Expand Down
Loading