mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 01:48:22 +00:00
Add Fetching of basic server settings
This commit is contained in:
parent
b919c3e09d
commit
09e38928aa
1 changed files with 46 additions and 0 deletions
46
api/settings.go
Normal file
46
api/settings.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// ServerSettingsResponse contains all Servers Settings
|
||||
type ServerSettingsResponse struct {
|
||||
Passbolt ServerPassboltSettings `json:"passbolt"`
|
||||
}
|
||||
|
||||
// ServerPassboltSettings contains Passbolt specific server settings
|
||||
type ServerPassboltSettings struct {
|
||||
Plugins map[string]ServerPassboltPluginSettings `json:"plugins"`
|
||||
}
|
||||
|
||||
// ServerPassboltPluginSettings contains the Settings of a Specific Passbolt Plugin
|
||||
type ServerPassboltPluginSettings struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// GetServerSettings gets the Server Settings
|
||||
func (c *Client) GetServerSettings(ctx context.Context) (*ServerSettingsResponse, error) {
|
||||
msg, err := c.DoCustomRequest(ctx, "GET", "/settings.json", "v3", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var settings ServerSettingsResponse
|
||||
err = json.Unmarshal(msg.Body, &settings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &settings, nil
|
||||
}
|
||||
|
||||
func (ps *ServerPassboltSettings) IsPluginEnabled(name string) bool {
|
||||
p, ok := ps.Plugins[name]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return p.Enabled
|
||||
}
|
Loading…
Add table
Reference in a new issue