Skip to content

Commit 3dd75fd

Browse files
authored
Jas config api for client-js (#96)
1 parent a98e746 commit 3dd75fd

File tree

7 files changed

+85
-3
lines changed

7 files changed

+85
-3
lines changed

.github/workflows/cla.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: "CLA Assistant"
2020
if: ${{ steps.sign-or-recheck.outputs.match != '' || github.event_name == 'pull_request_target' }}
2121
# Alpha Release
22-
uses: cla-assistant/github-action@v2.1.1-beta
22+
uses: cla-assistant/github-action@v2.6.0
2323
env:
2424
# Generated and maintained by github
2525
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Add jfrog-client-js as a dependency to your package.json file:
3131
- [Scanning a Dependency Tree with Consideration to the JFrog Project](#scanning-a-dependency-tree-with-consideration-to-the-jfrog-project)
3232
- [Scanning a Dependency Tree with Consideration to the Xray Watches](#scanning-a-dependency-tree-with-consideration-to-the-xray-watches)
3333
- [Retrieving Xray Build Details](#retrieving-xray-build-details)
34+
- [Retrieving JAS configuration](#retrieving-jas-configuration)
3435
- [Artifactory](#artifactory)
3536
- [Pinging Artifactory](#pinging-artifactory)
3637
- [Getting Artifactory Version](#getting-artifactory-version)
@@ -199,6 +200,20 @@ jfrogClient
199200
});
200201
```
201202

203+
#### Retrieving JAS configuration
204+
```javascript
205+
jfrogClient
206+
.xray()
207+
.jasconfig()
208+
.getJasConfig()
209+
.then((result) => {
210+
console.log(JSON.stringify(result));
211+
})
212+
.catch((error) => {
213+
console.error(error);
214+
});
215+
```
216+
202217
### Artifactory
203218

204219
#### Pinging Artifactory

model/Xray/JasConfig/JasConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface IJasConfig {
2+
enable_token_validation_scanning: boolean;
3+
}

src/Xray/XrayClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IClientSpecificConfig } from '../../model/ClientSpecificConfig';
77
import { ILogger } from '../../model/';
88
import { XrayGraphClient as XrayScanClient } from '..';
99
import { XrayEntitlementsClient } from './XrayEntitlementsClient';
10+
import { XrayJasConfigClient } from './XrayJasConfigClient';
1011

1112
export class XrayClient {
1213
static readonly scanGraphEndpoint: string = 'api/v1/scan/graph';
@@ -68,4 +69,8 @@ export class XrayClient {
6869
public entitlements(): XrayEntitlementsClient {
6970
return new XrayEntitlementsClient(this.httpClient, this.logger);
7071
}
72+
73+
public jasconfig(): XrayJasConfigClient {
74+
return new XrayJasConfigClient(this.httpClient, this.logger);
75+
}
7176
}

src/Xray/XrayJasConfigClient.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { HttpClient, IRequestParams } from '../HttpClient';
2+
import { ILogger } from '../../model';
3+
import { IJasConfig } from '../../model/Xray/JasConfig/JasConfig';
4+
5+
export class XrayJasConfigClient {
6+
private readonly jasConfigurationEndpoint: string = '/api/v1/configuration/jas';
7+
constructor(private readonly httpClient: HttpClient, private readonly logger: ILogger) {}
8+
/**
9+
*
10+
* Sends 'GET /configuration/js requests to Xray and waits for 200 response'.
11+
* @returns the jas config
12+
* @throws an exception if an unexpected response received from Xray
13+
*/
14+
async getJasConfig(): Promise<IJasConfig> {
15+
this.logger.debug(`Sending GET ${this.jasConfigurationEndpoint} request...`);
16+
const requestParams: IRequestParams = {
17+
url: this.jasConfigurationEndpoint,
18+
method: 'GET',
19+
validateStatus: (status: number): boolean => {
20+
return status === 200;
21+
},
22+
};
23+
return await (
24+
await this.httpClient.doAuthRequest(requestParams)
25+
).data;
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import faker from 'faker';
2+
import nock from 'nock';
3+
import { JfrogClient } from '../../../src';
4+
import { TestUtils } from '../../TestUtils';
5+
6+
describe('Xray jas config tests', () => {
7+
test('Get jas config', async () => {
8+
const PLATFORM_URL: string = faker.internet.url();
9+
const uri: string = `/xray/api/v1/configuration/jas`;
10+
const expectedResource: string = '{"enable_token_validation_scanning": true}';
11+
nock(PLATFORM_URL).get(uri).reply(200, expectedResource);
12+
const client: JfrogClient = new JfrogClient({ platformUrl: PLATFORM_URL, logger: TestUtils.createTestLogger() });
13+
const res: any = await client.xray().jasconfig().getJasConfig();
14+
expect(res).toHaveProperty("enable_token_validation_scanning")
15+
expect(res.enable_token_validation_scanning).toEqual(true)
16+
});
17+
});
18+
19+
describe('Xray jas config tests', () => {
20+
test('Fail get jas config', async () => {
21+
const PLATFORM_URL: string = faker.internet.url();
22+
const uri: string = `/xray/api/v1/configuration/jas`;
23+
nock(PLATFORM_URL).get(uri).reply(402, { message: 'error' }).persist();
24+
const client: JfrogClient = new JfrogClient({ platformUrl: PLATFORM_URL, logger: TestUtils.createTestLogger() })
25+
await expect(async () => {
26+
await client
27+
.xray()
28+
.jasconfig()
29+
.getJasConfig();
30+
}).rejects.toThrow(`Request failed with status code 402`);
31+
});
32+
});

test/tests/Xray/XraySummaryClient.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ describe('Xray summary tests', () => {
125125

126126
const license: ILicense = licenses[0];
127127
expect(license.name).toBe('MIT');
128-
expect(license.full_name).toBe('The MIT License');
129-
expect(license.more_info_url.length).toBeGreaterThanOrEqual(4);
128+
expect(license.full_name).toBe('MIT License');
129+
expect(license.more_info_url.length).toBeGreaterThanOrEqual(3);
130130
expect(license.components.length).toBe(1);
131131
expect(license.components[0]).toBe('npm://js-yaml:3.10.0');
132132
});

0 commit comments

Comments
 (0)