2025-01-20 02:11:12 +01:00
|
|
|
import * as plugins from './plugins.js';
|
2025-09-10 19:06:16 +00:00
|
|
|
import { CliClient } from './classes.cliclient.js';
|
2025-01-20 02:11:12 +01:00
|
|
|
|
2025-01-02 03:58:09 +01:00
|
|
|
export const runCli = async () => {
|
2025-01-20 02:11:12 +01:00
|
|
|
const cliQenv = new plugins.qenv.Qenv();
|
2025-09-10 19:06:16 +00:00
|
|
|
const cloudlyUrl = await cliQenv.getEnvVarOnDemand('CLOUDLY_URL');
|
|
|
|
const token = process.env.CLOUDLY_TOKEN;
|
|
|
|
const username = process.env.CLOUDLY_USERNAME;
|
|
|
|
const password = process.env.CLOUDLY_PASSWORD;
|
|
|
|
|
2025-01-20 02:11:12 +01:00
|
|
|
const apiClient = new plugins.servezoneApi.CloudlyApiClient({
|
|
|
|
registerAs: 'cli',
|
2025-09-10 19:06:16 +00:00
|
|
|
cloudlyUrl,
|
2025-01-20 02:11:12 +01:00
|
|
|
});
|
2025-09-10 19:06:16 +00:00
|
|
|
await apiClient.start();
|
|
|
|
|
|
|
|
if (token) {
|
|
|
|
await apiClient.getIdentityByToken(token, { tagConnection: true, statefullIdentity: true });
|
|
|
|
} else if (username && password) {
|
|
|
|
await apiClient.loginWithUsernameAndPassword(username, password);
|
|
|
|
} else {
|
|
|
|
console.log('No credentials provided. Set CLOUDLY_TOKEN or CLOUDLY_USERNAME/CLOUDLY_PASSWORD.');
|
|
|
|
}
|
|
|
|
|
2025-01-20 02:11:12 +01:00
|
|
|
const cliClient = new CliClient(apiClient);
|
2025-09-10 19:06:16 +00:00
|
|
|
// Default action example: list clusters when invoked without subcommands
|
|
|
|
await cliClient.getClusters();
|
|
|
|
};
|