Skip to content

Commit

Permalink
rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tulsishah committed Apr 26, 2024
1 parent 25b0ab7 commit f3ec08e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
51 changes: 29 additions & 22 deletions internal/storage/storageutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/googlecloudplatform/gcsfuse/v2/internal/auth"
"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
mountpkg "github.com/googlecloudplatform/gcsfuse/v2/internal/mount"
"golang.org/x/net/context"
"golang.org/x/oauth2"
Expand All @@ -48,12 +49,13 @@ type StorageClientConfig struct {
MaxIdleConnsPerHost int
HttpClientTimeout time.Duration
ExperimentalEnableJsonRead bool
SkipAuth bool

/** Grpc client parameters. */
GrpcConnPoolSize int

// Enabling new API flow for HNS bucket.
EnableHNS bool
EnableHNS config.EnableHNS
}

func CreateHttpClient(storageClientConfig *StorageClientConfig) (httpClient *http.Client, err error) {
Expand All @@ -79,21 +81,31 @@ func CreateHttpClient(storageClientConfig *StorageClientConfig) (httpClient *htt
}
}

tokenSrc, err := CreateTokenSource(storageClientConfig)
if err != nil {
err = fmt.Errorf("while fetching tokenSource: %w", err)
return
}
if storageClientConfig.SkipAuth {
httpClient = &http.Client{
Transport: &oauth2.Transport{
Source: oauth2.StaticTokenSource(&oauth2.Token{}),
Base: transport,
},
Timeout: storageClientConfig.HttpClientTimeout,
}
} else {
var tokenSrc oauth2.TokenSource
tokenSrc, err = CreateTokenSource(storageClientConfig)
if err != nil {
err = fmt.Errorf("while fetching tokenSource: %w", err)
return
}

// Custom http client for Go Client.
httpClient = &http.Client{
Transport: &oauth2.Transport{
Base: transport,
Source: tokenSrc,
},
Timeout: storageClientConfig.HttpClientTimeout,
// Custom http client for Go Client.
httpClient = &http.Client{
Transport: &oauth2.Transport{
Base: transport,
Source: tokenSrc,
},
Timeout: storageClientConfig.HttpClientTimeout,
}
}

// Setting UserAgent through RoundTripper middleware
httpClient.Transport = &userAgentRoundTripper{
wrapped: httpClient.Transport,
Expand All @@ -103,15 +115,10 @@ func CreateHttpClient(storageClientConfig *StorageClientConfig) (httpClient *htt
return httpClient, err
}

// It creates dummy token-source in case of non-nil custom url. If the custom-endpoint
// is nil, it creates the token-source from the provided key-file or using ADC search
// order (https://cloud.google.com/docs/authentication/application-default-credentials#order).
// It creates the token-source from the provided
// key-file or using ADC search order (https://cloud.google.com/docs/authentication/application-default-credentials#order).
func CreateTokenSource(storageClientConfig *StorageClientConfig) (tokenSrc oauth2.TokenSource, err error) {
if storageClientConfig.CustomEndpoint == nil {
return auth.GetTokenSource(context.Background(), storageClientConfig.KeyFile, storageClientConfig.TokenUrl, storageClientConfig.ReuseTokenFromUrl)
} else {
return oauth2.StaticTokenSource(&oauth2.Token{}), nil
}
return auth.GetTokenSource(context.Background(), storageClientConfig.KeyFile, storageClientConfig.TokenUrl, storageClientConfig.ReuseTokenFromUrl)
}

// StripScheme strips the scheme part of given url.
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func createStorageHandle(flags *flagStorage, mountConfig *config.MountConfig, us
ReuseTokenFromUrl: flags.ReuseTokenFromUrl,
ExperimentalEnableJsonRead: flags.ExperimentalEnableJsonRead,
GrpcConnPoolSize: mountConfig.GrpcClientConfig.ConnPoolSize,
EnableHNS: mountConfig.BucketFlow.EnableHNS,
EnableHNS: mountConfig.EnableHNS,
}
logger.Infof("UserAgent = %s\n", storageClientConfig.UserAgent)
storageHandle, err = storage.NewStorageHandle(context.Background(), storageClientConfig)
Expand Down
4 changes: 1 addition & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ func (t *MainTest) TestStringifyShouldReturnAllFlagsPassedInMountConfigAsMarshal
ListConfig: config.ListConfig{
EnableEmptyManagedFolders: false,
},
BucketFlow: config.BucketFlow{
EnableHNS: true,
},
EnableHNS: true,
}

actual, err := util.Stringify(mountConfig)
Expand Down

0 comments on commit f3ec08e

Please sign in to comment.