Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Ignore implicit working-directory CLI configuration

Neeraj Gupta3b985c4af2c7
diff --git a/cli/cmd/root.go b/cli/cmd/root.go
index 7dd912dcd1..fd3217387a 100644
--- a/cli/cmd/root.go
+++ b/cli/cmd/root.go
@@ -6,11 +6,8 @@ import (
"runtime"
"github.com/ente/cli/pkg"
- "github.com/spf13/cobra/doc"
-
- "github.com/spf13/viper"
-
"github.com/spf13/cobra"
+ "github.com/spf13/cobra/doc"
)
var version string
@@ -37,9 +34,6 @@ func Execute(controller *pkg.ClICtrl, ver string) {
func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
- viper.SetConfigName("config")
- viper.AddConfigPath(".")
- viper.ReadInConfig()
}
func recoverWithLog() {
diff --git a/cli/config.yaml.example b/cli/config.yaml.example
index 8a4627d555..568de6a887 100644
--- a/cli/config.yaml.example
+++ b/cli/config.yaml.example
@@ -1,6 +1,5 @@
# You can put this configuration file in the following locations:
# - $HOME/.ente/config.yaml
-# - config.yaml in the current working directory
# - $ENTE_CLI_CONFIG_DIR/config.yaml
endpoint:
diff --git a/cli/docs/selfhost.md b/cli/docs/selfhost.md
index ea48ac060e..d8a4c7a6ea 100644
--- a/cli/docs/selfhost.md
+++ b/cli/docs/selfhost.md
@@ -2,7 +2,7 @@
If you are self-hosting the server, you can still configure CLI to export data & perform basic admin actions.
-To do this, first configure the CLI to point to your server. Define a config.yaml and put it either in the same directory as CLI binary or path defined in env variable `ENTE_CLI_CONFIG_DIR`
+To do this, first configure the CLI to point to your server. Define a `config.yaml` and put it in `~/.ente/` or the directory specified by `ENTE_CLI_CONFIG_DIR`.
```yaml
endpoint:
diff --git a/cli/main.go b/cli/main.go
index 7607bdac21..fc57291b11 100644
--- a/cli/main.go
+++ b/cli/main.go
@@ -112,7 +112,6 @@ func initConfig(cliConfigDir string) {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(cliConfigDir + "/")
- viper.AddConfigPath(".")
viper.SetDefault("endpoint.api", constants.EnteApiUrl)
viper.SetDefault("log.http", false)
diff --git a/cli/main_test.go b/cli/main_test.go
new file mode 100644
index 0000000000..07558c5316
--- /dev/null
+++ b/cli/main_test.go
@@ -0,0 +1,90 @@
+package main
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "testing"
+
+ "github.com/ente/cli/utils/constants"
+ "github.com/spf13/viper"
+)
+
+func TestCLIConfigDiscovery(t *testing.T) {
+ if want := os.Getenv("ENTE_CLI_TEST_ENDPOINT"); want != "" {
+ configDir, err := GetCLIConfigDir()
+ if err != nil {
+ t.Fatal(err)
+ }
+ initConfig(configDir)
+ if got := viper.GetString("endpoint.api"); got != want {
+ t.Fatalf("endpoint.api = %q, want %q", got, want)
+ }
+ return
+ }
+
+ executable, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ tests := []struct {
+ name string
+ cwdConfig string
+ trustedConfig string
+ configDir string
+ legacyDir string
+ want string
+ }{
+ {name: "ignore cwd YAML", cwdConfig: "config.yaml", want: constants.EnteApiUrl},
+ {name: "ignore cwd JSON", cwdConfig: "config.json", want: constants.EnteApiUrl},
+ {name: "user config", cwdConfig: "config.yaml", trustedConfig: "home/.ente/config.yml", want: "https://trusted.invalid"},
+ {name: "explicit directory takes precedence", cwdConfig: "config.yaml", trustedConfig: "selected/config.yaml", configDir: "selected", legacyDir: "cwd", want: "https://trusted.invalid"},
+ {name: "legacy directory", cwdConfig: "config.yaml", trustedConfig: "selected/config", legacyDir: "selected", want: "https://trusted.invalid"},
+ {name: "explicit cwd", cwdConfig: "config.yaml", configDir: "cwd", want: "https://untrusted.invalid"},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ root := t.TempDir()
+ home := filepath.Join(root, "home")
+ cwd := filepath.Join(root, "cwd")
+ if err := os.MkdirAll(home, 0700); err != nil {
+ t.Fatal(err)
+ }
+ writeConfig := func(path, endpoint string) {
+ t.Helper()
+ if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
+ t.Fatal(err)
+ }
+ body := "endpoint:\n api: " + endpoint + "\n"
+ if filepath.Ext(path) == ".json" {
+ body = `{"endpoint":{"api":"` + endpoint + `"}}`
+ }
+ if err := os.WriteFile(path, []byte(body), 0600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ writeConfig(filepath.Join(cwd, tt.cwdConfig), "https://untrusted.invalid")
+ if tt.trustedConfig != "" {
+ writeConfig(filepath.Join(root, tt.trustedConfig), "https://trusted.invalid")
+ }
+ envDir := func(path string) string {
+ if path == "" {
+ return ""
+ }
+ return filepath.Join(root, path)
+ }
+ command := exec.Command(executable, "-test.run=^TestCLIConfigDiscovery$")
+ command.Dir = cwd
+ command.Env = append(os.Environ(),
+ "HOME="+home,
+ "USERPROFILE="+home,
+ "ENTE_CLI_CONFIG_DIR="+envDir(tt.configDir),
+ "ENTE_CLI_CONFIG_PATH="+envDir(tt.legacyDir),
+ "ENTE_CLI_TEST_ENDPOINT="+tt.want,
+ )
+ if output, err := command.CombinedOutput(); err != nil {
+ t.Fatalf("%v\n%s", err, output)
+ }
+ })
+ }
+}
diff --git a/docs/docs/self-hosting/administration/cli.md b/docs/docs/self-hosting/administration/cli.md
index b7cb4b00a6..a1244650a5 100644
--- a/docs/docs/self-hosting/administration/cli.md
+++ b/docs/docs/self-hosting/administration/cli.md
@@ -17,7 +17,7 @@ If you are self-hosting, you can configure Ente CLI to export data & perform bas
To do this, first configure the CLI to use your server's endpoint.
-Define `config.yaml` and place it in `~/.ente/` or directory specified by `ENTE_CLI_CONFIG_DIR` or directory where Ente CLI is present.
+Define `config.yaml` and place it in `~/.ente/` or the directory specified by `ENTE_CLI_CONFIG_DIR`.
```yaml
# Set the API endpoint to your domain where Museum is being served.
diff --git a/docs/docs/self-hosting/guides/tailscale.md b/docs/docs/self-hosting/guides/tailscale.md
index b9ebf69f84..6abf1495e7 100644
--- a/docs/docs/self-hosting/guides/tailscale.md
+++ b/docs/docs/self-hosting/guides/tailscale.md
@@ -272,7 +272,7 @@ networks:
> Thats it. Run `docker compose up -d`. Wait until every container becomes healthy. Open a web browser. Make sure tailscale is installed on the machine. Visit https://ente.xyz.ts.net/ping. It will pong. All good if you see it. First time it will take minute or two to get SSL cert. Downnload Desktop or mobile app. Tap 7 time on the screen, which will prompt developer mode. Add https://ente.xyz.ts.net. Add new user. When asked for OTP, go to your linux terminal and run `docker logs ente-museum-1`. Search for userauth. Feed the six digit and Done.
-> For getting 100TB (limitless) storage, install ente-cli for windows. Extract it and add folder. Name it **export**. Add config.yaml file along and populate it with the following:
+> For getting 100TB (limitless) storage, install ente-cli for windows. Extract it and add folder. Name it **export**. Create a `.ente` folder in your user profile directory and add `%USERPROFILE%\.ente\config.yaml` with the following:
```
endpoint: