MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / PostgresParameters

Function PostgresParameters

internal/patroni/postgres.go:43–83  ·  view source on GitHub ↗

PostgresParameters returns the Postgres parameters in spec, if any.

(spec *v1beta1.PatroniSpec)

Source from the content-addressed store, hash-verified

41
42// PostgresParameters returns the Postgres parameters in spec, if any.
43func PostgresParameters(spec *v1beta1.PatroniSpec) *postgres.ParameterSet {
44 result := postgres.NewParameterSet()
45
46 if spec != nil {
47 // DynamicConfiguration lacks an OpenAPI schema, so it may contain any type
48 // at any depth. Navigate the object and convert parameter values to string.
49 //
50 // Patroni accepts booleans, integers, and strings but also parses
51 // string values into the types it expects:
52 // https://github.com/patroni/patroni/blob/v4.0.0/patroni/postgresql/validator.py
53 //
54 // Patroni passes JSON arrays and objects through Python str() which looks
55 // similar to YAML in simple cases:
56 // https://github.com/patroni/patroni/blob/v4.0.0/patroni/postgresql/config.py#L254-L259
57 //
58 // >>> str(list((1, 2.3, True, "asdf")))
59 // "[1, 2.3, True, 'asdf']"
60 //
61 // >>> str(dict(a = 1, b = True))
62 // "{'a': 1, 'b': True}"
63 //
64 if root := spec.DynamicConfiguration; root != nil {
65 if postgresql, ok := root["postgresql"].(map[string]any); ok {
66 if section, ok := postgresql["parameters"].(map[string]any); ok {
67 for k, v := range section {
68 switch v.(type) {
69 case []any, map[string]any:
70 if b, err := json.Marshal(v); err == nil {
71 result.Add(k, string(b))
72 }
73 default:
74 result.Add(k, fmt.Sprint(v))
75 }
76 }
77 }
78 }
79 }
80 }
81
82 return result
83}

Callers 2

TestPostgresParametersFunction · 0.85

Calls 2

AddMethod · 0.95
NewParameterSetFunction · 0.92

Tested by 1

TestPostgresParametersFunction · 0.68