-
Notifications
You must be signed in to change notification settings - Fork 2
/
configuration_parameter.go
67 lines (57 loc) · 2.13 KB
/
configuration_parameter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package dbaas
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// ConfigurationParameter is the API response for the configuration parameters.
type ConfigurationParameter struct {
ID string `json:"id"`
DatastoreTypeID string `json:"datastore_type_id"`
Name string `json:"name"`
Type string `json:"type"`
Unit string `json:"unit"`
Min interface{} `json:"min"`
Max interface{} `json:"max"`
DefaultValue interface{} `json:"default_value"`
Choices []interface{} `json:"choices"`
InvalidValues []interface{} `json:"invalid_values"`
IsRestartRequired bool `json:"is_restart_required"`
IsChangeable bool `json:"is_changeable"`
}
const ConfigurationParametersURI = "/configuration-parameters"
// ConfigurationParameters returns all configuration parameters.
func (api *API) ConfigurationParameters(ctx context.Context) ([]ConfigurationParameter, error) {
resp, err := api.makeRequest(ctx, http.MethodGet, ConfigurationParametersURI, nil)
if err != nil {
return []ConfigurationParameter{}, err
}
var result struct {
ConfigurationParameters []ConfigurationParameter `json:"configuration-parameters"`
}
err = json.Unmarshal(resp, &result)
if err != nil {
return []ConfigurationParameter{}, fmt.Errorf("Error during Unmarshal, %w", err)
}
return result.ConfigurationParameters, nil
}
// ConfigurationParameter returns a configuration parameter based on the ID.
func (api *API) ConfigurationParameter(
ctx context.Context,
configurationParameterID string,
) (ConfigurationParameter, error) {
uri := fmt.Sprintf("%s/%s", ConfigurationParametersURI, configurationParameterID)
resp, err := api.makeRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return ConfigurationParameter{}, err
}
var result struct {
ConfigurationParameter ConfigurationParameter `json:"configuration-parameter"`
}
err = json.Unmarshal(resp, &result)
if err != nil {
return ConfigurationParameter{}, fmt.Errorf("Error during Unmarshal, %w", err)
}
return result.ConfigurationParameter, nil
}