Skip to content

Commit 8beafba

Browse files
authored
fix: Bug when writing config file if directory doesn't exist + Add arm64 Docker build (#55)
* build: Add goreleaser config to build Docker image for arm64 architecture * fix: Use https for default urls * fix: Ensure config directory exists before writing * chore: Rename config methods * chore: Increment package.json version
1 parent bcebadb commit 8beafba

5 files changed

Lines changed: 58 additions & 24 deletions

File tree

.goreleaser/linux.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ dockers:
6767
- hookdeck
6868
- hookdeck-linux
6969
image_templates:
70-
- "hookdeck/hookdeck-cli:latest"
71-
- "hookdeck/hookdeck-cli:{{ .Tag }}"
70+
- "hookdeck/hookdeck-cli:latest-amd64"
71+
- "hookdeck/hookdeck-cli:{{ .Tag }}-amd64"
7272
build_flag_templates:
7373
- "--pull"
7474
- "--label=org.opencontainers.image.created={{.Date}}"
@@ -77,3 +77,21 @@ dockers:
7777
- "--label=org.opencontainers.image.version={{.Version}}"
7878
- "--label=repository=https://github.com/hookdeck/hookdeck-cli"
7979
- "--label=homepage=https://hookdeck.com"
80+
- "--platform=linux/amd64"
81+
- goos: linux
82+
goarch: arm64
83+
ids:
84+
- hookdeck
85+
- hookdeck-linux-arm
86+
image_templates:
87+
- "hookdeck/hookdeck-cli:latest-arm64"
88+
- "hookdeck/hookdeck-cli:{{ .Tag }}-arm64"
89+
build_flag_templates:
90+
- "--pull"
91+
- "--label=org.opencontainers.image.created={{.Date}}"
92+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
93+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
94+
- "--label=org.opencontainers.image.version={{.Version}}"
95+
- "--label=repository=https://github.com/hookdeck/hookdeck-cli"
96+
- "--label=homepage=https://hookdeck.com"
97+
- "--platform=linux/arm64/v8"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hookdeck-cli",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "Hookdeck CLI",
55
"repository": {
66
"type": "git",

pkg/config/config.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func (c *Config) InitConfig() {
8787
c.LocalConfig = viper.New()
8888

8989
// Read global config
90-
GlobalConfigFolder := c.GetConfigFolder(os.Getenv("XDG_CONFIG_HOME"))
91-
c.GlobalConfigFile = filepath.Join(GlobalConfigFolder, "config.toml")
90+
globalConfigFolder := c.GetConfigFolder(os.Getenv("XDG_CONFIG_HOME"))
91+
c.GlobalConfigFile = filepath.Join(globalConfigFolder, "config.toml")
9292
c.GlobalConfig.SetConfigType("toml")
9393
c.GlobalConfig.SetConfigFile(c.GlobalConfigFile)
9494
c.GlobalConfig.SetConfigPermissions(os.FileMode(0600))
@@ -110,19 +110,19 @@ func (c *Config) InitConfig() {
110110
if err != nil {
111111
log.Fatal(err)
112112
}
113-
LocalConfigFile := ""
113+
localConfigFile := ""
114114
if c.LocalConfigFile == "" {
115-
LocalConfigFile = filepath.Join(workspaceFolder, ".hookdeck/config.toml")
115+
localConfigFile = filepath.Join(workspaceFolder, ".hookdeck/config.toml")
116116
} else {
117117
if filepath.IsAbs(c.LocalConfigFile) {
118-
LocalConfigFile = c.LocalConfigFile
118+
localConfigFile = c.LocalConfigFile
119119
} else {
120-
LocalConfigFile = filepath.Join(workspaceFolder, c.LocalConfigFile)
120+
localConfigFile = filepath.Join(workspaceFolder, c.LocalConfigFile)
121121
}
122122
}
123123
c.LocalConfig.SetConfigType("toml")
124-
c.LocalConfig.SetConfigFile(LocalConfigFile)
125-
c.LocalConfigFile = LocalConfigFile
124+
c.LocalConfig.SetConfigFile(localConfigFile)
125+
c.LocalConfigFile = localConfigFile
126126
if err := c.LocalConfig.ReadInConfig(); err == nil {
127127
log.WithFields(log.Fields{
128128
"prefix": "config.Config.InitConfig",
@@ -243,18 +243,21 @@ func (c *Config) RemoveAllProfiles() error {
243243
runtimeViper.SetConfigType("toml")
244244
runtimeViper.SetConfigFile(c.GlobalConfig.ConfigFileUsed())
245245
c.GlobalConfig = runtimeViper
246-
return c.GlobalConfig.WriteConfig()
246+
return c.WriteGlobalConfig()
247247
}
248248

249-
func (c *Config) SaveLocalConfig() error {
250-
if err := ensureDirectoy(filepath.Dir(c.LocalConfigFile)); err != nil {
249+
func (c *Config) WriteGlobalConfig() error {
250+
if err := makePath(c.GlobalConfig.ConfigFileUsed()); err != nil {
251251
return err
252252
}
253-
return c.LocalConfig.WriteConfig()
253+
return c.GlobalConfig.WriteConfig()
254254
}
255255

256-
func ensureDirectoy(path string) error {
257-
return os.MkdirAll(path, os.ModePerm)
256+
func (c *Config) WriteLocalConfig() error {
257+
if err := makePath(c.LocalConfig.ConfigFileUsed()); err != nil {
258+
return err
259+
}
260+
return c.LocalConfig.WriteConfig()
258261
}
259262

260263
// Construct the config struct from flags > local config > global config
@@ -314,6 +317,19 @@ func removeKey(v *viper.Viper, key string) (*viper.Viper, error) {
314317
return nv, nil
315318
}
316319

320+
func makePath(path string) error {
321+
dir := filepath.Dir(path)
322+
323+
if _, err := os.Stat(dir); os.IsNotExist(err) {
324+
err = os.MkdirAll(dir, os.ModePerm)
325+
if err != nil {
326+
return err
327+
}
328+
}
329+
330+
return nil
331+
}
332+
317333
// taken from https://github.com/spf13/viper/blob/master/util.go#L199,
318334
// we need this to delete configs, remove when viper supprts unset natively
319335
func deepSearch(m map[string]interface{}, path []string) map[string]interface{} {

pkg/config/profile.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ func (p *Profile) SaveProfile(local bool) error {
2222
// and we don't need to expose it to the end user
2323
if local {
2424
p.Config.GlobalConfig.Set(p.GetConfigField("api_key"), p.APIKey)
25-
if err := p.Config.GlobalConfig.WriteConfig(); err != nil {
25+
if err := p.Config.WriteGlobalConfig(); err != nil {
2626
return err
2727
}
2828
p.Config.LocalConfig.Set("workspace_id", p.TeamID)
29-
return p.Config.SaveLocalConfig()
29+
return p.Config.WriteLocalConfig()
3030
} else {
3131
p.Config.GlobalConfig.Set(p.GetConfigField("api_key"), p.APIKey)
3232
p.Config.GlobalConfig.Set(p.GetConfigField("workspace_id"), p.TeamID)
3333
p.Config.GlobalConfig.Set(p.GetConfigField("workspace_mode"), p.TeamMode)
34-
return p.Config.GlobalConfig.WriteConfig()
34+
return p.Config.WriteGlobalConfig()
3535
}
3636
}
3737

@@ -51,12 +51,12 @@ func (p *Profile) RemoveProfile() error {
5151
runtimeViper.SetConfigType("toml")
5252
runtimeViper.SetConfigFile(p.Config.GlobalConfig.ConfigFileUsed())
5353
p.Config.GlobalConfig = runtimeViper
54-
return p.Config.GlobalConfig.WriteConfig()
54+
return p.Config.WriteGlobalConfig()
5555
}
5656

5757
func (p *Profile) UseProfile() error {
5858
p.Config.GlobalConfig.Set("profile", p.Name)
59-
return p.Config.GlobalConfig.WriteConfig()
59+
return p.Config.WriteGlobalConfig()
6060
}
6161

6262
func (p *Profile) ValidateAPIKey() error {

pkg/hookdeck/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const DefaultAPIBaseURL = "https://api.hookdeck.com"
2222
const DefaultDashboardURL = "https://dashboard.hookdeck.com"
2323

2424
// DefaultDashboardBaseURL is the default base URL for dashboard requests
25-
const DefaultDashboardBaseURL = "http://dashboard.hookdeck.com"
25+
const DefaultDashboardBaseURL = "https://dashboard.hookdeck.com"
2626

27-
const DefaultConsoleBaseURL = "http://console.hookdeck.com"
27+
const DefaultConsoleBaseURL = "https://console.hookdeck.com"
2828

2929
const DefaultWebsocektURL = "wss://ws.hookdeck.com"
3030

0 commit comments

Comments
 (0)