feat(hostedapp): add hosted app lifecycle protocol support
This commit is contained in:
@@ -113,19 +113,28 @@ export class CloudlyAuthManager {
|
||||
}
|
||||
|
||||
const adminAccount = this.cloudlyRef.config.data.servezoneAdminaccount;
|
||||
if (!adminAccount) {
|
||||
throw new Error('SERVEZONE_ADMINACCOUNT is required for first-run Cloudly bootstrap');
|
||||
}
|
||||
let username: string;
|
||||
let password: string;
|
||||
let hostedBootstrapActionId: string | undefined;
|
||||
if (adminAccount) {
|
||||
const separatorIndex = adminAccount.indexOf(':');
|
||||
if (separatorIndex <= 0 || separatorIndex === adminAccount.length - 1) {
|
||||
throw new Error('SERVEZONE_ADMINACCOUNT must use username:password format');
|
||||
}
|
||||
|
||||
const separatorIndex = adminAccount.indexOf(':');
|
||||
if (separatorIndex <= 0 || separatorIndex === adminAccount.length - 1) {
|
||||
throw new Error('SERVEZONE_ADMINACCOUNT must use username:password format');
|
||||
}
|
||||
|
||||
const username = adminAccount.slice(0, separatorIndex).trim();
|
||||
const password = adminAccount.slice(separatorIndex + 1);
|
||||
if (!username || !password) {
|
||||
throw new Error('SERVEZONE_ADMINACCOUNT must include a non-empty username and password');
|
||||
username = adminAccount.slice(0, separatorIndex).trim();
|
||||
password = adminAccount.slice(separatorIndex + 1);
|
||||
if (!username || !password) {
|
||||
throw new Error('SERVEZONE_ADMINACCOUNT must include a non-empty username and password');
|
||||
}
|
||||
} else {
|
||||
const hostedBootstrap = await this.cloudlyRef.hostedAppManager.requestParentInitialAdminBootstrap();
|
||||
if (!hostedBootstrap) {
|
||||
throw new Error('SERVEZONE_ADMINACCOUNT is required for first-run Cloudly bootstrap unless hosted app lifecycle credentials are available');
|
||||
}
|
||||
username = hostedBootstrap.username;
|
||||
password = hostedBootstrap.password;
|
||||
hostedBootstrapActionId = hostedBootstrap.actionId;
|
||||
}
|
||||
|
||||
const user = new this.CUser({
|
||||
@@ -139,6 +148,14 @@ export class CloudlyAuthManager {
|
||||
});
|
||||
await user.save();
|
||||
logger.log('success', `created initial admin user ${username}`);
|
||||
if (hostedBootstrapActionId) {
|
||||
await this.cloudlyRef.hostedAppManager.completeParentBootstrapAction(
|
||||
hostedBootstrapActionId,
|
||||
'Cloudly created the initial admin user.',
|
||||
).catch((errorArg) => {
|
||||
logger.log('warn', `failed to complete hosted app bootstrap action: ${(errorArg as Error).message}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async stop() {}
|
||||
|
||||
Reference in New Issue
Block a user