Skip to content

Commit

Permalink
refactor: remove dumplicate config, fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
renlulu committed Oct 2, 2024
1 parent 2644a8e commit e63345b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
21 changes: 0 additions & 21 deletions cmd/genericconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,6 @@ var DefaultS3Config = S3Config{
SecretKey: "",
}

type GoogleCloudStorageConfig struct {
AccessToken string `koanf:"access-token"`
Bucket string `koanf:"bucket"`
ObjectPrefix string `koanf:"object-prefix"`
MaxRetention time.Duration `koanf:"max-retention"`
}

var DefaultGoogleCloudStorageConfig = GoogleCloudStorageConfig{
AccessToken: "",
Bucket: "",
ObjectPrefix: "",
MaxRetention: time.Hour * 24,
}

func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) {
f.String(prefix+".access-token", DefaultGoogleCloudStorageConfig.AccessToken, "Google Cloud Storage access token")
f.String(prefix+".bucket", DefaultGoogleCloudStorageConfig.Bucket, "Google Cloud Storage bucket")
f.String(prefix+".object-prefix", DefaultGoogleCloudStorageConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects")
f.Duration(prefix+".max-retention", DefaultGoogleCloudStorageConfig.MaxRetention, "store requests with expiry times farther in the future than max-retention will be rejected")
}

func HandlerFromLogType(logType string, output io.Writer) (slog.Handler, error) {
if logType == "plaintext" {
return log.NewTerminalHandler(output, false), nil
Expand Down
8 changes: 5 additions & 3 deletions das/google_cloud_storage_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/das/dastree"
"testing"
"time"
Expand Down Expand Up @@ -38,7 +37,7 @@ func (c *mockGCSClient) Upload(ctx context.Context, bucket, objectPrefix string,
return nil
}

func NewTestGoogleCloudStorageService(ctx context.Context, googleCloudStorageConfig genericconf.GoogleCloudStorageConfig) (StorageService, error) {
func NewTestGoogleCloudStorageService(ctx context.Context, googleCloudStorageConfig GoogleCloudStorageServiceConfig) (StorageService, error) {
return &GoogleCloudStorageService{
bucket: googleCloudStorageConfig.Bucket,
objectPrefix: googleCloudStorageConfig.ObjectPrefix,
Expand All @@ -52,7 +51,10 @@ func NewTestGoogleCloudStorageService(ctx context.Context, googleCloudStorageCon
func TestNewGoogleCloudStorageService(t *testing.T) {
ctx := context.Background()
expiry := uint64(time.Now().Add(time.Hour).Unix())
googleCloudService, err := NewTestGoogleCloudStorageService(ctx, genericconf.DefaultGoogleCloudStorageConfig)
googleCloudStorageServiceConfig := DefaultGoogleCloudStorageServiceConfig
googleCloudStorageServiceConfig.Enable = true
googleCloudStorageServiceConfig.MaxRetention = time.Hour * 24
googleCloudService, err := NewTestGoogleCloudStorageService(ctx, googleCloudStorageServiceConfig)
Require(t, err)

val1 := []byte("The first value")
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
golang.org/x/sys v0.21.0
golang.org/x/term v0.21.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
google.golang.org/api v0.187.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)

Expand All @@ -58,6 +59,7 @@ require (
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fjl/memsize v0.0.2 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand All @@ -69,7 +71,6 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
google.golang.org/api v0.187.0 // indirect
google.golang.org/genproto v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect
Expand Down

0 comments on commit e63345b

Please sign in to comment.