Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixing new bucket feature #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .commitlintrc.yml
100644 → 100755
Empty file.
Empty file modified .editorconfig
100644 → 100755
Empty file.
19 changes: 6 additions & 13 deletions .eslintignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

__mocks__
infrastructure/overwrite
newrelic.js
__test__
*.NOTE.*
*.js
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
build
cli/*
# don't lint nyc coverage output
coverage
40 changes: 0 additions & 40 deletions .eslintrc

This file was deleted.

28 changes: 28 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: false,
},
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["plugin:prettier/recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:import/errors", "plugin:import/warnings", "plugin:import/typescript"],
rules: {
"import/order": 1,
"import/no-commonjs": 1,
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts"],
},
"import/resolver": {
typescript: {
alwaysTryTypes: true,
},
},
},
};
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .npmrc
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions .prettierrc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"trailingComma": "es5",
"printWidth": 200,
"printWidth": 180,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
}
21 changes: 21 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Template for Analysis
> Rewrite that document, it's an example.

### how to run?
```bash
$ npm start
$ npm run inspect
$ nodemon # if you have nodemon installed, no params, just nodemon.
```

### how to test?
```bash
$ npm test
$ npm run test:watch
$ npm run test:coverage # Generate code test coverage report
```

### how to build?
```bash
$ npm run build
```
5 changes: 5 additions & 0 deletions __tests__/generictest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/lib/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/services/access/checkType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/services/access/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/services/customer/checkType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/services/customer/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/services/device/checkType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/services/device/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("test", () => {
test("generic", () => {
expect(true).toBe(true);
});
});
28 changes: 28 additions & 0 deletions export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Exporting Application
In order to export the application, you need to first make sure that all your entities:
* Devices
* Analysis
* Actions
* Access Management Rules

Has the tag **export_id** with a unique value on it.
Only entities with the export_id tag will be exported to the new profile. This is not applicable for Dictionaries and Run Buttons, as all of them will be exported.

## Warning
* Be careful with clean.ts ```bash $ npm run clean ``` will clean up the configured import token profile.
* Email templates are not exported.


### config.ts file
Edit the config.ts file to setup the export rules.

You will get the token from https://admin.tago.io/account for each profile.
* Make sure the token used is set with **Expire In** to never.
* Make sure the token from the exported application is the same as the ones from the Analysis, as it will be replaced by the token for the import profile.


### how to run?
```bash
$ npm run export
```

8 changes: 4 additions & 4 deletions src/clean.ts → export/clean.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Account } from "@tago-io/sdk";
import config from "./config";
import { EntityType } from "./exportTypes";

const IMPORT_ORDER: EntityType = ["devices", "dictionaries", "accessManagement", "run_buttons", "analysis", "actions", "dictionaries"];
const IMPORT_ORDER: EntityType = ["devices", "dashboards", "accessManagement", "run_buttons", "analysis", "actions", "dictionaries"];
// const IMPORT_ORDER: EntityType = ["devices", "accessManagement", "analysis", "actions", "dictionaries"];

async function startImport() {
const import_account = new Account({ token: config.import.token });
Expand All @@ -14,11 +15,10 @@ async function startImport() {
switch (item) {
case "devices":
console.info("Cleaning Devices");
const device_list = await import_account.devices.list({ amount: 999, fields: ["id", "bucket"] });
const device_list = await import_account.devices.list({ amount: 999, fields: ["id"] });
await Promise.all(device_list.map(({ id }) => import_account.devices.delete(id)));
await Promise.all(device_list.map(({ bucket }) => import_account.buckets.delete(bucket)));
break;
case "dictionaries":
case "dashboards":
console.info("Cleaning Dashboards");
const dash_list = await import_account.dashboards.list({ amount: 999, fields: ["id"] });
await Promise.all(dash_list.map(({ id }) => import_account.dashboards.delete(id)));
Expand Down
10 changes: 4 additions & 6 deletions src/config.ts → export/config.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { IExport } from "./exportTypes";

const config: IExport = {
// Export tag with unique ID's. Without tag bellow, entity will not be copied or updated.
export_tag: "export_id",
//to run: ts-node export/start.ts

const config: IExport = {
// Entities that will be copied from the application.
// entities: ["dictionaries"],
entities: ["devices", "analysis", "dashboards", "accessManagement", "run_buttons", "actions", "dictionaries"],
entities: ["devices", "dashboards", "analysis", "accessManagement", "actions", "run_buttons", "dictionaries"],
// entities: ["accessManagement"],
// data: ["list_devtype_id"],

Expand All @@ -21,7 +19,7 @@ const config: IExport = {
// token: "683d440e-4bf4-4950-aa60-3be553964fd9", // Sales
// token: "b8e6bd99-ca5d-48c3-90cc-7ec37608ea1b", // prod
// token: "5c0aab39-27cf-4a51-8094-cc0555eaa50b", // X-Talia
token: "7ec20119-e7e4-4605-a913-51c74dd78614", // X-Talia
token: "5e22b8ec-e65c-474f-bc7f-d6d1a0f307b6", // X-Talia
},
};

Expand Down
2 changes: 0 additions & 2 deletions src/exportTypes.ts → export/exportTypes.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ interface IExportHolder {
type Entity = "dashboards" | "devices" | "analysis";
type EntityType = Array<"dashboards" | "devices" | "run_buttons" | "analysis" | "actions" | "dictionaries" | "accessManagement">;
interface IExport {
export_tag: string;
entities: EntityType;
dictionary?: string[];
data?: string[],
export: {
token: string;
};
Expand Down
4 changes: 1 addition & 3 deletions src/lib/filterExport.ts → export/lib/filterExport.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { TagsObj } from "@tago-io/sdk/out/common/common.types";
function filterExport(dashboard: { [key: string]: any }) {
const export_tag = dashboard.tags.find((tag: TagsObj) => tag.key === "export_id");

if (!export_tag) {
return false;
}
if (!export_tag) return false;
return true;
}

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/services/accessExport.ts → export/services/accessExport.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Account } from "@tago-io/sdk";
import { IExportHolder } from "../exportTypes";
import filterExport from "../lib/filterExport";
import replaceObj from "../lib/replaceObj";

async function accessExport(account: Account, import_account: Account, export_holder: IExportHolder) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/services/analysisExport.ts → export/services/analysisExport.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function analysisExport(account: Account, import_account: Account, export_
const import_list = await import_account.analysis.list({ amount: 99, fields: ["id", "tags"], filter: { tags: [{ key: "export_id" }] } });

for (const { id: analysis_id, name } of list) {
console.info(`Exporting dashboard ${name}...`);
console.info(`Exporting analysis ${name}...`);
const analysis = await account.analysis.info(analysis_id);
const export_id = analysis.tags.find((tag) => tag.key === "export_id")?.value;

Expand Down
22 changes: 4 additions & 18 deletions src/services/collectIDs.ts → export/services/collectIDs.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,18 @@ import { Account, Utils } from "@tago-io/sdk";
import { Entity, EntityType, IExportHolder } from "../exportTypes";

async function collectIDs(account: Account, import_account: Account, entity: Entity, export_holder: IExportHolder) {
const list = await account[entity].list({
page: 1,
amount: 99,
fields: ["id", "tags"] as any,
filter: { tags: [{ key: "export_id" }] },
});
const import_list = await import_account[entity].list({
page: 1,
amount: 99,
fields: ["id", "tags"] as any,
filter: { tags: [{ key: "export_id" }] },
});
const list = await account[entity].list({ page: 1, amount: 99, fields: ["id", "tags"] as any, filter: { tags: [{ key: "export_id" }] } });
const import_list = await import_account[entity].list({ page: 1, amount: 99, fields: ["id", "tags"] as any, filter: { tags: [{ key: "export_id" }] } });

for (const item of list) {
const export_id = item.tags.find((tag) => tag.key === "export_id")?.value;
if (!export_id) {
continue;
}
if (!export_id) continue;

const { id: target_id } = (import_list as any).find((a: any) => a.tags.find((tag: any) => tag.key === "export_id" && tag.value == export_id)) || {
id: null,
};

if (!target_id) {
continue;
}
if (!target_id) continue;

if (entity === "devices") {
const token = await Utils.getTokenByName(account, item.id);
Expand Down
File renamed without changes.
Loading