Skip to content

Commit bdf23d3

Browse files
authored
Merge pull request #5 from functional-team/feat/sea-binaries
add single executable apps
2 parents c6996d8 + 3810c1d commit bdf23d3

File tree

7 files changed

+105
-50
lines changed

7 files changed

+105
-50
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ test.json
6767
bfg-1.14.0.jar
6868
crawled.json
6969
test copy.json
70+
.build/bundle.js
71+
.build/bundle.js.LICENSE.txt
72+
src/.DS_Store
73+
.DS_Store
74+
.gitignore
75+
.gitignore

README.md

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,58 @@
11
# kalypso-cli
22

3-
## Overview
4-
kalypso-cli is a command line tool to crawl resources in your Azure subscription and store it as local JSON file.
5-
This output can be used to visualise your resources in the [Kalypso UI](https://kalypso.tools/).
6-
The UI is running locally in your browser. There is no backend or other service and thus no data transfer whatsoever happening with your data. Everything stays on your local computer.
7-
Kalypso-cli is designed to crawl all kinds of resources from your subscription(s). As of 2024 the main focus of development lies on discovery of Azure Data Explorer (ADX) resources like tables, functions and policies.
3+
Discover Azure resources [querying](https://aka.ms/AzureResourceGraph-QueryLanguage) Azure Resource Graph, crawl additional info and store everything into a local JSON file, which can be used with https://kalypso.tools
84

9-
## Installation
5+
Support currently limited to resource type `microsoft.kusto/clusters`
106

11-
### Prerequisites
7+
The CLI expects you to be authenticated in Azure already. This typically achieved with running `az login` before.
128

13-
- [npm and node.js](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) are installed
14-
- [azure cli](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) is installed
159

10+
## Install the latest precompiled binary
1611

17-
you just clone the repo and run:
12+
```sh
13+
curl -fsSL https://raw.githubusercontent.com/functional-team/kalypso-cli/refs/heads/main/dist/install.sh | sh
14+
```
1815

19-
```shell
20-
npm install
21-
```
22-
16+
## Usage
2317

24-
## Documentation
18+
### Command line utility
2519

26-
### Quickstart
27-
Starting a crawl run is as simple as:
20+
```sh
21+
Usage: kalypso-cli crawl [options]
2822

29-
```shell
30-
#authenticate to your azure subscription(s)
31-
az login
23+
Crawl Azure Resources
3224

33-
#run crawler
34-
npm run crawl
35-
```
25+
Options:
26+
-o|--output-path [string] path to output file, default is set in configuration (default: "crawled.json")
27+
-q|--az-graph-query [string] Use Resource Graph Query to specify scope of the crawl
28+
-k|--az-kusto-uri [string] Use Kusto Cluster URI to crawl specific Cluster only
29+
-h, --help display help for command
30+
```
3631

37-
The crawl command supports two parameters:
32+
### Examples
3833

39-
* `--output-path`: file path for where the output JSON is getting stored. Defaults to ./crawled.json
40-
* `--azure-query`: A KQL query that narrows down what resources should be crawled. Please refer to https://aka.ms/AzureResourceGraph-QueryLanguage for a reference.
34+
Using the precompiled binaries:
4135

42-
### Example
36+
```sh
37+
az login
38+
kalypso-cli crawl --output-path "resources.json" --az-graph-query "type == 'microsoft.kusto/clusters' and resourceGroup contains 'dev'"
39+
```
4340

44-
```shell
45-
az login
46-
```
47-
This command opens a browser window to authenticate with your Azure subscription. After sucessful authentication, you should be seeing details about your Azure subscription starting with:
48-
```shell
49-
[
50-
{
51-
"cloudName": "AzureCloud",
52-
"homeTenantId": ...
53-
```
41+
Cloning the repo and using an existing node.js installation
5442

43+
```sh
44+
npm install
45+
az login
46+
npx ts-node ./src/index.ts crawl --output-path "resources.json" --az-graph-query "type == 'microsoft.kusto/clusters' and resourceGroup contains 'dev'"
47+
```
5548

56-
Now, crawling can be initiated by
49+
## Developer guide
5750

58-
```shell
59-
npm run crawl
60-
```
61-
The command output should now look like this:
62-
```shell
63-
SCAN KUSTO CLUSTER : https://myawesomecluster.westeurope.kusto.windows.net
64-
SCAN KUSTO DATABASE: myawesomedatabase: 45 Schemas. 63 Update Policies. 45 Tables. 143 Functions. 20 Materialized Views. 1 External Tables.
65-
...
66-
```
51+
### Build precompiled binaries (experimental)
6752

53+
We use https://github.com/james-pre/xsea to ease the creation of single executable apps for all major platforms:
6854

55+
```shell
56+
npm install --global xsea
57+
sudo npm run build && sudo npm run package
58+
```

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
},
2828
"scripts": {
2929
"build": "webpack",
30+
"package": "xsea .build/bundle.js --verbose --clean -o dist/kalypso-cli -t darwin-arm64 -t linux-x64 -t win-x64 && gzip -v dist/kalypso-cli-darwin-arm64 && gzip -v dist/kalypso-cli-linux-x64 && gzip -v dist/kalypso-cli-win-x64.exe",
3031
"commit": "git-cz",
3132
"format:check": "prettier --list-different '{src,__mocks__,bin}/**/*.ts'",
3233
"format:write": "prettier --write '{src,__mocks__,bin}/**/*.ts'",
3334
"start:help": "ts-node ./src/index.ts -h",
3435
"start": "ts-node ./src/index.ts",
35-
"crawl": "ts-node ./src/index.ts crawl -q \"Resources | where type contains 'microsoft.kusto/clusters' and name contains 'dev' | project id, name, type, location, subscriptionId, resourceGroup, properties\" -o crawled.json",
36+
"crawlkusto": "ts-node ./src/index.ts crawl -q \"Resources | where type contains 'microsoft.kusto/clusters' and name contains 'dev' | project id, name, type, location, subscriptionId, resourceGroup, properties\" -o test.json",
3637
"demo": "ts-node ./src/index.ts crawl -k \"https://help.kusto.windows.net/\"",
3738
"test": "jest",
3839
"bump-version": "rjp package.json version $VERSION",
@@ -89,5 +90,10 @@
8990
"ts-node": "^10.2.1",
9091
"typescript": "^4.9.5",
9192
"webpack-cli": "^5.1.4"
93+
},
94+
"overrides": {
95+
96+
"whatwg-url": "14.x"
97+
}
9298
}
9399
}

sea-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"main": ".build/bundle.js",
3+
"output": ".build/sea-prep.blob",
4+
"disableExperimentalSEAWarning": true
5+
}

src/commands/crawl/command.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Command } from 'commander';
22
import { Options } from './options';
3+
import { kalypsoPrint } from '../../lib/kalypso-logo-print';
34
import { ResourceGraphClient } from "@azure/arm-resourcegraph";
45
import { AzureKustoClusterScanner } from '../../lib/azure/AzureKustoClusterScanner';
56
import * as fs from 'fs';
@@ -24,15 +25,18 @@ export function CrawlCommand(): Command {
2425

2526
async function action(options: Options) {
2627

28+
kalypsoPrint(`\nAZURE GRAPH QUERY: ${options.azGraphQuery} \nLOCAL OUTPUT PATH: ${options.outputPath}\n` )
29+
2730
let startTime = new Date();
2831

2932
let azureresources:any = {};
3033
const creds = new DefaultAzureCredential();
3134

3235
if (options.azGraphQuery) {
3336
const client = new ResourceGraphClient(creds, {})
34-
const graphresources = await client.resources({query: options.azGraphQuery})
35-
37+
const graphresources = await client.resources({query: "resources | where "+options.azGraphQuery})
38+
console.log(`NUMBER OF RESOURCES FOUND IN AZURE GRAPH: ${graphresources.count}`);
39+
3640
for (const resource of graphresources.data) {
3741
if (resource.type=="microsoft.kusto/clusters") {
3842
const kustoclusters = await AzureKustoClusterScanner(resource);

src/lib/kalypso-logo-print.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import boxen from "boxen";
2+
import chalk from "chalk";
3+
4+
const header =
5+
'____ __. .__ _________ .__ \n' +
6+
'| |/ _|____ | | ___.__.______ __________ \\_ ___ \\____________ __ _ _| | ___________ \n' +
7+
'| < \\__ \\ | |< | |\\____ \\/ ___/ _ \\ / \\ \\/\\_ __ \\__ \\\ \\/ \\/ / | _/ __ \\_ __ \\ \n' +
8+
'| | \\ / __ \\| |_\\___ || |_> >___ ( <_> ) \\ \\____| | \\// __ \\\ /| |_\\ ___/| | \\/ \n' +
9+
'|____|__ (____ /____/ ____|| __/____ >____/ \\______ /|__| (____ /\\/\\_/ |____/\\___ >__| \n' +
10+
' \\/ \\/ \\/ |__| \\/ \\/ \\/ \\/ \n';
11+
12+
13+
export function kalypsoPrint(content: string) {
14+
console.log(boxen(chalk.yellowBright(header) + content, {
15+
padding: 1,
16+
margin: 1,
17+
borderStyle: 'round'
18+
}))
19+
20+
}

webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// webpack.config.js
2+
const path = require('path');
3+
4+
module.exports = {
5+
target: 'node',
6+
entry: './src/index.ts',
7+
module: {
8+
rules: [
9+
{
10+
test: /\.tsx?$/,
11+
use: 'ts-loader',
12+
exclude: /node_modules/,
13+
},
14+
],
15+
},
16+
resolve: {
17+
extensions: ['.tsx', '.ts', '.js'],
18+
},
19+
output: {
20+
filename: 'bundle.js',
21+
path: path.resolve(__dirname, '.build'),
22+
},
23+
mode: "production",
24+
};

0 commit comments

Comments
 (0)