Skip to content

Commit

Permalink
enhancement: Configuration to disable API explorer (#1767)
Browse files Browse the repository at this point in the history
* enhancement: Configuration to disable API explorer

Several users have asked whether it's possible to disable the API
explorer UI. This PR adds a configuration option to disable it.

Signed-off-by: Charith Ellawala <charith@cerbos.dev>

* Rename option

Signed-off-by: Charith Ellawala <charith@cerbos.dev>

* Run generate

Signed-off-by: Charith Ellawala <charith@cerbos.dev>

---------

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
  • Loading branch information
charithe committed Aug 29, 2023
1 parent d399486 commit 1130d12
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/modules/configuration/partials/fullconfiguration.adoc
Expand Up @@ -63,6 +63,7 @@ schema:
cacheSize: 1024 # CacheSize defines the number of schemas to cache in memory.
enforcement: reject # Enforcement defines level of the validations. Possible values are none, warn, reject.
server:
apiExplorerEnabled: true # APIExplorerEnabled defines whether the API explorer UI is enabled.
adminAPI: # AdminAPI defines the admin API configuration.
adminCredentials: # AdminCredentials defines the admin user credentials.
passwordHash: JDJ5JDEwJEdEOVFzZDE2VVhoVkR0N2VkUFBVM09nalc0QnNZaC9xc2E4bS9mcUJJcEZXenp5OUpjMi91Cgo= # PasswordHash is the base64-encoded bcrypt hash of the password to use for authentication.
Expand Down
3 changes: 3 additions & 0 deletions internal/server/conf.go
Expand Up @@ -64,6 +64,8 @@ type Conf struct {
LogRequestPayloads bool `yaml:"logRequestPayloads" conf:",example=false"`
// PlaygroundEnabled defines whether the playground API is enabled.
PlaygroundEnabled bool `yaml:"playgroundEnabled" conf:",ignore"`
// APIExplorerEnabled defines whether the API explorer UI is enabled.
APIExplorerEnabled bool `yaml:"apiExplorerEnabled" conf:",example=true"`
// Advanced server settings.
Advanced AdvancedConf `yaml:"advanced"`
}
Expand Down Expand Up @@ -169,6 +171,7 @@ func (c *Conf) SetDefaults() {
c.HTTPListenAddr = defaultHTTPListenAddr
c.GRPCListenAddr = defaultGRPCListenAddr
c.MetricsEnabled = true
c.APIExplorerEnabled = true
c.UDSFileMode = defaultUDSFileMode
c.RequestLimits = RequestLimitsConf{
MaxActionsPerResource: defaultMaxActionsPerResource,
Expand Down
4 changes: 3 additions & 1 deletion internal/server/server.go
Expand Up @@ -539,7 +539,9 @@ func (s *Server) startHTTPServer(ctx context.Context, l net.Listener, grpcSrv *g
cerbosMux.PathPrefix(zpagesEndpoint).Handler(hm)
}

cerbosMux.HandleFunc("/", schema.ServeUI)
if s.conf.APIExplorerEnabled {
cerbosMux.HandleFunc("/", schema.ServeUI)
}

httpHandler := withCORS(s.conf, cerbosMux)

Expand Down

0 comments on commit 1130d12

Please sign in to comment.