Skip to content

Commit

Permalink
[Identity] Enforcing ESLint (#10257)
Browse files Browse the repository at this point in the history
* [Identity] Enforcing ESLint

* avoiding changes on the public API, and attempting to fix CI

* removing the useless constructor

* removed empty line
  • Loading branch information
sadasant authored Jul 28, 2020
1 parent a91e5fc commit 752628b
Show file tree
Hide file tree
Showing 50 changed files with 106 additions and 88 deletions.
3 changes: 2 additions & 1 deletion sdk/identity/identity/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/manual/
test/manual/
test/manual-integration/
8 changes: 8 additions & 0 deletions sdk/identity/identity/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
"ignorePatterns": ["src/core"],
"rules": {
"@azure/azure-sdk/ts-naming-options": "warn"
}
}
16 changes: 11 additions & 5 deletions sdk/identity/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
"integration-test:browser": "echo skipped",
"integration-test:node": "echo skipped",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json tsconfig.json src test samples --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json tsconfig.json src test samples --ext .ts -f html -o identity-lintReport.html || exit 0",
"lint:fix": "eslint package.json tsconfig.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json tsconfig.json src test --ext .ts -f html -o identity-lintReport.html",
"lint:terminal": "eslint package.json api-extractor.json src test --ext .ts",
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
Expand All @@ -54,9 +55,13 @@
"README.md",
"LICENSE"
],
"engines": {
"node": ">=8.0.0"
},
"repository": "github:Azure/azure-sdk-for-js",
"keywords": [
"azure",
"Azure",
"cloud",
"active directory",
"authentication",
"credential",
Expand All @@ -68,12 +73,12 @@
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/azure/azure-sdk-for-js/issues"
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"engine": {
"node": ">=8.0.0"
},
"homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/identity/identity",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity/README.md",
"sideEffects": false,
"dependencies": {
"@azure/core-http": "^1.1.4",
Expand All @@ -91,6 +96,7 @@
"keytar": "^5.4.0"
},
"devDependencies": {
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/abort-controller": "^1.0.0",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
Expand Down
1 change: 0 additions & 1 deletion sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export enum AzureAuthorityHosts {

// @public
export class AzureCliCredential implements TokenCredential {
constructor();
protected getAzureCliAccessToken(resource: string): Promise<unknown>;
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/identity/src/client/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/**
* See the official documentation for more details:
Expand Down Expand Up @@ -153,7 +153,7 @@ export class AggregateAuthenticationError extends Error {
public errors: any[];

constructor(errors: any[], errorMessage?: string) {
let errorDetail = errors.join("\n");
const errorDetail = errors.join("\n");
super(`${errorMessage}\n\n${errorDetail}`);
this.errors = errors;

Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity/src/client/identityClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import {
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/**
* The default client ID for authentication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import { createSpan } from "../util/tracing";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
20 changes: 8 additions & 12 deletions sdk/identity/identity/src/credentials/azureCliCredential.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { createSpan } from "../util/tracing";
Expand All @@ -26,11 +26,6 @@ const logger = credentialLogger("AzureCliCredential");
* with Azure CLI command "az account get-access-token".
*/
export class AzureCliCredential implements TokenCredential {
/**
* Creates an instance of the AzureCliCredential class.
*/
constructor() {}

/**
* Gets the access token from Azure CLI
* @param resource The resource to use when getting the token
Expand Down Expand Up @@ -66,8 +61,7 @@ export class AzureCliCredential implements TokenCredential {
options?: GetTokenOptions
): Promise<AccessToken | null> {
return new Promise((resolve, reject) => {
let scope: string;
scope = typeof scopes === "string" ? scopes : scopes[0];
const scope = typeof scopes === "string" ? scopes : scopes[0];
logger.getToken.info(`Using the scope ${scope}`);

const resource = scope.replace(/\/.default$/, "");
Expand All @@ -85,8 +79,8 @@ export class AzureCliCredential implements TokenCredential {
this.getAzureCliAccessToken(resource)
.then((obj: any) => {
if (obj.stderr) {
let isLoginError = obj.stderr.match("(.*)az login(.*)");
let isNotInstallError =
const isLoginError = obj.stderr.match("(.*)az login(.*)");
const isNotInstallError =
obj.stderr.match("az:(.*)not found") ||
obj.stderr.startsWith("'az' is not recognized");
if (isNotInstallError) {
Expand All @@ -109,10 +103,12 @@ export class AzureCliCredential implements TokenCredential {
responseData = obj.stdout;
const response: { accessToken: string; expiresOn: string } = JSON.parse(responseData);
logger.getToken.info(formatSuccess(scopes));
resolve({
const returnValue = {
token: response.accessToken,
expiresOnTimestamp: new Date(response.expiresOn).getTime()
});
};
resolve(returnValue);
return returnValue;
}
})
.catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http";
import { AggregateAuthenticationError, CredentialUnavailable } from "../client/errors";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import jws from "jws";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { TokenCredentialOptions } from "../client/identityClient";
import { ChainedTokenCredential } from "./chainedTokenCredential";
Expand All @@ -26,7 +26,7 @@ export class DefaultAzureCredential extends ChainedTokenCredential {
* @param options Options for configuring the client which makes the authentication request.
*/
constructor(tokenCredentialOptions?: TokenCredentialOptions) {
let credentials = [];
const credentials = [];
credentials.push(new EnvironmentCredential(tokenCredentialOptions));
credentials.push(new ManagedIdentityCredential(tokenCredentialOptions));
credentials.push(new AzureCliCredential());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { TokenCredentialOptions } from "../client/identityClient";
import { ChainedTokenCredential } from "./chainedTokenCredential";
import { EnvironmentCredential } from "./environmentCredential";
import { ManagedIdentityCredential } from "./managedIdentityCredential";
import { AzureCliCredential } from "./azureCliCredential";
import { VSCodeCredential } from "./vscodeCredential";
import { TokenCredential } from "@azure/core-http";

/**
* Provides options to configure the default Azure credentials.
Expand Down Expand Up @@ -37,7 +36,7 @@ export class DefaultAzureCredential extends ChainedTokenCredential {
* @param options Options for configuring the client which makes the authentication request.
*/
constructor(tokenCredentialOptions?: DefaultAzureCredentialOptions) {
let credentials = [];
const credentials = [];
credentials.push(new EnvironmentCredential(tokenCredentialOptions));
credentials.push(new ManagedIdentityCredential(tokenCredentialOptions));
if (process.env.AZURE_CLIENT_ID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import * as msal from "msal";
import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { TokenCredentialOptions } from "../client/identityClient";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import {
Expand Down Expand Up @@ -369,7 +369,7 @@ export class ManagedIdentityCredential implements TokenCredential {
message: err.message
});

if (err.code == "ENETUNREACH") {
if (err.code === "ENETUNREACH") {
const error = new CredentialUnavailable(
"ManagedIdentityCredential is unavailable. No managed identity endpoint found."
);
Expand All @@ -387,6 +387,7 @@ export class ManagedIdentityCredential implements TokenCredential {
"ManagedIdentityCredential is unavailable. No managed identity endpoint found."
);
logger.getToken.info(formatError(error));
// eslint-disable-next-line no-unsafe-finally
throw error;
}
span.end();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import qs from "qs";
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

Expand Down
9 changes: 5 additions & 4 deletions sdk/identity/identity/src/credentials/vscodeCredential.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/* eslint-disable @typescript-eslint/no-unused-vars */

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredentialOptions, IdentityClient } from "../client/identityClient";
let keytar: any;
try {
var keytar = require("keytar");
keytar = require("keytar");
} catch (er) {
keytar = null;
}
Expand Down Expand Up @@ -83,9 +84,9 @@ export class VSCodeCredential implements TokenCredential {
scopeString += " offline_access";
}

let refreshToken = await keytar.findPassword(VSCodeUserName);
const refreshToken = await keytar.findPassword(VSCodeUserName);
if (refreshToken) {
let tokenResponse = await this.identityClient.refreshAccessToken(
const tokenResponse = await this.identityClient.refreshAccessToken(
this.tenantId,
AzureAccountClientId,
scopeString,
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

import { TokenCredential } from "@azure/core-http";
import { DefaultAzureCredential } from "./credentials/defaultAzureCredential";
Expand Down
5 changes: 4 additions & 1 deletion sdk/identity/identity/src/util/authHostEnv.browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

const BrowserNotSupportedError = new Error(
"getAuthorityHostEnvironment is not supported in the browser."
);

export function getAuthorityHostEnvironment() {
export function getAuthorityHostEnvironment(): { authorityHost: string } | undefined {
throw BrowserNotSupportedError;
}
5 changes: 4 additions & 1 deletion sdk/identity/identity/src/util/authHostEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export function getAuthorityHostEnvironment() {
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export function getAuthorityHostEnvironment(): { authorityHost: string } | undefined {
if (process.env.AZURE_AUTHORITY_HOST) {
return {
authorityHost: process.env.AZURE_AUTHORITY_HOST
Expand Down
Loading

0 comments on commit 752628b

Please sign in to comment.