Skip to content

Commit

Permalink
Merge branch 'master' into move_strecher_testify
Browse files Browse the repository at this point in the history
  • Loading branch information
Tulsishah committed May 2, 2024
2 parents 392ee0f + 4499126 commit 3c1d7bf
Show file tree
Hide file tree
Showing 22 changed files with 517 additions and 97 deletions.
7 changes: 7 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func newApp() (app *cli.App) {
"GCSFuse uses the global GCS JSON API endpoint, https://storage.googleapis.com/storage/v1.",
},

cli.BoolFlag{
Name: config.AnonymousAccess,
Usage: "Authentication is enabled by default. This flag will disable authentication",
},

cli.StringFlag{
Name: "billing-project",
Value: "",
Expand Down Expand Up @@ -385,6 +390,7 @@ type flagStorage struct {
EgressBandwidthLimitBytesPerSecond float64
OpRateLimitHz float64
SequentialReadSizeMb int32
AnonymousAccess bool

// Tuning
MaxRetrySleep time.Duration
Expand Down Expand Up @@ -516,6 +522,7 @@ func populateFlags(c *cli.Context) (flags *flagStorage, err error) {

// GCS,
CustomEndpoint: customEndpoint,
AnonymousAccess: c.Bool("anonymous-access"),
BillingProject: c.String("billing-project"),
KeyFile: c.String("key-file"),
TokenUrl: c.String("token-url"),
Expand Down
3 changes: 3 additions & 0 deletions flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (t *FlagsTest) Defaults() {
ExpectEq(-1, f.OpRateLimitHz)
ExpectTrue(f.ReuseTokenFromUrl)
ExpectEq(nil, f.CustomEndpoint)
ExpectFalse(f.AnonymousAccess)

// Tuning
ExpectEq(mount.DefaultStatCacheCapacity, f.StatCacheCapacity)
Expand Down Expand Up @@ -115,6 +116,7 @@ func (t *FlagsTest) Bools() {
"enable-nonexistent-type-cache",
"experimental-enable-json-read",
"ignore-interrupts",
"anonymous-access",
}

var args []string
Expand All @@ -137,6 +139,7 @@ func (t *FlagsTest) Bools() {
ExpectTrue(f.EnableNonexistentTypeCache)
ExpectTrue(f.ExperimentalEnableJsonRead)
ExpectTrue(f.IgnoreInterrupts)
ExpectTrue(f.AnonymousAccess)

// --foo=false form
args = nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/jacobsa/syncutil v0.0.0-20180201203307-228ac8e5a6c3
github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.14
go.opencensus.io v0.24.0
golang.org/x/net v0.22.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
Expand Down
10 changes: 10 additions & 0 deletions internal/config/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

const IgnoreInterruptsFlagName = "ignore-interrupts"
const AnonymousAccess = "anonymous-access"

// OverrideWithLoggingFlags overwrites the configs with the flag values if the
// config values are empty.
Expand Down Expand Up @@ -50,6 +51,15 @@ func OverrideWithIgnoreInterruptsFlag(c cliContext, mountConfig *MountConfig, ig
}
}

// OverrideWithAnonymousAccessFlag overwrites the anonymous-access config with
// the anonymous-access flag value if the flag is set.
func OverrideWithAnonymousAccessFlag(c cliContext, mountConfig *MountConfig, anonymousAccess bool) {
// If the anonymous-access flag is set, give it priority over the value in config file.
if c.IsSet(AnonymousAccess) {
mountConfig.AuthConfig.AnonymousAccess = anonymousAccess
}
}

func IsFileCacheEnabled(mountConfig *MountConfig) bool {
return mountConfig.FileCacheConfig.MaxSizeMB != 0 && string(mountConfig.CacheDir) != ""
}
29 changes: 29 additions & 0 deletions internal/config/config_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type flags struct {
DebugGCS bool
DebugMutex bool
IgnoreInterrupts bool
AnonymousAccess bool
}
type ConfigTest struct {
}
Expand Down Expand Up @@ -154,3 +155,31 @@ func TestOverrideWithIgnoreInterruptsFlag(t *testing.T) {
})
}
}

func TestOverrideWithAnonymousAccessFlag(t *testing.T) {
var overrideWithAnonymousAccessFlagTests = []struct {
testName string
anonymousAccessConfigValue bool
isFlagSet bool
anonymousAccessFlagValue bool
expectedAnonymousAccess bool
}{
{"anonymous-access config true and flag not set", true, false, false, true},
{"anonymous-access config false and flag not set", false, false, false, false},
{"anonymous-access config false and anonymous-access flag false", false, true, false, false},
{"anonymous-access config false and anonymous-access flag true", false, true, true, true},
{"anonymous-access config true and anonymous-access flag false", true, true, false, false},
{"anonymous-access config true and anonymous-access flag true", true, true, true, true},
}

for _, tt := range overrideWithAnonymousAccessFlagTests {
t.Run(tt.testName, func(t *testing.T) {
testContext := &TestCliContext{isSet: tt.isFlagSet}
mountConfig := &MountConfig{AuthConfig: AuthConfig{AnonymousAccess: tt.anonymousAccessConfigValue}}

OverrideWithAnonymousAccessFlag(testContext, mountConfig, tt.anonymousAccessFlagValue)

AssertEq(tt.expectedAnonymousAccess, mountConfig.AuthConfig.AnonymousAccess)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auth-config:
anonymous-access: abc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
write:
create-empty-file: true
15 changes: 15 additions & 0 deletions internal/config/yaml_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,18 @@ func (t *YamlParserTest) TestReadConfigFile_FileSystemConfig_UnsetIgnoreInterrup
AssertNe(nil, mountConfig)
AssertEq(false, mountConfig.FileSystemConfig.IgnoreInterrupts)
}

func (t *YamlParserTest) TestReadConfigFile_FileSystemConfig_InvalidAnonymousAccessValue() {
_, err := ParseConfigFile("testdata/auth_config/invalid_anonymous_access.yaml")

AssertNe(nil, err)
AssertTrue(strings.Contains(err.Error(), "error parsing config file: yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `abc` into bool"))
}

func (t *YamlParserTest) TestReadConfigFile_FileSystemConfig_UnsetAnonymousAccessValue() {
mountConfig, err := ParseConfigFile("testdata/auth_config/unset_anonymous_access.yaml")

AssertEq(nil, err)
AssertNe(nil, mountConfig)
AssertEq(false, mountConfig.AuthConfig.AnonymousAccess)
}

0 comments on commit 3c1d7bf

Please sign in to comment.