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

Function startupCommand

internal/pgadmin/config.go:108–153  ·  view source on GitHub ↗

startupCommand returns an entrypoint that prepares the filesystem for pgAdmin.

()

Source from the content-addressed store, hash-verified

106
107// startupCommand returns an entrypoint that prepares the filesystem for pgAdmin.
108func startupCommand() []string {
109 // pgAdmin reads from the following file by importing its public names.
110 // Make sure to assign only to variables that begin with underscore U+005F.
111 // - https://github.com/pgadmin-org/pgadmin4/blob/REL-4_30/web/config.py#L669
112 // - https://docs.python.org/3/reference/simple_stmts.html#import
113 //
114 // DEFAULT_BINARY_PATHS contains the paths to various client tools. The "pg"
115 // key is for PostgreSQL. Use the latest version found in "/usr" or fallback
116 // to the default of empty string.
117 // - https://github.com/pgadmin-org/pgadmin4/blob/REL-4_30/web/config.py#L415
118 //
119 // Python 3.6.8 (default, Sep 10 2021, 09:13:53)
120 // >>> sorted(['']+[]).pop()
121 // ''
122 // >>> sorted(['']+['/pg13','/pg10']).pop()
123 // '/pg13'
124 //
125 // Set all remaining variables from the JSON in settingsAbsolutePath. All
126 // pgAdmin settings are uppercase with underscores, so ignore any keys/names
127 // that are not.
128 //
129 // Lastly, set pgAdmin's LDAP_BIND_PASSWORD setting, if the value was provided
130 // via Secret. As this assignment happens after any values provided via the
131 // 'Settings' ConfigMap loaded above, this value will overwrite any previous
132 // configuration of LDAP_BIND_PASSWORD (that is, last write wins).
133 const configSystem = `
134import glob, json, re, os
135DEFAULT_BINARY_PATHS = {'pg': sorted([''] + glob.glob('/usr/pgsql-*/bin')).pop()}
136with open('` + settingsAbsolutePath + `') as _f:
137 _conf, _data = re.compile(r'[A-Z_0-9]+'), json.load(_f)
138 if type(_data) is dict:
139 globals().update({k: v for k, v in _data.items() if _conf.fullmatch(k)})
140if os.path.isfile('` + ldapPasswordAbsolutePath + `'):
141 with open('` + ldapPasswordAbsolutePath + `') as _f:
142 LDAP_BIND_PASSWORD = _f.read()
143`
144
145 args := []string{strings.TrimLeft(configSystem, "\n")}
146
147 script := strings.Join([]string{
148 // Write the system configuration into a read-only file.
149 `(umask a-w && echo "$1" > ` + configSystemAbsolutePath + `)`,
150 }, "\n")
151
152 return append([]string{"bash", "-ceu", "--", script, "startup"}, args...)
153}
154
155// systemSettings returns pgAdmin settings as a value that can be marshaled to JSON.
156func systemSettings(spec *v1beta1.PGAdminPodSpec) map[string]any {

Callers 2

TestStartupCommandFunction · 0.70
PodFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestStartupCommandFunction · 0.56