Skip to content

Commit 3182b3f

Browse files
committed
Merge instance configuration manually.
- Always change roles. - Change github configuration only when we configuration is present. Signed-off-by: David Calavera <[email protected]>
1 parent 7a624ca commit 3182b3f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

api/instance.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77

88
"github.com/go-chi/chi"
9-
"github.com/imdario/mergo"
109
"github.com/netlify/git-gateway/conf"
1110
"github.com/netlify/git-gateway/models"
1211
"github.com/pborman/uuid"
@@ -93,9 +92,7 @@ func (a *API) UpdateInstance(w http.ResponseWriter, r *http.Request) error {
9392
}
9493

9594
if params.BaseConfig != nil {
96-
if err := mergo.MergeWithOverwrite(i.BaseConfig, params.BaseConfig); err != nil {
97-
return internalServerError("Error merging instance configurations").WithInternalError(err)
98-
}
95+
i.BaseConfig = mergeConfig(i.BaseConfig, params.BaseConfig)
9996
}
10097

10198
if err := a.db.UpdateInstance(i); err != nil {
@@ -115,3 +112,20 @@ func (a *API) DeleteInstance(w http.ResponseWriter, r *http.Request) error {
115112
w.WriteHeader(http.StatusNoContent)
116113
return nil
117114
}
115+
116+
func mergeConfig(baseConfig *conf.Configuration, newConfig *conf.Configuration) *conf.Configuration {
117+
if newConfig.GitHub.AccessToken != "" {
118+
baseConfig.GitHub.AccessToken = newConfig.GitHub.AccessToken
119+
}
120+
121+
if newConfig.GitHub.Endpoint != "" {
122+
baseConfig.GitHub.Endpoint = newConfig.GitHub.Endpoint
123+
}
124+
125+
if newConfig.GitHub.Repo != "" {
126+
baseConfig.GitHub.Repo = newConfig.GitHub.Repo
127+
}
128+
129+
baseConfig.Roles = newConfig.Roles
130+
return baseConfig
131+
}

0 commit comments

Comments
 (0)