Skip to content

Commit f47505d

Browse files
committed
feat: optionally disable configuration management via UI/API (#439)
1 parent 2db6723 commit f47505d

File tree

13 files changed

+97
-40
lines changed

13 files changed

+97
-40
lines changed

engine/api/swagger-spec/dblab_server_swagger.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,15 @@ definitions:
679679
properties:
680680
version:
681681
type: "string"
682+
edition:
683+
type: "string"
682684
startedAt:
683685
type: "string"
684686
format: "date-time"
685687
telemetry:
686688
type: boolean
689+
allowModifyingConfig:
690+
type: boolean
687691

688692
PoolEntry:
689693
type: "object"

engine/configs/config.example.logical_generic.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ server:
2323
# HTTP server port. Default: 2345.
2424
port: 2345
2525

26+
# Allow modifying configuration via UI/API. Default: true.
27+
allowModifyingConfig: true
28+
2629
# Embedded UI. Controls the application to provide a user interface to DLE API.
2730
embeddedUI:
2831
enabled: true

engine/configs/config.example.logical_rds_iam.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ server:
2323
# HTTP server port. Default: 2345.
2424
port: 2345
2525

26+
# Allow modifying configuration via UI/API. Default: true.
27+
allowModifyingConfig: true
28+
2629
# Embedded UI. Controls the application to provide a user interface to DLE API.
2730
embeddedUI:
2831
enabled: true

engine/configs/config.example.physical_generic.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ server:
2323
# HTTP server port. Default: 2345.
2424
port: 2345
2525

26+
# Allow modifying configuration via UI/API. Default: true.
27+
allowModifyingConfig: true
28+
2629
# Embedded UI. Controls the application to provide a user interface to DLE API.
2730
embeddedUI:
2831
enabled: true

engine/configs/config.example.physical_pgbackrest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ server:
2323
# HTTP server port. Default: 2345.
2424
port: 2345
2525

26+
# Allow modifying configuration via UI/API. Default: true.
27+
allowModifyingConfig: true
28+
2629
# Embedded UI. Controls the application to provide a user interface to DLE API.
2730
embeddedUI:
2831
enabled: true

engine/configs/config.example.physical_walg.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ server:
2323
# HTTP server port. Default: 2345.
2424
port: 2345
2525

26+
# Allow modifying configuration via UI/API. Default: true.
27+
allowModifyingConfig: true
28+
2629
# Embedded UI. Controls the application to provide a user interface to DLE API.
2730
embeddedUI:
2831
enabled: true

engine/internal/srv/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import (
2323
yamlUtils "gitlab.com/postgres-ai/database-lab/v3/pkg/util/yaml"
2424
)
2525

26-
const connectionCheckTimeout = 10 * time.Second
26+
const (
27+
connectionCheckTimeout = 10 * time.Second
28+
configManagementDenied = "configuration management via UI/API disabled by admin"
29+
)
2730

2831
func (s *Server) getProjectedAdminConfig(w http.ResponseWriter, r *http.Request) {
2932
cfg, err := s.projectedAdminConfig()
@@ -57,6 +60,11 @@ func (s *Server) getAdminConfigYaml(w http.ResponseWriter, r *http.Request) {
5760
}
5861

5962
func (s *Server) setProjectedAdminConfig(w http.ResponseWriter, r *http.Request) {
63+
if !s.Config.AllowModifyingConfig {
64+
api.SendBadRequestError(w, r, configManagementDenied)
65+
return
66+
}
67+
6068
var cfg interface{}
6169
if err := api.ReadJSON(r, &cfg); err != nil {
6270
api.SendBadRequestError(w, r, err.Error())
@@ -91,6 +99,11 @@ func (s *Server) setProjectedAdminConfig(w http.ResponseWriter, r *http.Request)
9199
}
92100

93101
func (s *Server) testDBSource(w http.ResponseWriter, r *http.Request) {
102+
if !s.Config.AllowModifyingConfig {
103+
api.SendBadRequestError(w, r, configManagementDenied)
104+
return
105+
}
106+
94107
if s.Retrieval.State.Mode != models.Logical {
95108
api.SendBadRequestError(w, r, "the endpoint is only available in the Logical mode of the data retrieval")
96109
return

engine/internal/srv/config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ package config
77

88
// Config provides configuration for an HTTP server of the Database Lab.
99
type Config struct {
10-
VerificationToken string `yaml:"verificationToken" json:"-"`
11-
Host string `yaml:"host"`
12-
Port uint `yaml:"port"`
10+
VerificationToken string `yaml:"verificationToken" json:"-"`
11+
Host string `yaml:"host"`
12+
Port uint `yaml:"port"`
13+
AllowModifyingConfig bool `yaml:"allowModifyingConfig" json:"-"`
1314
}

engine/internal/srv/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ func (s *Server) instanceStatus() *models.InstanceStatus {
111111
Message: models.InstanceMessageOK,
112112
},
113113
Engine: models.Engine{
114-
Version: version.GetVersion(),
115-
StartedAt: s.startedAt,
116-
Telemetry: pointer.ToBool(s.tm.IsEnabled()),
114+
Version: version.GetVersion(),
115+
Edition: s.engProps.GetEdition(),
116+
StartedAt: s.startedAt,
117+
Telemetry: pointer.ToBool(s.tm.IsEnabled()),
118+
AllowModifyingConfig: pointer.ToBool(s.Config.AllowModifyingConfig),
117119
},
118120
Pools: s.provisioner.GetPoolEntryList(),
119121
Cloning: s.Cloning.GetCloningState(),

engine/pkg/models/instance_status.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ type Cloning struct {
4444

4545
// Engine represents info about Database Lab Engine instance.
4646
type Engine struct {
47-
Version string `json:"version"`
48-
Edition string `json:"edition"`
49-
StartedAt *LocalTime `json:"startedAt,omitempty"`
50-
Telemetry *bool `json:"telemetry,omitempty"`
47+
Version string `json:"version"`
48+
Edition string `json:"edition"`
49+
StartedAt *LocalTime `json:"startedAt,omitempty"`
50+
Telemetry *bool `json:"telemetry,omitempty"`
51+
AllowModifyingConfig *bool `json:"allowModifyingConfig,omitempty"`
5152
}
5253

5354
// CloneList represents a list of clones.

0 commit comments

Comments
 (0)