Skip to content

Commit

Permalink
enable updating of publicHost through server config
Browse files Browse the repository at this point in the history
  • Loading branch information
majelbstoat committed Mar 10, 2022
1 parent 71fdd6b commit fba1be0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fakestorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func (s *Server) updateServerConfig(r *http.Request) jsonResponse {

var configOptions struct {
ExternalUrl string `json:"externalUrl,omitempty"`
PublicHost string `json:"publicHost,omitempty"`
}
err := json.NewDecoder(r.Body).Decode(&configOptions)
if err != nil {
Expand All @@ -22,5 +23,9 @@ func (s *Server) updateServerConfig(r *http.Request) jsonResponse {
s.externalURL = configOptions.ExternalUrl
}

if configOptions.PublicHost != "" {
s.publicHost = configOptions.PublicHost
}

return jsonResponse{status: http.StatusOK}
}
10 changes: 10 additions & 0 deletions fakestorage/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,25 @@ func TestUpdateServerConfig(t *testing.T) {
name string
requestBody string
expectedExternalUrl string
expectedPublicHost string
}{
{
"PUT: empty json",
"{}",
"https://0.0.0.0:4443",
"0.0.0.0:4443",
},
{
"PUT: externalUrl provided",
"{\"externalUrl\": \"https://1.2.3.4:4321\"}",
"https://1.2.3.4:4321",
"0.0.0.0:4443",
},
{
"PUT: publicHost provided",
"{\"publicHost\": \"1.2.3.4:4321\"}",
"https://1.2.3.4:4321",
"1.2.3.4:4321",
},
}

Expand Down Expand Up @@ -317,6 +326,7 @@ func TestUpdateServerConfig(t *testing.T) {
}

assert.Equal(t, test.expectedExternalUrl, server.externalURL)
assert.Equal(t, test.expectedPublicHost, server.publicHost)
})
}
}
Expand Down

0 comments on commit fba1be0

Please sign in to comment.