Skip to content

Commit

Permalink
Merge pull request #2 from splunk/next
Browse files Browse the repository at this point in the history
next version
  • Loading branch information
Siegfried Puchbauer authored May 12, 2021
2 parents cfca534 + 49f71cd commit 3789438
Show file tree
Hide file tree
Showing 11 changed files with 10,782 additions and 3,641 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@ jobs:
runs-on: ubuntu-latest
steps:
# ...
- uses: splunk/appinspect-api-action@v1
- uses: splunk/appinspect-api-action@v2
with:
filePath: ./dist/myapp.tar.gz
splunkUser: ${{ secrets.SPLUNKBASE_USER }}
splunkPassword: ${{ secrets.SPLUNKBASE_PASSWORD }}
includedTags: cloud
failOnError: true
failOnWarning: true
```
## Inputs
| Name | Description |
| ---------------- | ------------------------------------------------------------------------------ |
| `filePath` | Path to the app bundle file (.tar.gz or .spl) |
| `splunkUser` | Splunk.com user used to login to the appinspect API |
| `splunkPassword` | Splunk.com password used to login to the appinspect API |
| `includedTags` | Optional: Comma separated list of [tags](#tags) to include in appinspect job |
| `excludedTags` | Optional: Comma separated list of [tags](#tags) to exclude from appinspect job |

### Tags

For more info on tags see [Splunk AppInspect tag reference](https://dev.splunk.com/enterprise/docs/reference/appinspecttagreference).
| Name | Description | Notes |
| ---------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------- |
| `filePath` | Path to the app bundle file (.tar.gz or .spl) | **required** |
| `splunkUser` | Splunk.com user used to login to the appinspect API | **required** |
| `splunkPassword` | Splunk.com password used to login to the appinspect API | **required** |
| `includedTags` | Comma separated list of [tags](#reference-docs) to include in appinspect job | |
| `excludedTags` | Comma separated list of [tags](#reference-docs) to exclude from appinspect job | |
| `failOnError` | If enabled the action will fail when errors or failures are reported by AppInspect | default: `true` |
| `failOnWarning` | If enabled the action will fail when warnings are reported by AppInspect | default: `false` |
| `ignoredChecks` | Comma separated list of [check names](#reference-docs) to explicitly ignore | |
| `uploadReportArtifact` | If enabled the action will upload the HTML report from the AppInspect API as an artifact to GitHub actions | default: `true` |

### Reference Docs

For more info on check critera, tags and the API see the [Splunk AppInspect reference](https://dev.splunk.com/enterprise/reference/appinspect).
15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ inputs:
excludedTags:
description: Comma separated list of tags to exclude from appinspect job
required: false
failOnError:
description: If enabled the action will fail when errors or failures are reported by AppInspect (enabled by default)
required: false
default: 'true'
failOnWarning:
description: If enabled the action will fail when warnings are reported by AppInspect
required: false
default: 'false'
ignoredChecks:
description: Comma separated list of check names to explicitly ignore
required: false
uploadReportArtifact:
description: If enabled the action will upload the HTML report from the AppInspect API as an artifact to GitHub actions (enabled by default)
required: false
default: 'true'
13,511 changes: 10,429 additions & 3,082 deletions dist/index.js

Large diffs are not rendered by default.

118 changes: 0 additions & 118 deletions lib/api.js

This file was deleted.

125 changes: 0 additions & 125 deletions lib/main.js

This file was deleted.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
"private": true,
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"pack": "ncc build",
"all": "npm run build && npm run pack"
"build": "ncc build src/main.ts"
},
"license": "UNLICENSED",
"dependencies": {
"@actions/artifact": "^0.5.1",
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.3",
"@actions/github": "^2.1.1",
"@vercel/ncc": "^0.28.3",
"form-data": "^3.0.0",
"@actions/github": "^4.0.0",
"@vercel/ncc": "^0.28.5",
"form-data": "^4.0.0",
"node-fetch": "^2.6.0"
},
"devDependencies": {
"@types/form-data": "^2.5.0",
"@types/node": "^12.7.12",
"@types/node": "^15.0.2",
"@types/node-fetch": "^2.5.7",
"js-yaml": "^3.13.1",
"typescript": "^3.6.4"
"js-yaml": "^4.1.0",
"typescript": "^4.2.4"
}
}
29 changes: 25 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ async function req<T>({
method,
body,
headers,
json = true,
}: {
method: 'GET' | 'POST';
url: string;
headers?: { [k: string]: string };
body?: any;
json?: boolean;
}): Promise<T> {
const res = await fetch(url, {
method,
Expand All @@ -28,7 +30,7 @@ async function req<T>({
}
throw new Error(`HTTP status ${res.status} from ${url}`);
}
return res.json();
return json ? res.json() : res.text();
}

export interface AuthResponse {
Expand Down Expand Up @@ -200,12 +202,31 @@ export interface ReportResponse {
}>;
}

export async function getReport(data: { request_id: string; token: string }): Promise<ReportResponse> {
export async function getReportInternal<T>({
request_id,
token,
format = 'json',
}: {
request_id: string;
token: string;
format?: 'json' | 'html';
}): Promise<T> {
const contentType = format === 'html' ? 'text/html' : 'application/json';
return req({
method: 'GET',
url: `https://appinspect.splunk.com/v1/app/report/${encodeURIComponent(data.request_id)}`,
url: `https://appinspect.splunk.com/v1/app/report/${encodeURIComponent(request_id)}`,
headers: {
Authorization: `Bearer ${data.token}`,
Authorization: `Bearer ${token}`,
'Content-Type': contentType,
},
json: format === 'json',
});
}

export async function getReport({ request_id, token }: { request_id: string; token: string }): Promise<ReportResponse> {
return getReportInternal({ request_id, token, format: 'json' });
}

export async function getHtmlReport({ request_id, token }: { request_id: string; token: string }): Promise<string> {
return getReportInternal({ request_id, token, format: 'html' });
}
Loading

0 comments on commit 3789438

Please sign in to comment.