Skip to content

Commit

Permalink
route module missing from admin api, code cleaning, new line ofor dga…
Browse files Browse the repository at this point in the history
…te-cli, etc.
  • Loading branch information
bubbajoe committed Jun 2, 2024
1 parent 298fa12 commit d577368
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
1 change: 1 addition & 0 deletions cmd/dgate-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func main() {
err := commands.Run(client, version)
if err != nil {
os.Stderr.WriteString(err.Error())
os.Stderr.WriteString("\n")
os.Exit(1)
}
}
10 changes: 3 additions & 7 deletions internal/admin/admin_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ func configureRoutes(
ipList := iplist.NewIPList()
for _, address := range adminConfig.AllowList {
if strings.Contains(address, "/") {
err := ipList.AddCIDRString(address)
if err != nil {
if err := ipList.AddCIDRString(address); err != nil {
panic(fmt.Sprintf("invalid cidr address in admin.allow_list: %s", address))
}
} else {
err := ipList.AddIPString(address)
if err != nil {
if err := ipList.AddIPString(address); err != nil {
panic(fmt.Sprintf("invalid ip address in admin.allow_list: %s", address))
}
}
Expand Down Expand Up @@ -181,9 +179,7 @@ func configureRoutes(
if adminConfig != nil {
server.Route("/api/v1", func(api chi.Router) {
apiLogger := logger.Named("api")
routes.ConfigureRouteAPI(
api,
apiLogger, cs, conf)
routes.ConfigureRouteAPI(api, apiLogger, cs, conf)
routes.ConfigureModuleAPI(api, apiLogger, cs, conf)
routes.ConfigureServiceAPI(api, apiLogger, cs, conf)
routes.ConfigureNamespaceAPI(api, apiLogger, cs, conf)
Expand Down
9 changes: 1 addition & 8 deletions internal/admin/routes/misc_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ func ConfigureChangeLogAPI(server chi.Router, cs changestate.ChangeState, appCon
w.Write([]byte(b))
}
})
server.Get("/changelog/rm", func(w http.ResponseWriter, r *http.Request) {
if b, err := json.Marshal(cs.ResourceManager()); err != nil {
util.JsonError(w, http.StatusInternalServerError, err.Error())
} else {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(b))
}
})
}

func ConfigureHealthAPI(server chi.Router, version string, cs changestate.ChangeState) {
Expand All @@ -54,6 +46,7 @@ func ConfigureHealthAPI(server chi.Router, version string, cs changestate.Change
server.Get("/readyz", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r := cs.Raft(); r != nil {
w.Header().Set("X-Raft-State", r.State().String())
if r.Leader() == "" {
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte(`{"status":"no leader"}`))
Expand Down
8 changes: 4 additions & 4 deletions pkg/dgclient/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ func validateStatusCode(code int) error {
} else if code < 400 {
return errors.New("redirect from server; retry with the --follow flag")
}
return fmt.Errorf("error code %d: %s", code, http.StatusText(code))
return fmt.Errorf("%d error from server", code)
}

func parseApiError(body io.Reader, defaultErr error) error {
func parseApiError(body io.Reader, wrapErr error) error {
var apiError struct {
Error string `json:"error"`
}
if err := json.NewDecoder(body).Decode(&apiError); err != nil || apiError.Error == "" {
return defaultErr
return wrapErr
}
return errors.New("api error: " + apiError.Error)
return fmt.Errorf("%d: %s", wrapErr, apiError.Error)
}
2 changes: 1 addition & 1 deletion pkg/spec/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TransformDGateRoute(r *DGateRoute) *Route {
}
var modules []string
if r.Modules != nil && len(r.Modules) > 0 {
sliceutil.SliceMapper(r.Modules, func(m *DGateModule) string { return m.Name })
modules = sliceutil.SliceMapper(r.Modules, func(m *DGateModule) string { return m.Name })
}
return &Route{
Name: r.Name,
Expand Down

0 comments on commit d577368

Please sign in to comment.