Skip to content

Commit

Permalink
cifs: Add 'enable-shared-dirs' config for windows
Browse files Browse the repository at this point in the history
this adds an additional config 'shared-dir-password' to  store
the needed password for mounting the samba share and  modifies
the help message of 'enable-shared-dirs' config for linux  and
macOS

the 'shared-dir-password' config is a secret config and is not
listed in the reponse from the config api when getting all the
config options
  • Loading branch information
anjannath committed Oct 11, 2022
1 parent 34989df commit 4a52aef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
13 changes: 12 additions & 1 deletion cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func runStart(ctx context.Context) (*types.StartResult, error) {
PullSecret: cluster.NewInteractivePullSecretLoader(config),
KubeAdminPassword: config.Get(crcConfig.KubeAdminPassword).AsString(),
Preset: crcConfig.GetPreset(config),
EnableSharedDirs: crcConfig.ShouldEnableSharedDirs(config),
IngressHTTPPort: config.Get(crcConfig.IngressHTTPPort).AsUInt(),
IngressHTTPSPort: config.Get(crcConfig.IngressHTTPSPort).AsUInt(),
EnableSharedDirs: config.Get(crcConfig.EnableSharedDirs).AsBool(),
}

client := newMachine()
Expand All @@ -96,6 +96,17 @@ func runStart(ctx context.Context) (*types.StartResult, error) {
}
}

if runtime.GOOS == "windows" {
username, err := crcos.GetCurrentUsername()
if err != nil {
return nil, err
}

// config SharedDirPassword ('shared-dir-password') only exists in windows
startConfig.SharedDirPassword = config.Get(crcConfig.SharedDirPassword).AsString()
startConfig.SharedDirUsername = username
}

return client.Start(ctx, startConfig)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC
IngressHTTPPort: cfg.Get(crcConfig.IngressHTTPPort).AsUInt(),
IngressHTTPSPort: cfg.Get(crcConfig.IngressHTTPSPort).AsUInt(),
Preset: crcConfig.GetPreset(cfg),
EnableSharedDirs: crcConfig.ShouldEnableSharedDirs(cfg),
EnableSharedDirs: cfg.Get(crcConfig.EnableSharedDirs).AsBool(),
}
}

Expand Down
33 changes: 22 additions & 11 deletions pkg/crc/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
KubeAdminPassword = "kubeadmin-password"
Preset = "preset"
EnableSharedDirs = "enable-shared-dirs"
SharedDirPassword = "shared-dir-password" // #nosec G101
IngressHTTPPort = "ingress-http-port"
IngressHTTPSPort = "ingress-https-port"
)
Expand All @@ -56,6 +57,17 @@ func RegisterSettings(cfg *Config) {
return ValidateBundlePath(value, GetPreset(cfg))
}

validateSmbSharedDirs := func(value interface{}) (bool, string) {
if !cfg.Get(HostNetworkAccess).AsBool() {
return false, fmt.Sprintf("%s can only be used with %s set to 'true'",
EnableSharedDirs, HostNetworkAccess)
}
if cfg.Get(SharedDirPassword).IsDefault {
return false, fmt.Sprintf("Please set '%s' first to enable shared directories", SharedDirPassword)
}
return ValidateBool(value)
}

// Preset setting should be on top because CPUs/Memory config depend on it.
cfg.AddSetting(Preset, string(preset.OpenShift), validatePreset, RequiresDeleteAndSetupMsg,
fmt.Sprintf("Virtual machine preset (valid values are: %s, %s and %s)", preset.Podman, preset.OpenShift, preset.OKD))
Expand All @@ -77,10 +89,17 @@ func RegisterSettings(cfg *Config) {
"Disable update check (true/false, default: false)")
cfg.AddSetting(ExperimentalFeatures, false, ValidateBool, SuccessfullyApplied,
"Enable experimental features (true/false, default: false)")
// shared dir is not implemented for windows yet
if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {

// Shared directories configs
if runtime.GOOS == "windows" {
cfg.AddSetting(SharedDirPassword, Secret(""), ValidateString, SuccessfullyApplied,
"Password used while using CIFS/SMB file sharing (It is the password for the current logged in user)")

cfg.AddSetting(EnableSharedDirs, false, validateSmbSharedDirs, SuccessfullyApplied,
"Mounts host's user profile folder at '/' in the CRC VM (true/false, default: false)")
} else {
cfg.AddSetting(EnableSharedDirs, true, ValidateBool, SuccessfullyApplied,
"Enable shared directories which mounts host's $HOME at /home in the CRC VM (true/false, default: true)")
"Mounts host's home directory at '/' in the CRC VM (true/false, default: true)")
}

if !version.IsInstaller() {
Expand Down Expand Up @@ -145,14 +164,6 @@ func GetNetworkMode(config Storage) network.Mode {
return network.ParseMode(config.Get(NetworkMode).AsString())
}

func ShouldEnableSharedDirs(config Storage) bool {
// Shared dirs are not implemented for windows
if runtime.GOOS == "windows" {
return false
}
return config.Get(EnableSharedDirs).AsBool()
}

func UpdateDefaults(cfg *Config) {
RegisterSettings(cfg)
}

0 comments on commit 4a52aef

Please sign in to comment.