startupCommand returns an entrypoint that prepares the filesystem for pgAdmin.
()
| 106 | |
| 107 | // startupCommand returns an entrypoint that prepares the filesystem for pgAdmin. |
| 108 | func 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 = ` |
| 134 | import glob, json, re, os |
| 135 | DEFAULT_BINARY_PATHS = {'pg': sorted([''] + glob.glob('/usr/pgsql-*/bin')).pop()} |
| 136 | with 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)}) |
| 140 | if 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. |
| 156 | func systemSettings(spec *v1beta1.PGAdminPodSpec) map[string]any { |
no outgoing calls