Skip to content

Commit

Permalink
Merge pull request #150 from 4urcloud/dev-esteban-exportSaaSAddOn
Browse files Browse the repository at this point in the history
Dev esteban export saas addOn
  • Loading branch information
aeppling authored Apr 25, 2024
2 parents d9b10bc + a762325 commit 55093b5
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 25 deletions.
86 changes: 86 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,48 @@ package-lock.json was changed

package.json was changed

## 1.14.0-devestebanexportsaasaddon.15.d3d1bf9

### Files added: 5

Kexa/models/export/kexa/config.model.ts was added

Kexa/services/addOn/exportation/kexaExportation.service.ts was added

Kexa/services/addOn/save/kexaSave.service.ts was added

config/demo/kexa.default.json was added

documentation/save/Kexa.md was added

### Files changed: 13

Kexa/models/export/kexa/config.model.ts was changed

Kexa/services/addOn/exportation/kexaExportation.service.ts was changed

Kexa/services/addOn/save/kexaSave.service.ts was changed

config/demo/kexa.default.json was changed

documentation/save/Kexa.md was changed

Dockerfile was changed

Kexa/main.ts was changed

Kexa/services/analyse.service.ts was changed

Kexa/services/exportation.service.ts was changed

documentation/Documentation-Kexa.md was changed

documentation/save/AzureBlobStorage.md was changed

documentation/save/MongoDB.md was changed

documentation/save/MySQL.md was changed


## 1.14.0-SNAPSHOT.18.b28d27d

Expand Down Expand Up @@ -1584,6 +1626,50 @@ package.json was changed

Kexa/services/analyse.service.ts was changed

documentation/Documentation-Kexa.md was changed## 1.14.0-devestebanexportsaasaddon.38.b0f21a8

### Files added: 5

Kexa/models/export/kexa/config.model.ts was added

Kexa/services/addOn/exportation/kexaExportation.service.ts was added

Kexa/services/addOn/save/kexaSave.service.ts was added

config/demo/kexa.default.json was added

documentation/save/Kexa.md was added

### Files changed: 15

Kexa/models/export/kexa/config.model.ts was changed

Kexa/services/addOn/exportation/kexaExportation.service.ts was changed

Kexa/services/addOn/save/kexaSave.service.ts was changed

config/demo/kexa.default.json was changed

documentation/save/Kexa.md was changed

CHANGELOG.md was changed

Dockerfile was changed

Kexa/main.ts was changed

Kexa/services/analyse.service.ts was changed

Kexa/services/exportation.service.ts was changed

VERSION was changed

documentation/Documentation-Kexa.md was changed

documentation/save/AzureBlobStorage.md was changed

documentation/save/MongoDB.md was changed

documentation/save/MySQL.md was changed


11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
RUN pnpm install --frozen-lockfile

FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
ENV NODE_OPTIONS=--max-old-space-size=16384
RUN pnpm run build

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
FROM base AS release
COPY --from=build /app/build /app/build
EXPOSE 8000
CMD [ "pnpm", "start:nobuild" ]
#CMD ["sleep","infinity"]
CMD [ "pnpm", "run", "start:nobuild" ]
2 changes: 1 addition & 1 deletion Kexa/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function main() {
logger.info("___________________________________-= running Kexa scan =-_________________________________________");
logger.info("___________________________________________________________________________________________________");
await displayVersionAndLatest(logger);
let settings = await gatheringRules(await getEnvVar("RULESDIRECTORY")??"./Kexa/rules");
let settings = await gatheringRules(await getEnvVar("RULESDIRECTORY")??"https://github.com/4urcloud/Kexa_Rules");
let allPromises = [];
if(settings.length != 0){
let resources = await loadAddOns(settings);
Expand Down
7 changes: 7 additions & 0 deletions Kexa/models/export/kexa/config.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SaveConfig } from "../config.models";

export interface KexaSaveConfig extends SaveConfig {
type: "kexa";
name: string;
token: string;
}
30 changes: 30 additions & 0 deletions Kexa/services/addOn/exportation/kexaExportation.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { getEnvVar } from "../../manageVarEnvironnement.service";
import { getContext, getNewLogger } from "../../logger.service";
import { ProviderResource } from "../../../models/providerResource.models";
import { getConfig } from "../../../helpers/loaderConfig";
import { KexaSaveConfig } from "../../../models/export/kexa/config.model";

const axios = require('axios');
const logger = getNewLogger("KexaExportationLogger");
const context = getContext();
//const addOnPropertyToSend: { [key: string]: Function; } = loadAddOnsCustomUtility("display", "propertyToSend");

export async function exportation(save: KexaSaveConfig, resources: ProviderResource): Promise<void>{
throw new Error("Not implemented");
if(!save.name) throw new Error("name is required");
let name = (await getEnvVar(save.name))??save.name;
let token = (await getEnvVar(save.token))??save.token;
logger.info(`Exportation to Kexa SaaS`);
context?.log(`Exportation to Kexa SaaS`);
const config = getConfig();
let configSend:any = {};
Object.keys(resources).forEach((providerName) => {
configSend[providerName] = config[providerName]??[];
});
await axios.post((process.env.DOMAINEKEXA??`https://api.kexa.io`) + '/api/job/exportation', {resources: resources, configSend, save}, {
headers: {
User: name,
Authorization: token
}
});
}
25 changes: 25 additions & 0 deletions Kexa/services/addOn/save/kexaSave.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ResultScan } from "../../../models/resultScan.models";
import { getEnvVar } from "../../manageVarEnvironnement.service";
import { getContext, getNewLogger } from "../../logger.service";
import { loadAddOnsCustomUtility } from "../../addOn.service";
import { KexaSaveConfig } from "../../../models/export/kexa/config.model";

const axios = require('axios');
const logger = getNewLogger("KexaSaveLogger");
const context = getContext();
//const addOnPropertyToSend: { [key: string]: Function; } = loadAddOnsCustomUtility("display", "propertyToSend");

export async function save(save: KexaSaveConfig, result: ResultScan[][]): Promise<void>{
throw new Error("Not implemented");
if(!save.name) throw new Error("name is required");
let name = (await getEnvVar(save.name))??save.name;
let token = (await getEnvVar(save.token))??save.token;
logger.info(`Saving to Kexa SaaS`);
context?.log(`Saving to Kexa SaaS`);
await axios.post((process.env.DOMAINEKEXA??`https://api.kexa.io`) + `/api/job/save`, {result: result, save}, {
headers: {
User: name,
Authorization: token
}
});
}
4 changes: 3 additions & 1 deletion Kexa/services/analyse.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const varEnvMin = {
const config = getConfig();
const levelAlert = ["info", "warning", "error", "critical"];
const defaultRulesDirectory = "./rules";
const secondDefaultRulesDirectory = "./Kexa/rules";

let headers: any;
// Analyze list
Expand All @@ -49,7 +50,8 @@ export async function gatheringRules(rulesDirectory:string, getAll:boolean=false
await gatheringDistantRules(rulesDirectory);
rulesDirectory = defaultRulesDirectory;
}
const paths = fs.readdirSync(rulesDirectory, { withFileTypes: true});
let paths = fs.readdirSync(rulesDirectory, { withFileTypes: true});
if(paths.length === 0) paths = fs.readdirSync(secondDefaultRulesDirectory, { withFileTypes: true});
logger.debug("listing rules files.");
let settingFileList = new Array<SettingFile>;
headers = require('../../config/headers.json');
Expand Down
2 changes: 1 addition & 1 deletion Kexa/services/exportation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const context = getContext();
export async function exportationData(resources: ProviderResource): Promise<any[]> {
if(!configuration.export) return [];
const addOnExportation: { [key: string]: Function; } = loadAddOnsCustomUtility("exportation", "exportation", configuration.export.map((save: SaveConfig) => save.type));
if(!Array.isArray(configuration.save)) configuration.save = [configuration.save];
if(!Array.isArray(configuration.export)) configuration.export = [configuration.export];
let promises = Promise.all(configuration.export.map(async (save: SaveConfig) => {
if(addOnExportation[save.type]){
try{
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.14.0-SNAPSHOT.32.8960e5d
1.14.0-devestebanexportsaasaddon.38.b0f21a8
29 changes: 29 additions & 0 deletions config/demo/kexa.default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"azure": [
{
"name": "Project A",
"prefix": "PROJECTA-",
"description": "First subscription (0) : Project A subscription",
"rules": [
"Name of my rule"
]
},
{
"name": "Project B",
"prefix": "PROJECTB-",
"description": "Second subscription (1) : Project B subscription",
"rules": [
"Name of my rule",
"Another rules"
]
}
],
"save": [
{
"type": "kexa",
"name": "name of the token or the name of the var environment where the real name is stored",
"token": "token for kexa or the name of the var environment where the token is stored: the format is uuid4",
"description": "example of save for kexa"
}
]
}
12 changes: 6 additions & 6 deletions documentation/Documentation-Kexa.md
Original file line number Diff line number Diff line change
Expand Up @@ -1249,15 +1249,15 @@ However if you want to run kexa with a special config or rules, you can perform

- set your own configuration:

```shell
docker run -d -v Absolute/Path/to/config:/app/config kexa
```
```shell
docker run -d -v Absolute/Path/to/config:/app/config kexa
```

- set your own rules:

```shell
docker run -d -v Absolute/Path/to/rules:/app/kexa/rules kexa
```
```shell
docker run -d -v Absolute/Path/to/rules:/app/kexa/rules kexa
```

<br/>

Expand Down
6 changes: 3 additions & 3 deletions documentation/save/AzureBlobStorage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<a href="https://www.kexa.io/addOn/azure">
<a href="https://www.kexa.io/modules">
<img src="../../images/azureBlobStorage.png" alt="Logo" width="200">
</a>

Expand All @@ -17,7 +17,7 @@

### Default.json

For each of your blob storage, no key is mandatory in the original sense of the term execpt:
For each of your blob storage, no key is mandatory in the original sense of the term except:

- "containerName": it's refer to the name of your container where you want to store the data

Expand All @@ -37,4 +37,4 @@ Example config for each identification you can use:

### Environment

urlName can be use to refer to a specific value in your environnement with his name as value.
urlName can be use to refer to a specific value in your environnement with his name as value.
39 changes: 39 additions & 0 deletions documentation/save/Kexa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div align="center">
<a href="https://www.kexa.io/modules">
<img src="../../images/kexa-no-background-color.png" alt="Logo" width="200">
</a>

# <h3 align="center">Kexa SaaS</h3>

<p align="center">
<br />
<a href="https://github.com/4urcloud/Kexa/issues">Report Bug</a>
·
<a href="https://github.com/4urcloud/Kexa/issues">Request Feature</a>
</p>
</div>

## Configuration

### Prerequire

Create a token in the [web site](https://saas.kexa.io).

### Default.json

Keys mandatory:

- name: the name of the key you generated in the Kexa portal
- token: the token himself

Example config for each identification you can use:
![example config for kexa](../../config/demo/kexa.default.json)

### Environment

"name" and "token" can be use to refer to a specific value in your environnement with his name as value.

### Utility

By saving or exporting your data from your kexa to the SaaS service, you can use all the viewing tools available to you.
The data sent using this method is in no way processed by anyone other than yourself.
4 changes: 2 additions & 2 deletions documentation/save/MongoDB.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<a href="https://www.kexa.io/addOn/azure">
<a href="https://www.kexa.io/modules">
<img src="../../images/MongoDB-Logo.png" alt="Logo" width="200">
</a>

Expand All @@ -23,7 +23,7 @@ For each of your database, keys mandatory:
- "collectionName": name of the collection where to store the data. If it's not exist we create it.

Example config for each identification you can use:
![example config for azure](../../config/demo/mongoDB.default.json)
![example config for mongo](../../config/demo/mongoDB.default.json)

### Environment

Expand Down
4 changes: 2 additions & 2 deletions documentation/save/MySQL.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<a href="https://www.kexa.io/addOn/azure">
<a href="https://www.kexa.io/modules">
<img src="../../images/MySQL-Logo.png" alt="Logo" width="200">
</a>

Expand All @@ -26,7 +26,7 @@ For each of your database, keys mandatory:
- "urlName": uri connection to access (with database in the uri)

Example config for each identification you can use:
![example config for azure](../../config/demo/mongoDB.default.json)
![example config for mySQL](../../config/demo/mySQL.default.json)

### Environment

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
"typescript": "^4.9.5"
},
"name": "Kexa",
"version": "1.14.0-SNAPSHOT.32.8960e5d",
"version": "1.14.0-devestebanexportsaasaddon.38.b0f21a8",
"main": "./build/index.js",
"scripts": {
"postinstall": "node-config-ts",
Expand Down

0 comments on commit 55093b5

Please sign in to comment.