-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcontainers.js
92 lines (81 loc) · 2.54 KB
/
containers.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// @ts-check
import * as base from '../utils/base.js'
export const command = 'containers [containerGroup] [container]'
export const aliases = ['cont', 'listContainers', 'listcontainers']
export const describe = base.bundle.getText("containers")
export const builder = base.getBuilder({
container: {
alias: ['c', 'Container'],
type: 'string',
default: "*",
desc: base.bundle.getText("container")
},
containerGroup: {
alias: ['g', 'Group', 'group', 'containergroup'],
type: 'string',
default: '*',
desc: base.bundle.getText("containerGroup")
},
limit: {
alias: ['l'],
type: 'number',
default: 200,
desc: base.bundle.getText("limit")
}
})
export let inputPrompts = {
container: {
description: base.bundle.getText("container"),
type: 'string',
required: true
},
containerGroup: {
description: base.bundle.getText("containerGroup"),
type: 'string',
required: true
},
limit: {
description: base.bundle.getText("limit"),
type: 'number',
required: true
}
}
export function handler(argv) {
base.promptHandler(argv, getContainers, inputPrompts)
}
export async function getContainers(prompts) {
base.debug('getContainers')
try {
base.setPrompts(prompts)
const db = await base.createDBConnection()
base.debug(`${base.bundle.getText("containerGroup")}: ${prompts.containerGroup}, ${base.bundle.getText("container")}: ${prompts.container}`)
let results = await getContainersInt(prompts.containerGroup, prompts.container, db, prompts.limit)
base.outputTableFancy(results)
base.end()
return results
} catch (error) {
base.error(error)
}
}
export async function getContainersInt(containerGroup, container, client, limit) {
base.debug('getContainersInt')
let query =
`SELECT A.CONTAINER_NAME, A.CONTAINER_GROUP_NAME, B.SCHEMA_NAME, A.CREATE_USER_NAME, A.CREATE_TIMESTAMP_UTC
FROM ( _SYS_DI.M_ALL_CONTAINERS AS A
INNER JOIN _SYS_DI.M_ALL_CONTAINER_SCHEMAS AS B
ON ( A.CONTAINER_NAME = B.CONTAINER_NAME
AND B.SCHEMA_TYPE = 'com.sap.hana.runtime.db.target/*' ) )
WHERE A.CONTAINER_NAME LIKE ?
AND A.CONTAINER_GROUP_NAME LIKE ?
ORDER BY A.CONTAINER_NAME `
if (limit | base.sqlInjection.isAcceptableParameter(limit)) {
query += `LIMIT ${limit.toString()}`
}
return await client.statementExecPromisified(
await client.preparePromisified(query),
[
base.dbClass.objectName(container),
base.dbClass.objectName(containerGroup)
]
)
}