Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion clients/stellartoml/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"os"

"github.com/BurntSushi/toml"
"github.com/stellar/go/address"
Expand Down Expand Up @@ -55,6 +56,14 @@ func (c *Client) GetStellarTomlByAddress(addr string) (*Response, error) {
return c.GetStellarToml(domain)
}

func getWellKnownPathFromEnv() string {
path := os.Getenv("STELLAR_TOML_PATH")
if path == "" {
return WellKnownPath
}
return path
}

// url returns the appropriate url to load for resolving domain's stellar.toml
// file
func (c *Client) url(domain string) string {
Expand All @@ -66,5 +75,7 @@ func (c *Client) url(domain string) string {
scheme = "https"
}

return fmt.Sprintf("%s://%s%s", scheme, domain, WellKnownPath)
wellKnownPath := getWellKnownPathFromEnv()

return fmt.Sprintf("%s://%s%s", scheme, domain, wellKnownPath)
}
15 changes: 15 additions & 0 deletions clients/stellartoml/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stellartoml

import (
"os"
"strings"
"testing"

Expand Down Expand Up @@ -64,3 +65,17 @@ func TestClient(t *testing.T) {
assert.Contains(t, err.Error(), "toml decode failed")
}
}

func TestGetWellKnownPathFromEnv(t *testing.T) {
// Backup and defer restore
orig := os.Getenv("STELLAR_TOML_PATH")
defer os.Setenv("STELLAR_TOML_PATH", orig)

// Test default
os.Unsetenv("STELLAR_TOML_PATH")
assert.Equal(t, WellKnownPath, getWellKnownPathFromEnv())

// Test custom path
os.Setenv("STELLAR_TOML_PATH", "/custom/path/stellar.toml")
assert.Equal(t, "/custom/path/stellar.toml", getWellKnownPathFromEnv())
}