This repository is currently being migrated. It's locked while the migration is in progress.
forked from shughes-uk/resume
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
70 lines (63 loc) · 1.98 KB
/
fetch.js
File metadata and controls
70 lines (63 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const { Pool } = require("pg");
const pool = new Pool({
host: process.env.CUBEJS_DB_HOST,
port: process.env.CUBEJS_DB_PORT,
user: process.env.CUBEJS_DB_USER,
password: process.env.CUBEJS_DB_PASS,
database: process.env.CUBEJS_DB_NAME,
ssl: {
rejectUnauthorized: false // Heroku requires SSL but with this flag off
},
});
const tenantIdClaim = "https://synccomputing.com/sync_tenant_id";
exports.fetchUniqueTagKeys = async (sync_tenant_id) => {
let client;
let tagKeys = [];
try {
console.log("looking up tags for: ", sync_tenant_id);
client = await pool.connect();
const uniqueTagKeysQuery = `
SELECT DISTINCT tag_key
FROM public.databricks_cluster_tags
WHERE sync_tenant_id = '${sync_tenant_id}'
`;
const result = await client.query(uniqueTagKeysQuery);
// remove special characters from the tag key name so we can expose as a dimension
tagKeys = result.rows.map((row) => row.tag_key.replace(/[^a-zA-Z0-9_]/g, '_'));
} catch(error) {
console.error(error)
} finally {
if (client) {
client.release();
}
}
return tagKeys;
};
exports.fetchUniqueTenants = async () => {
console.log("trying to fetch unique tenants")
let client;
let uniqueTenants = [];
try {
client = await pool.connect();
const uniqueTenantsQuery = `
SELECT DISTINCT sync_tenant_id
FROM public.user
WHERE sync_tenant_id IS NOT NULL and last_login > NOW() - INTERVAL '30 days';
`;
const result = await client.query(uniqueTenantsQuery);
console.log(result);
uniqueTenants = result.rows.map((row) => {
const secContext = { "securityContext": {}};
secContext["securityContext"][tenantIdClaim] = row.sync_tenant_id;
return secContext;
});
} catch(error) {
console.error('Error fetching unique tenants:', error);
} finally {
if (client) {
client.release();
}
}
console.log("Found tenants: " + uniqueTenants)
return uniqueTenants
}