Skip to content

Commit

Permalink
Merge pull request #23 from Amnesic-Systems/rename-flag
Browse files Browse the repository at this point in the history
Rename `ExtPubPort` to `ExtPort`.
  • Loading branch information
NullHypothesis authored Nov 14, 2024
2 parents 25b90dc + 7b50967 commit 9073528
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
10 changes: 5 additions & 5 deletions cmd/veil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

const (
defaultExtPubPort = "8443"
defaultIntPort = "8080"
defaultExtPort = "8443"
defaultIntPort = "8080"
)

func parseFlags(out io.Writer, args []string) (*config.Config, error) {
Expand All @@ -40,9 +40,9 @@ func parseFlags(out io.Writer, args []string) (*config.Config, error) {
false,
"enable debug logging",
)
extPubPort := fs.String(
extPort := fs.String(
"ext-pub-port",
defaultExtPubPort,
defaultExtPort,
"external public port",
)
fqdn := fs.String(
Expand Down Expand Up @@ -80,7 +80,7 @@ func parseFlags(out io.Writer, args []string) (*config.Config, error) {
return &config.Config{
AppWebSrv: util.Must(url.Parse(*appWebSrv)),
Debug: *debug,
ExtPubPort: *extPubPort,
ExtPort: *extPort,
FQDN: *fqdn,
IntPort: *intPort,
EnclaveCodeURI: *enclaveCodeURI,
Expand Down
2 changes: 1 addition & 1 deletion cmd/veil/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func intSrv(path string) string {
}

func extSrv(path string) string {
return fmt.Sprintf("https://127.0.0.1:%s%s", defaultExtPubPort, path)
return fmt.Sprintf("https://127.0.0.1:%s%s", defaultExtPort, path)
}

func errFromBody(t *testing.T, resp *http.Response) string {
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type Config struct {
// nitro-cli's "--debug-mode" flag.
Debug bool

// ExtPubPort contains the TCP port that the public Web server should
// ExtPort contains the TCP port that the public Web server should
// listen on, e.g. 443. This port is not *directly* reachable by the
// Internet but the EC2 host's proxy *does* forward Internet traffic to
// this port. This field is required.
ExtPubPort string
ExtPort string

// FQDN contains the fully qualified domain name that's set in the HTTPS
// certificate of the enclave's Web server, e.g. "example.com". This field
Expand Down Expand Up @@ -83,8 +83,8 @@ func (c *Config) Validate(_ context.Context) map[string]string {
problems := make(map[string]string)

// Check required fields.
if !isValidPort(c.ExtPubPort) {
problems["ExtPubPort"] = "must be a valid port number"
if !isValidPort(c.ExtPort) {
problems["ExtPort"] = "must be a valid port number"
}
if !isValidPort(c.IntPort) {
problems["IntPort"] = "must be a valid port number"
Expand Down
29 changes: 10 additions & 19 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,29 @@ import (
)

func TestConfig(t *testing.T) {
defaultConfig := Config{
ExtPubPort: "443",
IntPort: "8081",
}

cases := []struct {
name string
cfgFn func() *Config
cfg *Config
wantErrs int
}{
{
name: "default config",
cfgFn: func() *Config {
return &defaultConfig
},
wantErrs: 0,
name: "valid config",
cfg: &Config{ExtPort: "8443", IntPort: "8080"},
},
{
name: "still valid config",
cfg: &Config{ExtPort: "1", IntPort: "65535"},
},
{
name: "missing ports",
cfgFn: func() *Config {
confCopy := defaultConfig
confCopy.IntPort = "foo"
confCopy.ExtPubPort = ""
return &confCopy
},
name: "invalid ports",
cfg: &Config{ExtPort: "0", IntPort: "foo"},
wantErrs: 2,
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
errs := c.cfgFn().Validate(context.Background())
errs := c.cfg.Validate(context.Background())
require.Equal(t, c.wantErrs, len(errs), util.SprintErrs(errs))
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func newExtSrv(
addExternalPublicRoutes(r, config, builder)

return &http.Server{
Addr: net.JoinHostPort("0.0.0.0", config.ExtPubPort),
Addr: net.JoinHostPort("0.0.0.0", config.ExtPort),
Handler: http.Handler(r),
}
}

0 comments on commit 9073528

Please sign in to comment.