Skip to content

Commit b00a93b

Browse files
authored
Add defender easm sdk (#27256)
[product documentation](https://learn.microsoft.com/en-us/azure/external-attack-surface-management/) Azure/azure-sdk#5062 Typespec PR: Azure/azure-rest-api-specs#24937 arcboard: Azure/azure-sdk#5062 apiview: https://apiview.dev/Assemblies/Review/03ef0c5f65374c3789d8302ef5c9c570 ### Packages impacted by this PR ### Issues associated with this PR Azure SDK Review issue: Azure/azure-sdk-pr#1276 Azure SDK Introducing issue: Azure/azure-sdk#5062 ### Describe the problem that is addressed by this PR Adding a new JavaScript data-plane sdk for EASM service ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ Yes, test cases are added ### Provide a list of related PRs _(if any)_ - Previous PR: #26755. It was closed because Shad is no longer working for Microsoft and other developers don't have access to push to that PR. ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ Used npx tsp complile to generate the PR ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 72d460d commit b00a93b

52 files changed

Lines changed: 8046 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/config/rush/pnpm-lock.yaml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rush.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@
345345
"projectFolder": "sdk/translation/ai-translation-text-rest",
346346
"versionPolicyName": "client"
347347
},
348+
{
349+
"packageName": "@azure-rest/defender-easm",
350+
"projectFolder": "sdk/easm/defender-easm-rest",
351+
"versionPolicyName": "client"
352+
},
348353
{
349354
"packageName": "@azure-rest/confidential-ledger",
350355
"projectFolder": "sdk/confidentialledger/confidential-ledger-rest",

sdk/easm/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
2+
3+
trigger:
4+
branches:
5+
include:
6+
- main
7+
- release/*
8+
- hotfix/*
9+
paths:
10+
include:
11+
- sdk/iot/
12+
13+
pr:
14+
branches:
15+
include:
16+
- main
17+
- feature/*
18+
- release/*
19+
- hotfix/*
20+
paths:
21+
include:
22+
- sdk/easm/
23+
24+
extends:
25+
template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
26+
parameters:
27+
ServiceDirectory: easm
28+
Artifacts:
29+
- name: azure-easm-defender
30+
safeName: azureeasmdefender
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"plugins": ["@azure/azure-sdk"],
3+
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
4+
"rules": {
5+
"@azure/azure-sdk/ts-modules-only-named": "warn",
6+
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
7+
"@azure/azure-sdk/ts-package-json-types": "warn",
8+
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
9+
"tsdoc/syntax": "warn"
10+
}
11+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Azure DefenderEasm REST client library for JavaScript
2+
3+
Defender EASM discovers and maps your digital attack surface to provide an "outside-in" perspective using probes to discover assets. The assets are provided with detailed metadata associated, including vulnerabilities, configurations and web components, allowing customers to view and prioritize external risk. The EASM REST API enables you to develop clients that integrate with your application.
4+
5+
**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
6+
7+
Key links:
8+
9+
- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/easm/defender-easm-rest)
10+
- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/defender-easm)
11+
- [API reference documentation](https://azure.github.io/azure-sdk-for-js)
12+
- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/easm/defender-easm-rest/samples/v1-beta)
13+
14+
## Getting started
15+
16+
### Currently supported environments
17+
18+
- LTS versions of Node.js
19+
20+
### Prerequisites
21+
22+
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
23+
24+
### Install the `@azure-rest/defender-easm` package
25+
26+
Install the Azure DefenderEasm REST client REST client library for JavaScript with `npm`:
27+
28+
```bash
29+
npm install @azure-rest/defender-easm
30+
```
31+
32+
### Create and authenticate a `EasmClient`
33+
34+
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
35+
provide an instance of the desired credential type obtained from the
36+
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
37+
38+
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
39+
40+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
41+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
42+
can be used to authenticate the client.
43+
44+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
45+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
46+
47+
## Troubleshooting
48+
49+
### Logging
50+
51+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
52+
53+
```javascript
54+
const { setLogLevel } = require("@azure/logger");
55+
56+
setLogLevel("info");
57+
```
58+
59+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "./types/src/index.d.ts",
4+
"docModel": { "enabled": true },
5+
"apiReport": { "enabled": true, "reportFolder": "./review" },
6+
"dtsRollup": {
7+
"enabled": true,
8+
"untrimmedFilePath": "",
9+
"publicTrimmedFilePath": "./types/defender-easm.d.ts"
10+
},
11+
"messages": {
12+
"tsdocMessageReporting": { "default": { "logLevel": "none" } },
13+
"extractorMessageReporting": {
14+
"ae-missing-release-tag": { "logLevel": "none" },
15+
"ae-unresolved-link": { "logLevel": "none" }
16+
}
17+
}
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"AssetsRepo": "Azure/azure-sdk-assets",
3+
"AssetsRepoPrefixPath": "js",
4+
"TagPrefix": "js/easm/defender-easm-rest",
5+
"Tag": "js/easm/defender-easm-rest_a1fc08fe50"
6+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
// https://github.com/karma-runner/karma-chrome-launcher
5+
process.env.CHROME_BIN = require("puppeteer").executablePath();
6+
require("dotenv").config();
7+
const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
8+
process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
9+
10+
module.exports = function (config) {
11+
config.set({
12+
// base path that will be used to resolve all patterns (eg. files, exclude)
13+
basePath: "./",
14+
15+
// frameworks to use
16+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
17+
frameworks: ["source-map-support", "mocha"],
18+
19+
plugins: [
20+
"karma-mocha",
21+
"karma-mocha-reporter",
22+
"karma-chrome-launcher",
23+
"karma-firefox-launcher",
24+
"karma-env-preprocessor",
25+
"karma-coverage",
26+
"karma-sourcemap-loader",
27+
"karma-junit-reporter",
28+
"karma-source-map-support",
29+
],
30+
31+
// list of files / patterns to load in the browser
32+
files: [
33+
"dist-test/index.browser.js",
34+
{
35+
pattern: "dist-test/index.browser.js.map",
36+
type: "html",
37+
included: false,
38+
served: true,
39+
},
40+
],
41+
42+
// list of files / patterns to exclude
43+
exclude: [],
44+
45+
// preprocess matching files before serving them to the browser
46+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
47+
preprocessors: {
48+
"**/*.js": ["sourcemap", "env"],
49+
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
50+
// Preprocess source file to calculate code coverage, however this will make source file unreadable
51+
// "dist-test/index.js": ["coverage"]
52+
},
53+
54+
envPreprocessor: [
55+
"TEST_MODE",
56+
"ENDPOINT",
57+
"AZURE_CLIENT_SECRET",
58+
"AZURE_CLIENT_ID",
59+
"AZURE_TENANT_ID",
60+
"SUBSCRIPTION_ID",
61+
"RESOURCEGROUPNAME",
62+
"WORKSPACENAME",
63+
"RECORDINGS_RELATIVE_PATH",
64+
],
65+
66+
// test results reporter to use
67+
// possible values: 'dots', 'progress'
68+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
69+
reporters: ["mocha", "coverage", "junit"],
70+
71+
coverageReporter: {
72+
// specify a common output directory
73+
dir: "coverage-browser/",
74+
reporters: [
75+
{ type: "json", subdir: ".", file: "coverage.json" },
76+
{ type: "lcovonly", subdir: ".", file: "lcov.info" },
77+
{ type: "html", subdir: "html" },
78+
{ type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" },
79+
],
80+
},
81+
82+
junitReporter: {
83+
outputDir: "", // results will be saved as $outputDir/$browserName.xml
84+
outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
85+
suite: "", // suite will become the package name attribute in xml testsuite element
86+
useBrowserName: false, // add browser name to report and classes names
87+
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
88+
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
89+
properties: {}, // key value pair of properties to add to the <properties> section of the report
90+
},
91+
92+
// web server port
93+
port: 9876,
94+
95+
// enable / disable colors in the output (reporters and logs)
96+
colors: true,
97+
98+
// level of logging
99+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
100+
logLevel: config.LOG_INFO,
101+
102+
// enable / disable watching file and executing tests whenever any file changes
103+
autoWatch: false,
104+
105+
// --no-sandbox allows our tests to run in Linux without having to change the system.
106+
// --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.
107+
browsers: ["ChromeHeadlessNoSandbox"],
108+
customLaunchers: {
109+
ChromeHeadlessNoSandbox: {
110+
base: "ChromeHeadless",
111+
flags: ["--no-sandbox", "--disable-web-security"],
112+
},
113+
},
114+
115+
// Continuous Integration mode
116+
// if true, Karma captures browsers, runs the tests and exits
117+
singleRun: false,
118+
119+
// Concurrency level
120+
// how many browser should be started simultaneous
121+
concurrency: 1,
122+
123+
browserNoActivityTimeout: 60000000,
124+
browserDisconnectTimeout: 10000,
125+
browserDisconnectTolerance: 3,
126+
127+
client: {
128+
mocha: {
129+
// change Karma's debug.html to the mocha web reporter
130+
reporter: "html",
131+
timeout: "600000",
132+
},
133+
},
134+
});
135+
};

0 commit comments

Comments
 (0)