feat(cryptpad): Refactor installer configuration logic
Refactors the CryptPad installer to improve its configuration handling. - The `hostname` and `namespace` are now derived from the installer's `name` property by default. - Implemented name sanitization to remove special characters (`_`, `-`, `.`). - Added validation to ensure the namespace does not contain invalid characters. - Updated the factory's `reload` function to persist changes made to the installer object after its initial creation. This change ensures consistent and predictable behavior, allowing for both default generation and manual override of configuration values. Co-authored-by: Mahmoud-Emad <mahmmoud.hassanein@gmail.com>
This commit is contained in:
@@ -11,9 +11,10 @@ mut installer := cryptpad.get(
|
||||
create: true
|
||||
)!
|
||||
|
||||
// cryptpad.delete()!
|
||||
// 2. Configure the installer (all settings are optional with sensible defaults)
|
||||
installer.hostname = 'mycryptpad'
|
||||
installer.namespace = 'cryptpad'
|
||||
// installer.hostname = 'mycryptpad'
|
||||
// installer.namespace = 'cryptpad'
|
||||
|
||||
// 3. Install CryptPad.
|
||||
// This will generate the necessary Kubernetes YAML files and apply them to your cluster.
|
||||
|
||||
@@ -165,8 +165,8 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self CryptpadServer) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
set(self)!
|
||||
}
|
||||
|
||||
@[params]
|
||||
|
||||
@@ -34,12 +34,26 @@ pub mut:
|
||||
fn obj_init(mycfg_ CryptpadServer) !CryptpadServer {
|
||||
mut mycfg := mycfg_
|
||||
|
||||
if mycfg.name == '' {
|
||||
mycfg.name = 'cryptpad'
|
||||
}
|
||||
|
||||
// Replace the dashes, dots, and underscores with nothing
|
||||
mycfg.name = mycfg.name.replace('_', '')
|
||||
mycfg.name = mycfg.name.replace('-', '')
|
||||
mycfg.name = mycfg.name.replace('.', '')
|
||||
|
||||
if mycfg.namespace == '' {
|
||||
mycfg.namespace = mycfg.name
|
||||
mycfg.namespace = '${mycfg.name}-cryptpad-namespace'
|
||||
}
|
||||
|
||||
if mycfg.namespace.contains('_') || mycfg.namespace.contains('.') {
|
||||
console.print_stderr('namespace cannot contain _, was: ${mycfg.namespace}, use dashes instead.')
|
||||
return error('namespace cannot contain _, was: ${mycfg.namespace}')
|
||||
}
|
||||
|
||||
if mycfg.hostname == '' {
|
||||
mycfg.hostname = mycfg.name
|
||||
mycfg.hostname = '${mycfg.name}cryptpad'
|
||||
}
|
||||
|
||||
mycfg.kube_client = kubernetes.get(create: true)!
|
||||
|
||||
Reference in New Issue
Block a user