@reyemtech/nimbus 2.12.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/backup/index.d.ts.map +1 -1
  3. package/dist/cjs/backup/index.js +6 -1
  4. package/dist/cjs/backup/index.js.map +1 -1
  5. package/dist/cjs/cli/migrate-cnpg-ownership.d.ts +43 -0
  6. package/dist/cjs/cli/migrate-cnpg-ownership.d.ts.map +1 -0
  7. package/dist/cjs/cli/migrate-cnpg-ownership.js +67 -0
  8. package/dist/cjs/cli/migrate-cnpg-ownership.js.map +1 -0
  9. package/dist/cjs/cli/migrate-cnpg-roles.d.ts +92 -0
  10. package/dist/cjs/cli/migrate-cnpg-roles.d.ts.map +1 -0
  11. package/dist/cjs/cli/migrate-cnpg-roles.js +337 -0
  12. package/dist/cjs/cli/migrate-cnpg-roles.js.map +1 -0
  13. package/dist/cjs/cli/migrate-cnpg.d.ts +38 -0
  14. package/dist/cjs/cli/migrate-cnpg.d.ts.map +1 -0
  15. package/dist/cjs/cli/migrate-cnpg.js +258 -0
  16. package/dist/cjs/cli/migrate-cnpg.js.map +1 -0
  17. package/dist/cjs/cli/migrate-exec.d.ts +45 -0
  18. package/dist/cjs/cli/migrate-exec.d.ts.map +1 -0
  19. package/dist/cjs/cli/migrate-exec.js +104 -0
  20. package/dist/cjs/cli/migrate-exec.js.map +1 -0
  21. package/dist/cjs/cli/migrate-psql.d.ts +125 -0
  22. package/dist/cjs/cli/migrate-psql.d.ts.map +1 -0
  23. package/dist/cjs/cli/migrate-psql.js +213 -0
  24. package/dist/cjs/cli/migrate-psql.js.map +1 -0
  25. package/dist/cjs/cli/migrate-report.d.ts +27 -0
  26. package/dist/cjs/cli/migrate-report.d.ts.map +1 -0
  27. package/dist/cjs/cli/migrate-report.js +29 -0
  28. package/dist/cjs/cli/migrate-report.js.map +1 -0
  29. package/dist/cjs/cli/migrate-superuser.d.ts +22 -0
  30. package/dist/cjs/cli/migrate-superuser.d.ts.map +1 -0
  31. package/dist/cjs/cli/migrate-superuser.js +73 -0
  32. package/dist/cjs/cli/migrate-superuser.js.map +1 -0
  33. package/dist/cjs/cli/migrate.d.ts +37 -0
  34. package/dist/cjs/cli/migrate.d.ts.map +1 -0
  35. package/dist/cjs/cli/migrate.js +67 -0
  36. package/dist/cjs/cli/migrate.js.map +1 -0
  37. package/dist/cjs/cli.d.ts +1 -0
  38. package/dist/cjs/cli.d.ts.map +1 -1
  39. package/dist/cjs/cli.js +6 -0
  40. package/dist/cjs/cli.js.map +1 -1
  41. package/dist/cjs/index.d.ts +1 -1
  42. package/dist/cjs/index.d.ts.map +1 -1
  43. package/dist/cjs/index.js.map +1 -1
  44. package/dist/cjs/operator/cnpg-common.d.ts +56 -0
  45. package/dist/cjs/operator/cnpg-common.d.ts.map +1 -0
  46. package/dist/cjs/operator/cnpg-common.js +82 -0
  47. package/dist/cjs/operator/cnpg-common.js.map +1 -0
  48. package/dist/cjs/operator/cnpg-database.d.ts +66 -0
  49. package/dist/cjs/operator/cnpg-database.d.ts.map +1 -0
  50. package/dist/cjs/operator/cnpg-database.js +296 -0
  51. package/dist/cjs/operator/cnpg-database.js.map +1 -0
  52. package/dist/cjs/operator/cnpg-roles.d.ts +173 -0
  53. package/dist/cjs/operator/cnpg-roles.d.ts.map +1 -0
  54. package/dist/cjs/operator/cnpg-roles.js +225 -0
  55. package/dist/cjs/operator/cnpg-roles.js.map +1 -0
  56. package/dist/cjs/operator/cnpg.d.ts.map +1 -1
  57. package/dist/cjs/operator/cnpg.js +50 -162
  58. package/dist/cjs/operator/cnpg.js.map +1 -1
  59. package/dist/cjs/operator/connection-uri.d.ts +44 -0
  60. package/dist/cjs/operator/connection-uri.d.ts.map +1 -0
  61. package/dist/cjs/operator/connection-uri.js +49 -0
  62. package/dist/cjs/operator/connection-uri.js.map +1 -0
  63. package/dist/cjs/operator/credentials.d.ts +76 -0
  64. package/dist/cjs/operator/credentials.d.ts.map +1 -0
  65. package/dist/cjs/operator/credentials.js +106 -0
  66. package/dist/cjs/operator/credentials.js.map +1 -0
  67. package/dist/cjs/operator/database-options.d.ts +121 -0
  68. package/dist/cjs/operator/database-options.d.ts.map +1 -0
  69. package/dist/cjs/operator/database-options.js +131 -0
  70. package/dist/cjs/operator/database-options.js.map +1 -0
  71. package/dist/cjs/operator/grants/postgres-job.d.ts +109 -0
  72. package/dist/cjs/operator/grants/postgres-job.d.ts.map +1 -0
  73. package/dist/cjs/operator/grants/postgres-job.js +232 -0
  74. package/dist/cjs/operator/grants/postgres-job.js.map +1 -0
  75. package/dist/cjs/operator/grants/postgres-sql.d.ts +130 -0
  76. package/dist/cjs/operator/grants/postgres-sql.d.ts.map +1 -0
  77. package/dist/cjs/operator/grants/postgres-sql.js +305 -0
  78. package/dist/cjs/operator/grants/postgres-sql.js.map +1 -0
  79. package/dist/cjs/operator/grants/privileges.d.ts +24 -0
  80. package/dist/cjs/operator/grants/privileges.d.ts.map +1 -0
  81. package/dist/cjs/operator/grants/privileges.js +35 -0
  82. package/dist/cjs/operator/grants/privileges.js.map +1 -0
  83. package/dist/cjs/operator/grants/role-config.d.ts +80 -0
  84. package/dist/cjs/operator/grants/role-config.d.ts.map +1 -0
  85. package/dist/cjs/operator/grants/role-config.js +134 -0
  86. package/dist/cjs/operator/grants/role-config.js.map +1 -0
  87. package/dist/cjs/operator/index.d.ts +1 -1
  88. package/dist/cjs/operator/index.d.ts.map +1 -1
  89. package/dist/cjs/operator/index.js.map +1 -1
  90. package/dist/cjs/operator/interfaces.d.ts +223 -1
  91. package/dist/cjs/operator/interfaces.d.ts.map +1 -1
  92. package/dist/cjs/operator/interfaces.js.map +1 -1
  93. package/dist/cjs/operator/mariadb-common.d.ts +99 -0
  94. package/dist/cjs/operator/mariadb-common.d.ts.map +1 -0
  95. package/dist/cjs/operator/mariadb-common.js +141 -0
  96. package/dist/cjs/operator/mariadb-common.js.map +1 -0
  97. package/dist/cjs/operator/mariadb-database.d.ts +65 -0
  98. package/dist/cjs/operator/mariadb-database.d.ts.map +1 -0
  99. package/dist/cjs/operator/mariadb-database.js +285 -0
  100. package/dist/cjs/operator/mariadb-database.js.map +1 -0
  101. package/dist/cjs/operator/mariadb-roles.d.ts +264 -0
  102. package/dist/cjs/operator/mariadb-roles.d.ts.map +1 -0
  103. package/dist/cjs/operator/mariadb-roles.js +366 -0
  104. package/dist/cjs/operator/mariadb-roles.js.map +1 -0
  105. package/dist/cjs/operator/mariadb.d.ts.map +1 -1
  106. package/dist/cjs/operator/mariadb.js +35 -147
  107. package/dist/cjs/operator/mariadb.js.map +1 -1
  108. package/dist/cjs/operator/neo4j-common.d.ts +62 -0
  109. package/dist/cjs/operator/neo4j-common.d.ts.map +1 -0
  110. package/dist/cjs/operator/neo4j-common.js +89 -0
  111. package/dist/cjs/operator/neo4j-common.js.map +1 -0
  112. package/dist/cjs/operator/neo4j-database.d.ts +88 -0
  113. package/dist/cjs/operator/neo4j-database.d.ts.map +1 -0
  114. package/dist/cjs/operator/neo4j-database.js +274 -0
  115. package/dist/cjs/operator/neo4j-database.js.map +1 -0
  116. package/dist/cjs/operator/neo4j-roles.d.ts +203 -0
  117. package/dist/cjs/operator/neo4j-roles.d.ts.map +1 -0
  118. package/dist/cjs/operator/neo4j-roles.js +298 -0
  119. package/dist/cjs/operator/neo4j-roles.js.map +1 -0
  120. package/dist/cjs/operator/neo4j.d.ts.map +1 -1
  121. package/dist/cjs/operator/neo4j.js +32 -132
  122. package/dist/cjs/operator/neo4j.js.map +1 -1
  123. package/dist/cjs/operator/resource-identity.d.ts +170 -0
  124. package/dist/cjs/operator/resource-identity.d.ts.map +1 -0
  125. package/dist/cjs/operator/resource-identity.js +231 -0
  126. package/dist/cjs/operator/resource-identity.js.map +1 -0
  127. package/dist/cjs/operator/role-registry.d.ts +85 -0
  128. package/dist/cjs/operator/role-registry.d.ts.map +1 -0
  129. package/dist/cjs/operator/role-registry.js +72 -0
  130. package/dist/cjs/operator/role-registry.js.map +1 -0
  131. package/dist/cjs/platform/components/image-pruner.d.ts +3 -1
  132. package/dist/cjs/platform/components/image-pruner.d.ts.map +1 -1
  133. package/dist/cjs/platform/components/image-pruner.js +38 -19
  134. package/dist/cjs/platform/components/image-pruner.js.map +1 -1
  135. package/dist/cjs/types/errors.d.ts +3 -0
  136. package/dist/cjs/types/errors.d.ts.map +1 -1
  137. package/dist/cjs/types/errors.js +3 -0
  138. package/dist/cjs/types/errors.js.map +1 -1
  139. package/dist/esm/backup/index.d.ts.map +1 -1
  140. package/dist/esm/backup/index.js +6 -1
  141. package/dist/esm/backup/index.js.map +1 -1
  142. package/dist/esm/cli/migrate-cnpg-ownership.d.ts +43 -0
  143. package/dist/esm/cli/migrate-cnpg-ownership.d.ts.map +1 -0
  144. package/dist/esm/cli/migrate-cnpg-ownership.js +67 -0
  145. package/dist/esm/cli/migrate-cnpg-ownership.js.map +1 -0
  146. package/dist/esm/cli/migrate-cnpg-roles.d.ts +92 -0
  147. package/dist/esm/cli/migrate-cnpg-roles.d.ts.map +1 -0
  148. package/dist/esm/cli/migrate-cnpg-roles.js +337 -0
  149. package/dist/esm/cli/migrate-cnpg-roles.js.map +1 -0
  150. package/dist/esm/cli/migrate-cnpg.d.ts +38 -0
  151. package/dist/esm/cli/migrate-cnpg.d.ts.map +1 -0
  152. package/dist/esm/cli/migrate-cnpg.js +258 -0
  153. package/dist/esm/cli/migrate-cnpg.js.map +1 -0
  154. package/dist/esm/cli/migrate-exec.d.ts +45 -0
  155. package/dist/esm/cli/migrate-exec.d.ts.map +1 -0
  156. package/dist/esm/cli/migrate-exec.js +104 -0
  157. package/dist/esm/cli/migrate-exec.js.map +1 -0
  158. package/dist/esm/cli/migrate-psql.d.ts +125 -0
  159. package/dist/esm/cli/migrate-psql.d.ts.map +1 -0
  160. package/dist/esm/cli/migrate-psql.js +213 -0
  161. package/dist/esm/cli/migrate-psql.js.map +1 -0
  162. package/dist/esm/cli/migrate-report.d.ts +27 -0
  163. package/dist/esm/cli/migrate-report.d.ts.map +1 -0
  164. package/dist/esm/cli/migrate-report.js +29 -0
  165. package/dist/esm/cli/migrate-report.js.map +1 -0
  166. package/dist/esm/cli/migrate-superuser.d.ts +22 -0
  167. package/dist/esm/cli/migrate-superuser.d.ts.map +1 -0
  168. package/dist/esm/cli/migrate-superuser.js +73 -0
  169. package/dist/esm/cli/migrate-superuser.js.map +1 -0
  170. package/dist/esm/cli/migrate.d.ts +37 -0
  171. package/dist/esm/cli/migrate.d.ts.map +1 -0
  172. package/dist/esm/cli/migrate.js +67 -0
  173. package/dist/esm/cli/migrate.js.map +1 -0
  174. package/dist/esm/cli.d.ts +1 -0
  175. package/dist/esm/cli.d.ts.map +1 -1
  176. package/dist/esm/cli.js +6 -0
  177. package/dist/esm/cli.js.map +1 -1
  178. package/dist/esm/index.d.ts +1 -1
  179. package/dist/esm/index.d.ts.map +1 -1
  180. package/dist/esm/index.js.map +1 -1
  181. package/dist/esm/operator/cnpg-common.d.ts +56 -0
  182. package/dist/esm/operator/cnpg-common.d.ts.map +1 -0
  183. package/dist/esm/operator/cnpg-common.js +82 -0
  184. package/dist/esm/operator/cnpg-common.js.map +1 -0
  185. package/dist/esm/operator/cnpg-database.d.ts +66 -0
  186. package/dist/esm/operator/cnpg-database.d.ts.map +1 -0
  187. package/dist/esm/operator/cnpg-database.js +296 -0
  188. package/dist/esm/operator/cnpg-database.js.map +1 -0
  189. package/dist/esm/operator/cnpg-roles.d.ts +173 -0
  190. package/dist/esm/operator/cnpg-roles.d.ts.map +1 -0
  191. package/dist/esm/operator/cnpg-roles.js +225 -0
  192. package/dist/esm/operator/cnpg-roles.js.map +1 -0
  193. package/dist/esm/operator/cnpg.d.ts.map +1 -1
  194. package/dist/esm/operator/cnpg.js +50 -162
  195. package/dist/esm/operator/cnpg.js.map +1 -1
  196. package/dist/esm/operator/connection-uri.d.ts +44 -0
  197. package/dist/esm/operator/connection-uri.d.ts.map +1 -0
  198. package/dist/esm/operator/connection-uri.js +49 -0
  199. package/dist/esm/operator/connection-uri.js.map +1 -0
  200. package/dist/esm/operator/credentials.d.ts +76 -0
  201. package/dist/esm/operator/credentials.d.ts.map +1 -0
  202. package/dist/esm/operator/credentials.js +106 -0
  203. package/dist/esm/operator/credentials.js.map +1 -0
  204. package/dist/esm/operator/database-options.d.ts +121 -0
  205. package/dist/esm/operator/database-options.d.ts.map +1 -0
  206. package/dist/esm/operator/database-options.js +131 -0
  207. package/dist/esm/operator/database-options.js.map +1 -0
  208. package/dist/esm/operator/grants/postgres-job.d.ts +109 -0
  209. package/dist/esm/operator/grants/postgres-job.d.ts.map +1 -0
  210. package/dist/esm/operator/grants/postgres-job.js +232 -0
  211. package/dist/esm/operator/grants/postgres-job.js.map +1 -0
  212. package/dist/esm/operator/grants/postgres-sql.d.ts +130 -0
  213. package/dist/esm/operator/grants/postgres-sql.d.ts.map +1 -0
  214. package/dist/esm/operator/grants/postgres-sql.js +305 -0
  215. package/dist/esm/operator/grants/postgres-sql.js.map +1 -0
  216. package/dist/esm/operator/grants/privileges.d.ts +24 -0
  217. package/dist/esm/operator/grants/privileges.d.ts.map +1 -0
  218. package/dist/esm/operator/grants/privileges.js +35 -0
  219. package/dist/esm/operator/grants/privileges.js.map +1 -0
  220. package/dist/esm/operator/grants/role-config.d.ts +80 -0
  221. package/dist/esm/operator/grants/role-config.d.ts.map +1 -0
  222. package/dist/esm/operator/grants/role-config.js +134 -0
  223. package/dist/esm/operator/grants/role-config.js.map +1 -0
  224. package/dist/esm/operator/index.d.ts +1 -1
  225. package/dist/esm/operator/index.d.ts.map +1 -1
  226. package/dist/esm/operator/index.js.map +1 -1
  227. package/dist/esm/operator/interfaces.d.ts +223 -1
  228. package/dist/esm/operator/interfaces.d.ts.map +1 -1
  229. package/dist/esm/operator/interfaces.js.map +1 -1
  230. package/dist/esm/operator/mariadb-common.d.ts +99 -0
  231. package/dist/esm/operator/mariadb-common.d.ts.map +1 -0
  232. package/dist/esm/operator/mariadb-common.js +141 -0
  233. package/dist/esm/operator/mariadb-common.js.map +1 -0
  234. package/dist/esm/operator/mariadb-database.d.ts +65 -0
  235. package/dist/esm/operator/mariadb-database.d.ts.map +1 -0
  236. package/dist/esm/operator/mariadb-database.js +285 -0
  237. package/dist/esm/operator/mariadb-database.js.map +1 -0
  238. package/dist/esm/operator/mariadb-roles.d.ts +264 -0
  239. package/dist/esm/operator/mariadb-roles.d.ts.map +1 -0
  240. package/dist/esm/operator/mariadb-roles.js +366 -0
  241. package/dist/esm/operator/mariadb-roles.js.map +1 -0
  242. package/dist/esm/operator/mariadb.d.ts.map +1 -1
  243. package/dist/esm/operator/mariadb.js +35 -147
  244. package/dist/esm/operator/mariadb.js.map +1 -1
  245. package/dist/esm/operator/neo4j-common.d.ts +62 -0
  246. package/dist/esm/operator/neo4j-common.d.ts.map +1 -0
  247. package/dist/esm/operator/neo4j-common.js +89 -0
  248. package/dist/esm/operator/neo4j-common.js.map +1 -0
  249. package/dist/esm/operator/neo4j-database.d.ts +88 -0
  250. package/dist/esm/operator/neo4j-database.d.ts.map +1 -0
  251. package/dist/esm/operator/neo4j-database.js +274 -0
  252. package/dist/esm/operator/neo4j-database.js.map +1 -0
  253. package/dist/esm/operator/neo4j-roles.d.ts +203 -0
  254. package/dist/esm/operator/neo4j-roles.d.ts.map +1 -0
  255. package/dist/esm/operator/neo4j-roles.js +298 -0
  256. package/dist/esm/operator/neo4j-roles.js.map +1 -0
  257. package/dist/esm/operator/neo4j.d.ts.map +1 -1
  258. package/dist/esm/operator/neo4j.js +32 -132
  259. package/dist/esm/operator/neo4j.js.map +1 -1
  260. package/dist/esm/operator/resource-identity.d.ts +170 -0
  261. package/dist/esm/operator/resource-identity.d.ts.map +1 -0
  262. package/dist/esm/operator/resource-identity.js +231 -0
  263. package/dist/esm/operator/resource-identity.js.map +1 -0
  264. package/dist/esm/operator/role-registry.d.ts +85 -0
  265. package/dist/esm/operator/role-registry.d.ts.map +1 -0
  266. package/dist/esm/operator/role-registry.js +72 -0
  267. package/dist/esm/operator/role-registry.js.map +1 -0
  268. package/dist/esm/platform/components/image-pruner.d.ts +3 -1
  269. package/dist/esm/platform/components/image-pruner.d.ts.map +1 -1
  270. package/dist/esm/platform/components/image-pruner.js +38 -19
  271. package/dist/esm/platform/components/image-pruner.js.map +1 -1
  272. package/dist/esm/types/errors.d.ts +3 -0
  273. package/dist/esm/types/errors.d.ts.map +1 -1
  274. package/dist/esm/types/errors.js +3 -0
  275. package/dist/esm/types/errors.js.map +1 -1
  276. package/package.json +1 -1
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ /**
3
+ * Databases inside a MariaDB Operator instance.
4
+ *
5
+ * Provisioning is fully declarative: a `Database` CR owns the database, a
6
+ * `User` CR owns each login account and its password, and a `Grant` CR owns
7
+ * each privilege set. Unlike CloudNativePG — where privileges have no CRD
8
+ * equivalent and are applied by a `psql` Job — nothing here executes SQL, which
9
+ * is also why `config.sql` throws rather than being dropped. The operator
10
+ * reconciles all three kinds continuously, so drift is corrected rather than
11
+ * silently persisting.
12
+ *
13
+ * @module operator/mariadb-database
14
+ */
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
28
+ }) : function(o, v) {
29
+ o["default"] = v;
30
+ });
31
+ var __importStar = (this && this.__importStar) || (function () {
32
+ var ownKeys = function(o) {
33
+ ownKeys = Object.getOwnPropertyNames || function (o) {
34
+ var ar = [];
35
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
36
+ return ar;
37
+ };
38
+ return ownKeys(o);
39
+ };
40
+ return function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
47
+ })();
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.createSingleMariadbDatabaseInstance = createSingleMariadbDatabaseInstance;
50
+ const k8s = __importStar(require("@pulumi/kubernetes"));
51
+ const pulumi = __importStar(require("@pulumi/pulumi"));
52
+ const mariadb_common_js_1 = require("./mariadb-common.js");
53
+ const mariadb_roles_js_1 = require("./mariadb-roles.js");
54
+ const role_config_js_1 = require("./grants/role-config.js");
55
+ const database_options_js_1 = require("./database-options.js");
56
+ const errors_js_1 = require("../types/errors.js");
57
+ /** Label marking every object this module creates as nimbus-managed. */
58
+ const MANAGED_BY_LABEL = "app.kubernetes.io/managed-by";
59
+ /** Value of {@link MANAGED_BY_LABEL}. */
60
+ const MANAGED_BY_VALUE = "nimbus";
61
+ /** Character set every provisioned database is created with. */
62
+ const DEFAULT_CHARACTER_SET = "utf8mb4";
63
+ /** Collation every provisioned database is created with. */
64
+ const DEFAULT_COLLATION = "utf8mb4_unicode_ci";
65
+ /** Field of the `Database` CR that mariadb-operator rejects updates to. */
66
+ const DATABASE_IMMUTABLE_FIELDS = ["spec.name"];
67
+ /** Engine name used in errors about options MariaDB cannot honour. */
68
+ const MARIADB_ENGINE_NAME = database_options_js_1.ENGINE_NAMES.MARIADB;
69
+ /**
70
+ * Create a single database instance within a MariaDB instance.
71
+ *
72
+ * The owner is granted `ALL PRIVILEGES` on the database with `GRANT OPTION`,
73
+ * and its connection details are replicated into the configured namespaces.
74
+ * Additional roles are added afterwards via the returned `addRole()`.
75
+ *
76
+ * @param options - Instance, database name, configuration, and provider
77
+ * @returns The database instance, with `addRole()` bound to it
78
+ * @throws {AnyCloudError} code `INVALID_GRANT` when a role's grant lists no privileges
79
+ * @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a role's grant names
80
+ * a privilege a database-scoped MariaDB `GRANT` cannot carry
81
+ * @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when `dbName` is blank
82
+ * or `addRole()` is called with a blank name, when `config.sql` is
83
+ * set (MariaDB runs no SQL), when `config.owner` is set to anything but the
84
+ * database name, when `addRole()` is called with the database owner's own
85
+ * name, when `addRole()` is called with a `user`@`host` pair any other
86
+ * database on the same instance has already claimed, when `addRole()` is
87
+ * passed `login: false`, or when it is passed an `engineOptions` block
88
+ * belonging to another engine
89
+ */
90
+ function createSingleMariadbDatabaseInstance(options) {
91
+ const { clusterName, dbName, config, endpoint, port, mariadb, provider } = options;
92
+ const { roleRegistry } = options;
93
+ (0, role_config_js_1.assertValidDatabaseName)(dbName);
94
+ // Nothing here executes SQL — provisioning is CRs all the way down — so
95
+ // `sql` is refused rather than dropped on the floor.
96
+ (0, database_options_js_1.assertNoSql)(dbName, config, MARIADB_ENGINE_NAME);
97
+ // MariaDB cannot honour `owner`, and rejects it rather than ignoring it.
98
+ //
99
+ // The live `User` and `Grant` CRs carry `ignoreChanges` on `spec.name` /
100
+ // `spec.username` because mariadb-operator's webhook refuses updates to them.
101
+ // `ignoreChanges` suppresses diffs only on resources that already exist, so
102
+ // honouring `owner` would in fact work on a greenfield stack and break only on
103
+ // upgrade: the existing account would stay named after the database while
104
+ // `username` and `uri` flipped in every already-replicated connection Secret,
105
+ // leaving applications authenticating as a user that was never created. An
106
+ // option whose correctness depends on how old the stack is, is worse than one
107
+ // that is refused outright — so this fails at preview, before anything is
108
+ // registered. The owner's username is always the database name.
109
+ if (config.owner !== undefined && config.owner !== dbName) {
110
+ throw new errors_js_1.AnyCloudError(`Database "${dbName}" cannot set owner "${config.owner}" on MariaDB — the owner is ` +
111
+ `always the database name. mariadb-operator treats User.spec.name and ` +
112
+ `Grant.spec.username as immutable, so an owner that differs would rename only the ` +
113
+ `replicated connection Secrets. Remove "owner", or use addRole("${config.owner}") ` +
114
+ `to create it as an additional role.`, errors_js_1.ERROR_CODES.UNSUPPORTED_ROLE_OPTION);
115
+ }
116
+ const username = dbName;
117
+ (0, role_config_js_1.assertValidRoleName)(username, dbName);
118
+ // The owner's CRs omit `spec.host` and rely on the operator's own default,
119
+ // which is DEFAULT_GRANT_HOST — so that is the host its account effectively
120
+ // has, and the host it must claim. Claiming it matters because a later
121
+ // addRole() on a *different* database could otherwise take the same pair.
122
+ (0, mariadb_common_js_1.claimMariadbRoleName)(roleRegistry, username, mariadb_common_js_1.DEFAULT_GRANT_HOST, dbName);
123
+ const labels = {
124
+ [MANAGED_BY_LABEL]: MANAGED_BY_VALUE,
125
+ "nimbus/cluster": clusterName,
126
+ "nimbus/database": dbName,
127
+ };
128
+ const ownerNaming = (0, mariadb_roles_js_1.ownerRoleNaming)(clusterName, dbName);
129
+ const ownerConfig = (0, role_config_js_1.resolveRoleConfig)({ namespaces: config.namespaces, login: true });
130
+ // Database CR: owns the database itself. `spec.name` is the raw MariaDB
131
+ // identifier so the CR adopts a database created under that exact name.
132
+ const database = new k8s.apiextensions.CustomResource(`${clusterName}-${dbName}-database`, {
133
+ apiVersion: mariadb_common_js_1.MARIADB_API_VERSION,
134
+ kind: mariadb_common_js_1.DATABASE_KIND,
135
+ metadata: {
136
+ name: `${clusterName}-${dbName}`,
137
+ namespace: mariadb_common_js_1.DATA_NAMESPACE,
138
+ labels,
139
+ },
140
+ spec: {
141
+ mariaDbRef: { name: clusterName },
142
+ name: dbName,
143
+ characterSet: DEFAULT_CHARACTER_SET,
144
+ collate: DEFAULT_COLLATION,
145
+ },
146
+ }, { provider, dependsOn: [mariadb], ignoreChanges: DATABASE_IMMUTABLE_FIELDS });
147
+ // The owner's User and Grant CRs deliberately omit `spec.host`: the live
148
+ // objects were created without it and rely on the operator's own default, so
149
+ // writing it explicitly would diff an immutable field on every existing stack.
150
+ const owner = (0, mariadb_roles_js_1.provisionMariadbRole)({
151
+ clusterName,
152
+ dbName,
153
+ roleName: username,
154
+ naming: ownerNaming,
155
+ grants: [mariadb_roles_js_1.OWNER_GRANT],
156
+ labels,
157
+ mariadb,
158
+ database,
159
+ provider,
160
+ });
161
+ const secrets = (0, mariadb_roles_js_1.replicateMariadbConnectionSecrets)({
162
+ naming: ownerNaming,
163
+ namespaces: ownerConfig.namespaces,
164
+ dbName,
165
+ username,
166
+ password: owner.credentials.stablePassword,
167
+ endpoint,
168
+ port,
169
+ labels,
170
+ provider,
171
+ dependsOn: owner.grants,
172
+ });
173
+ return {
174
+ name: dbName,
175
+ clusterName,
176
+ host: endpoint,
177
+ port,
178
+ database: pulumi.output(dbName),
179
+ secrets,
180
+ nativeResource: database,
181
+ addRole(roleName, roleConfig) {
182
+ (0, role_config_js_1.assertValidRoleName)(roleName, dbName);
183
+ // The owner already has a User CR from createDatabase(). Adding it again
184
+ // would create a SECOND CR for the same MariaDB account, bound to a
185
+ // different password Secret, and the two would then reconcile that
186
+ // account's password against each other indefinitely — leaving the
187
+ // owner's replicated connection Secrets holding a credential that no
188
+ // longer authenticates. The two CRs have different Pulumi logical names,
189
+ // so `pulumi preview` sees no conflict and this fails only in production.
190
+ if (roleName === username) {
191
+ throw new errors_js_1.AnyCloudError(`Role "${roleName}" is the owner of database "${dbName}" and is created by ` +
192
+ `createDatabase(); it cannot be added again. Use a different role name — on ` +
193
+ `MariaDB the owner is always the database name.`, errors_js_1.ERROR_CODES.UNSUPPORTED_ROLE_OPTION);
194
+ }
195
+ const resolved = (0, role_config_js_1.resolveRoleConfig)(roleConfig);
196
+ // Every MariaDB account is a login account — `CREATE USER` has no
197
+ // non-login form. Honouring `login: false` by ignoring it would hand back
198
+ // a role that can log in when the caller asked for one that cannot.
199
+ if (!resolved.login) {
200
+ throw new errors_js_1.AnyCloudError(`Role "${roleName}" cannot be created with login: false on MariaDB — every ` +
201
+ `MariaDB user is a login account. Omit "login", or grant no privileges instead.`, errors_js_1.ERROR_CODES.UNSUPPORTED_ROLE_OPTION);
202
+ }
203
+ // A `postgresql` block here names an engine that will never run this
204
+ // role, so its memberships, connection cap and expiry would be dropped
205
+ // while the role provisioned as if they had been applied.
206
+ (0, database_options_js_1.assertNoForeignEngineOptions)({
207
+ roleName,
208
+ databaseName: dbName,
209
+ engineOptions: roleConfig?.engineOptions,
210
+ honoured: "mariadb",
211
+ engine: MARIADB_ENGINE_NAME,
212
+ });
213
+ const mariadbOptions = roleConfig?.engineOptions?.mariadb;
214
+ // Resolved once, here, and used for the registry claim, the naming
215
+ // identity, and `spec.host` alike. A configured `""` is not nullish, so it
216
+ // used to reach all three as itself while the CRs — which omitted a falsy
217
+ // host — inherited the operator's `%` default: a second database could
218
+ // then claim `reader`@`%` for what MariaDB sees as the same account. See
219
+ // {@link resolveMariadbHost}.
220
+ const host = (0, mariadb_common_js_1.resolveMariadbHost)(mariadbOptions?.host);
221
+ // Translated before the claim below, not where the CRs are built, because
222
+ // this throws: a privilege MariaDB cannot carry in a database-scoped
223
+ // GRANT is rejected here. Claiming first and translating afterwards left
224
+ // the account claimed for a role that was never provisioned, so a caller
225
+ // who fixed the privilege and retried in the same program run was refused
226
+ // as a duplicate.
227
+ //
228
+ // `grants: []` and an omitted `grants` both come to the same thing on
229
+ // MariaDB: no `Grant` CRs. Removing a grant from config deletes its CR and
230
+ // mariadb-operator issues the `REVOKE`, so the revoke semantics
231
+ // `grants: []` asks for are what the declarative path already gives.
232
+ const grants = (0, mariadb_roles_js_1.toMariadbGrants)(resolved.grants ?? []);
233
+ // Same hazard one scope wider: the check above only sees this database's
234
+ // own owner, while this `user`@`host` pair may already belong to a sibling
235
+ // database on the same instance — the same account, since MariaDB has only
236
+ // one. The registry is what notices. A different host is a different
237
+ // account, and stays allowed.
238
+ //
239
+ // Claimed after every rejecting guard, not before them, so a call they
240
+ // reject leaves no claim behind.
241
+ (0, mariadb_common_js_1.claimMariadbRoleName)(roleRegistry, roleName, host, dbName);
242
+ // Named for the `user`@`host` pair the claim above was made on, not for
243
+ // the username: the registry lets one username exist on two hosts because
244
+ // MariaDB does, and names derived from the username alone would then
245
+ // register the second account under the first's logical names.
246
+ const naming = (0, mariadb_roles_js_1.additionalRoleNaming)(clusterName, dbName, roleName, host);
247
+ const provisioned = (0, mariadb_roles_js_1.provisionMariadbRole)({
248
+ clusterName,
249
+ dbName,
250
+ roleName,
251
+ naming,
252
+ grants,
253
+ host,
254
+ maxUserConnections: mariadbOptions?.maxUserConnections,
255
+ labels,
256
+ mariadb,
257
+ database,
258
+ provider,
259
+ });
260
+ // The connection Secret waits on every Grant CR so a consumer cannot read
261
+ // working credentials, connect, and hit permission errors before the
262
+ // privileges have landed. A role with no grants waits on the User CR.
263
+ const roleSecrets = (0, mariadb_roles_js_1.replicateMariadbConnectionSecrets)({
264
+ naming,
265
+ namespaces: resolved.namespaces,
266
+ dbName,
267
+ username: roleName,
268
+ password: provisioned.credentials.stablePassword,
269
+ endpoint,
270
+ port,
271
+ labels,
272
+ provider,
273
+ dependsOn: provisioned.grants.length > 0 ? provisioned.grants : [database, provisioned.user],
274
+ });
275
+ return {
276
+ name: roleName,
277
+ databaseName: dbName,
278
+ clusterName,
279
+ secrets: roleSecrets,
280
+ nativeResource: provisioned.user,
281
+ };
282
+ },
283
+ };
284
+ }
285
+ //# sourceMappingURL=mariadb-database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mariadb-database.js","sourceRoot":"","sources":["../../../src/operator/mariadb-database.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FH,kFAsOC;AAnUD,wDAA0C;AAC1C,uDAAyC;AACzC,2DAO6B;AAC7B,yDAO4B;AAC5B,4DAIiC;AACjC,+DAAgG;AAChG,kDAAgE;AAShE,wEAAwE;AACxE,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AACxD,yCAAyC;AACzC,MAAM,g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AC,CAAC;YAEH,0EAA0E;YAC1E,qEAAqE;YACrE,sEAAsE;YACtE,MAAM,WAAW,GAAG,IAAA,oDAAiC,EAAC;gBACpD,MAAM;gBACN,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,MAAM;gBACN,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,WAAW,CAAC,WAAW,CAAC,cAAc;gBAChD,QAAQ;gBACR,IAAI;gBACJ,MAAM;gBACN,QAAQ;gBACR,SAAS,EACP,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC;aACpF,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,MAAM;gBACpB,WAAW;gBACX,OAAO,EAAE,WAAW;gBACpB,cAAc,EAAE,WAAW,CAAC,IAAI;aACjC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * MariaDB users inside a MariaDB Operator instance.
3
+ *
4
+ * Every user — the database owner created alongside the database, and every
5
+ * role added later via `addRole()` — is provisioned by the single function
6
+ * {@link provisionMariadbRole}. Unlike CloudNativePG, mariadb-operator models
7
+ * privileges declaratively with a `Grant` CRD, so no SQL Job is involved
8
+ * anywhere: an {@link IDatabaseGrant} maps directly onto a `Grant` custom
9
+ * resource and the operator reconciles it continuously.
10
+ *
11
+ * Only the names differ between the two paths, and those names are the one
12
+ * genuinely dangerous part: Pulumi identifies a resource by its logical name,
13
+ * so renaming one deletes and recreates it, and for a credential Secret that
14
+ * regenerates the password and breaks every application already using it.
15
+ * {@link ownerRoleNaming} therefore pins the owner's names to the exact strings
16
+ * live stacks already carry.
17
+ *
18
+ * @module operator/mariadb-roles
19
+ */
20
+ import * as k8s from "@pulumi/kubernetes";
21
+ import * as pulumi from "@pulumi/pulumi";
22
+ import { type IRoleCredentials } from "./credentials.js";
23
+ import type { IDatabaseGrant } from "./interfaces.js";
24
+ /** Pulumi logical and Kubernetes names for one `Grant` custom resource. */
25
+ export interface IMariadbGrantNaming {
26
+ /** Pulumi logical name of the `Grant` custom resource. */
27
+ readonly resource: string;
28
+ /** Kubernetes name of the `Grant` custom resource. */
29
+ readonly metadataName: string;
30
+ }
31
+ /**
32
+ * Every name — Pulumi logical and Kubernetes — used by one provisioned user.
33
+ *
34
+ * Collecting them in one place keeps the replace-on-rename risk reviewable
35
+ * instead of scattered through the provisioning code.
36
+ */
37
+ export interface IMariadbRoleNaming {
38
+ /** Pulumi logical name of the password Secret. */
39
+ readonly credentialResource: string;
40
+ /** Kubernetes name of the password Secret. */
41
+ readonly credentialSecret: string;
42
+ /** Pulumi logical name of the `User` custom resource. */
43
+ readonly userResource: string;
44
+ /** Kubernetes name of the `User` custom resource. */
45
+ readonly userMetadataName: string;
46
+ /** Pulumi logical name prefix of the replicated connection Secrets. */
47
+ readonly connectionResourcePrefix: string;
48
+ /** Kubernetes name of each replicated connection Secret. */
49
+ readonly connectionSecret: string;
50
+ /**
51
+ * Names for the `Grant` custom resource covering `table`.
52
+ *
53
+ * A user may hold any number of grants, so these cannot be plain fields.
54
+ * Keying on the table rather than the grant's position makes reordering a
55
+ * role's `grants` array a no-op and an edit to its privileges an in-place
56
+ * update; only changing the table forces a replace, which is the one case
57
+ * where a replace is correct. The owner holds exactly one grant and ignores
58
+ * the argument entirely, which is how its pre-existing unsuffixed name
59
+ * survives.
60
+ *
61
+ * The key must be injective over table names for the same reason a role's
62
+ * name must be: two Grant CRs deriving one logical name abort the preview
63
+ * with a duplicate URN. See {@link toIdentitySegment}.
64
+ *
65
+ * @param table - The grant's `spec.table`, `"*"` for the whole database
66
+ * @returns The grant's Pulumi logical and Kubernetes names
67
+ */
68
+ grantNaming(table: string): IMariadbGrantNaming;
69
+ }
70
+ /**
71
+ * Names for the database owner's user.
72
+ *
73
+ * These strings predate the shared provisioner and are reproduced verbatim:
74
+ * `-password-secret`, `-user`, `-grant`, and `-secret-{namespace}` are the
75
+ * logical names live stacks already carry, and `metadata.name` is the
76
+ * unsanitized `{cluster}-{database}` those objects were created under. Do not
77
+ * "tidy" them.
78
+ *
79
+ * @param clusterName - MariaDB instance name
80
+ * @param dbName - Database name
81
+ * @returns The owner user's pinned naming
82
+ */
83
+ export declare function ownerRoleNaming(clusterName: string, dbName: string): IMariadbRoleNaming;
84
+ /**
85
+ * Names for a user added via `addRole()`.
86
+ *
87
+ * Every name is prefixed `{cluster}-{database}-role-{role}` so it can never
88
+ * collide with the owner's pinned names above — the owner's names have no
89
+ * `-role-` segment following `{cluster}-{database}`.
90
+ *
91
+ * Grants are named for the table they cover (`*` renders as `all`), never for
92
+ * their position, so reordering a role's `grants` array changes nothing.
93
+ *
94
+ * **The identity is the `username`@`host` pair, not the username.** MariaDB
95
+ * treats those two together as one account, which is why the role registry
96
+ * permits `reader`@`%` and `reader`@`10.0.0.1` to coexist — and a name derived
97
+ * from the username alone made the second of them register under the first's
98
+ * logical names, aborting the preview with a duplicate URN so that the account
99
+ * the registry had just allowed could never actually be created. Folding the
100
+ * host in also keeps a host *change* honest: it derives new names rather than
101
+ * attempting an in-place update of `spec.host`, which mariadb-operator treats as
102
+ * immutable.
103
+ *
104
+ * The role segment comes from {@link toCompositeIdentitySegment}, not from plain
105
+ * sanitizing: `Read_Only` and `read_only` are two distinct, simultaneously valid
106
+ * MariaDB usernames that sanitize alike, and two resources deriving one logical
107
+ * name abort the entire preview with a duplicate-URN error. Every segment
108
+ * carries the hash, including names that needed no sanitizing, so no raw name
109
+ * can land on another's encoded form.
110
+ *
111
+ * Every name is then bounded by {@link toBoundedName}: instance, database, role
112
+ * and table names are all caller-controlled and unbounded, and a `metadata.name`
113
+ * over {@link DNS_1123_SUBDOMAIN_MAX_LENGTH} is rejected by the Kubernetes API
114
+ * at apply time — after preview has passed, so the CRs the account needs are
115
+ * never created. Nothing here names a Job, so the stricter 63-character label
116
+ * limit does not apply and ordinary names keep their readable form.
117
+ *
118
+ * @param clusterName - MariaDB instance name
119
+ * @param dbName - Database name
120
+ * @param roleName - Role name as it exists in MariaDB
121
+ * @param host - Effective host pattern, as returned by `resolveMariadbHost`
122
+ * @returns Naming for the additional user's resources, each within the DNS-1123
123
+ * subdomain limit
124
+ */
125
+ export declare function additionalRoleNaming(clusterName: string, dbName: string, roleName: string, host: string): IMariadbRoleNaming;
126
+ /** One privilege grant expressed in mariadb-operator's own terms. */
127
+ export interface IMariadbGrantSpec {
128
+ /** Privileges granted, upper-cased as MariaDB spells them. */
129
+ readonly privileges: ReadonlyArray<string>;
130
+ /** Table the grant is scoped to, or `"*"` for every table in the database. */
131
+ readonly table: string;
132
+ /** Whether the grantee may pass these privileges on to others. */
133
+ readonly grantOption: boolean;
134
+ }
135
+ /** The database owner's grant: everything on the database, with `GRANT OPTION`. */
136
+ export declare const OWNER_GRANT: IMariadbGrantSpec;
137
+ /**
138
+ * Translate portable grants into mariadb-operator `Grant` specs, one per table.
139
+ *
140
+ * `IDatabaseGrant.schema` has no MariaDB equivalent and is dropped — MariaDB
141
+ * has no schema concept distinct from the database itself. `objects` is either
142
+ * a single table name or `"all"`, which becomes `"*"`.
143
+ *
144
+ * **Grants are merged by table.** A role may legitimately express two grants for
145
+ * one table — separate `SELECT` and `INSERT` entries, say — but
146
+ * {@link IMariadbRoleNaming.grantNaming} keys a `Grant` CR's logical name on the
147
+ * table, so rendering both would register two resources under one name and abort
148
+ * the preview with a duplicate-URN error instead of provisioning anything. Their
149
+ * privileges are unioned into a single CR, which is also what the caller meant.
150
+ *
151
+ * The result is canonical: privileges are deduplicated after normalization and
152
+ * sorted, and tables are sorted, so reordering the input array produces byte-
153
+ * identical output and no Pulumi diff. `ALL PRIVILEGES` absorbs everything it is
154
+ * merged with — MariaDB's `GRANT` grammar rejects it alongside other privileges,
155
+ * so a union that keeps both would only render invalid SQL.
156
+ *
157
+ * @param grants - Portable grants from the role configuration
158
+ * @returns One MariaDB grant spec per distinct table, ordered by table name
159
+ * @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a grant names a
160
+ * privilege outside {@link ALLOWED_PRIVILEGES}
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * toMariadbGrants([
165
+ * { privileges: ["SELECT"], objects: "orders" },
166
+ * { privileges: ["INSERT"], objects: "orders" },
167
+ * ]);
168
+ * // → [{ privileges: ["INSERT", "SELECT"], table: "orders", grantOption: false }]
169
+ * ```
170
+ */
171
+ export declare function toMariadbGrants(grants: ReadonlyArray<IDatabaseGrant>): ReadonlyArray<IMariadbGrantSpec>;
172
+ /** Inputs for {@link provisionMariadbRole}. */
173
+ export interface IMariadbRoleOptions {
174
+ /** MariaDB instance the user belongs to. */
175
+ readonly clusterName: string;
176
+ /** Database the grants are scoped to. */
177
+ readonly dbName: string;
178
+ /** Username as it will exist in MariaDB, passed through verbatim. */
179
+ readonly roleName: string;
180
+ /** Pinned Pulumi and Kubernetes names for this user's resources. */
181
+ readonly naming: IMariadbRoleNaming;
182
+ /** Grants to create, already translated by {@link toMariadbGrants}. */
183
+ readonly grants: ReadonlyArray<IMariadbGrantSpec>;
184
+ /**
185
+ * Effective host pattern the user may connect from.
186
+ *
187
+ * Written to both CRs exactly as given, or omitted from both when undefined —
188
+ * which is how the owner's pre-existing specs stay byte-identical rather than
189
+ * gaining an explicit copy of the operator's own default.
190
+ *
191
+ * Callers pass the *resolved* value, never the raw configuration: see
192
+ * {@link resolveMariadbHost}. Omitting a blank host instead of writing it
193
+ * would silently hand the account the operator's default while the registry
194
+ * and the resource names identified it by the blank value, so a blank string
195
+ * is deliberately not treated as "unset" here.
196
+ */
197
+ readonly host?: string;
198
+ /** Concurrent connection cap. Default: {@link DEFAULT_MAX_USER_CONNECTIONS}. */
199
+ readonly maxUserConnections?: number;
200
+ /** Labels applied to every created object. */
201
+ readonly labels: Record<string, string>;
202
+ /** The `MariaDB` CR the user is created on. */
203
+ readonly mariadb: k8s.apiextensions.CustomResource;
204
+ /** The `Database` CR the grants are scoped to. */
205
+ readonly database: k8s.apiextensions.CustomResource;
206
+ /** Kubernetes provider. */
207
+ readonly provider: k8s.Provider;
208
+ }
209
+ /** A provisioned user, its grants, and the credentials backing it. */
210
+ export interface IMariadbProvisionedRole {
211
+ /** The `User` custom resource. */
212
+ readonly user: k8s.apiextensions.CustomResource;
213
+ /** One `Grant` custom resource per requested grant, in the order supplied. */
214
+ readonly grants: ReadonlyArray<k8s.apiextensions.CustomResource>;
215
+ /** The user's password Secret and its stable password. */
216
+ readonly credentials: IRoleCredentials;
217
+ }
218
+ /**
219
+ * Provision one MariaDB user: a password Secret, the `User` CR that reconciles
220
+ * the account, and one `Grant` CR per requested privilege set.
221
+ *
222
+ * The Secret holds only `password` — the `User` CR names the account itself, so
223
+ * a `username` key would be redundant, and adding one would change the schema
224
+ * of a Secret live applications already read.
225
+ *
226
+ * @param options - Instance, username, pinned naming, and translated grants
227
+ * @returns The `User` CR, its `Grant` CRs, and the credentials it authenticates with
228
+ */
229
+ export declare function provisionMariadbRole(options: IMariadbRoleOptions): IMariadbProvisionedRole;
230
+ /** Inputs for {@link replicateMariadbConnectionSecrets}. */
231
+ export interface IMariadbConnectionSecretOptions {
232
+ /** Pinned naming for the user whose credentials are replicated. */
233
+ readonly naming: IMariadbRoleNaming;
234
+ /** Namespaces to replicate into. */
235
+ readonly namespaces: ReadonlyArray<string>;
236
+ /** Database the connection points at. */
237
+ readonly dbName: string;
238
+ /** User the connection authenticates as. */
239
+ readonly username: string;
240
+ /** The user's password, read back from its Secret. */
241
+ readonly password: pulumi.Output<string>;
242
+ /** Instance endpoint. */
243
+ readonly endpoint: pulumi.Output<string>;
244
+ /** Instance port. */
245
+ readonly port: pulumi.Output<number>;
246
+ /** Labels applied to each Secret. */
247
+ readonly labels: Record<string, string>;
248
+ /** Kubernetes provider. */
249
+ readonly provider: k8s.Provider;
250
+ /** Resources each Secret must be created after. */
251
+ readonly dependsOn: ReadonlyArray<pulumi.Resource>;
252
+ }
253
+ /**
254
+ * Replicate a user's connection details into each consuming namespace.
255
+ *
256
+ * The `username`, `password` and `database` keys carry raw values; only the
257
+ * composed `uri` percent-encodes them, because there a `@` or `:` in a username
258
+ * would otherwise be read as a URI delimiter. See {@link encodeUriComponentValue}.
259
+ *
260
+ * @param options - Naming, namespaces, connection details, and dependencies
261
+ * @returns Map of namespace → created Secret name
262
+ */
263
+ export declare function replicateMariadbConnectionSecrets(options: IMariadbConnectionSecretOptions): Record<string, pulumi.Output<string>>;
264
+ //# sourceMappingURL=mariadb-roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mariadb-roles.d.ts","sourceRoot":"","sources":["../../../src/operator/mariadb-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAYzC,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAOtD,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IAClD,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,8CAA8C;IAC9C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,yDAAyD;IACzD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,uEAAuE;IACvE,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,4DAA4D;I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