Skip to content

Commit

Permalink
Fixes: updates the region parameter when using TagoDeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuscardosodeveloper committed Aug 23, 2024
1 parent 3ffb7f3 commit 1567abe
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/commands/analysis/analysis-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function connectAnalysisConsole(scriptName: string | void, options: { envi
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const analysis_info = await account.analysis.info(scriptObj.id);
if (!analysis_info) {
errorHandler(`Analysis with ID: ${scriptObj.id} couldn't be found.`);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/analysis/analysis-set-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function analysisSetMode(userInputName: string | void, options: { environm
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const analysisFilterName = userInputName ? `*${userInputName}*` : undefined;

// Get analysis list from TagoIO
Expand Down
2 changes: 1 addition & 1 deletion src/commands/analysis/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function deployAnalysis(cmdScriptName: string, options: { environment: str
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
for (const { id, fileName } of scriptList) {
await buildScript(account, fileName, id, config);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/analysis/run-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function runAnalysis(scriptName: string | undefined, options: { environmen
return process.exit();
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });

let { token: analysisToken, run_on, name } = await account.analysis.info(scriptToRun.id);
successMSG(`> Analysis found: ${highlightMSG(scriptToRun.fileName)} (${name}}) [${highlightMSG(analysisToken)}].`);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/analysis/trigger-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function triggerAnalysis(scriptName: string | void, options: { environment
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const analysisList = config.analysisList.filter((x) => x.fileName);

let script: IEnvironment["analysisList"][0] | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dashboard/copy-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function copyTabWidgets(dashID: string, options: IOptions) {
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
if (!dashID) {
dashID = await pickDashboardIDFromTagoIO(account);
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/devices/change-bucket-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface BucketSettings {
const coloredBucketType = (type: string) => (type === "mutable" ? kleur.green(type) : type === "legacy" ? kleur.red(type) : kleur.blue(type));

async function convertDevice(deviceID: string, settings: BucketSettings, profileToken: string) {
const account = new Account({ token: profileToken, region: "usa-1" });
const account = new Account({ token: profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const deviceInfo = await account.devices.info(deviceID);
const bucketType = deviceInfo.type;

Expand Down Expand Up @@ -81,7 +81,7 @@ async function changeBucketType(id: string, options: { environment: string }) {
errorHandler("Environment not found");
return;
}
const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const bucketList = id ? [id] : await chooseBucketsFromList(account);
if (id) {
const bucketInfo = await account.buckets.info(id);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/devices/copy-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ async function copyDeviceData(options: IOptions) {
}

if (!options.from || !options.to) {
const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
options.from = await pickDeviceIDFromTagoIO(account, "Choose a device to copy the data from:");
options.to = await pickDeviceIDFromTagoIO(account, "Choose a device to copy the data to: ");
}

let deviceFrom: Device | undefined;
let deviceTo: Device | undefined;
if (options.from?.length === 24 || options.to?.length === 24) {
const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });

if (options.from.length === 24) {
deviceFrom = await Utils.getDevice(account, options.from);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/devices/data-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function getDeviceData(idOrToken: string, options: IOptions) {
errorHandler("Environment not found");
return;
}
const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
if (!idOrToken) {
idOrToken = await pickDeviceIDFromTagoIO(account);
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/devices/data-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ async function postDeviceData(idOrToken: string, options: IOptions) {
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
if (!idOrToken) {
idOrToken = await pickDeviceIDFromTagoIO(account);
}
const deviceInfo = await account.devices
.info(idOrToken)
.catch(() => {
const device = new Device({ token: idOrToken, region: "usa-1" });
const device = new Device({ token: idOrToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
return device.info();
})
.catch(errorHandler);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/devices/device-bkp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ async function bkpDeviceData(idOrToken: string, options: IOptions) {
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
if (!idOrToken) {
idOrToken = await pickDeviceIDFromTagoIO(account);
}

const deviceInfo = await account.devices
.info(idOrToken)
.catch(() => {
const device = new Device({ token: idOrToken, region: "usa-1" });
const device = new Device({ token: idOrToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
return device.info();
})
.catch(errorHandler);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/devices/device-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function deviceInfo(idOrToken: string, options: { environment: string; raw
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
if (!idOrToken) {
idOrToken = await pickDeviceIDFromTagoIO(account);
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/devices/device-live-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ async function inspectorConnection(deviceIdOrToken: string, options: IOptions) {
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
if (!deviceIdOrToken) {
deviceIdOrToken = await pickDeviceIDFromTagoIO(account);
}

let deviceInfo = await account.devices.info(deviceIdOrToken).catch(() => null);
if (!deviceInfo) {
const device = new Device({ token: deviceIdOrToken, region: "usa-1" });
const device = new Device({ token: deviceIdOrToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
deviceInfo = await device
.info()
.then((r) => r as DeviceInfo)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/profile/export/export-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function setupExport(options: { setup: string }) {
return;
}

const account = new Account({ token: config.profileToken, region: "usa-1" });
const account = new Account({ token: config.profileToken, region: !process.env.TAGOIO_API ? "usa-1" : "env" });

const exportTag = await enterExportTag("export_id");
const entities = await chooseEntities([], ["dictionaries", "run"]);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/profile/export/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ async function enterExportTag(defaultTag: string) {
}

async function confirmEnvironments(userConfig: IExport) {
const exportAcc = new Account({ token: userConfig.export.token, region: "usa-1" });
const importAcc = new Account({ token: userConfig.import.token, region: "usa-1" });
const exportAcc = new Account({ token: userConfig.export.token, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const importAcc = new Account({ token: userConfig.import.token, region: !process.env.TAGOIO_API ? "usa-1" : "env" });

const errorWhenReading = (error: any, type: string) => {
errorHandler(`${type} profile: ${error}`);
Expand Down Expand Up @@ -163,8 +163,8 @@ async function startExport(options: IExportOptions) {
return;
}

const account = new Account({ token: userConfig.export.token, region: "usa-1" });
const import_account = new Account({ token: userConfig.import.token, region: "usa-1" });
const account = new Account({ token: userConfig.export.token, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const import_account = new Account({ token: userConfig.import.token, region: !process.env.TAGOIO_API ? "usa-1" : "env" });

const import_rule = ENTITY_ORDER.filter((entity) => userConfig.entities.includes(entity));
let export_holder: IExportHolder = {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/profile/export/services/devices-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function deviceExport(account: Account, import_account: Account, export_ho
({ device_id: target_id, token: new_token } = await import_account.devices.create(new_device));

if (config.data && config.data.length > 0) {
const device = new Device({ token: new_token, region: "usa-1" });
const device = new Device({ token: new_token, region: !process.env.TAGOIO_API ? "usa-1" : "env" });
const old_device = new Device({ token });

const data = await old_device.getData({
Expand Down

0 comments on commit 1567abe

Please sign in to comment.