Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity project noUnusedParameters, noImplicitReturns and noUnusedLocals tsconfig fixes #11453

Merged
merged 17 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export enum AzureAuthorityHosts {

// @public
export class AzureCliCredential implements TokenCredential {
protected getAzureCliAccessToken(resource: string): Promise<unknown>;
protected getAzureCliAccessToken(resource: string): Promise<{
stdout: string;
stderr: string;
error: Error | null;
}>;
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}

Expand Down Expand Up @@ -143,7 +147,7 @@ export { GetTokenOptions }
// @public
export class InteractiveBrowserCredential implements TokenCredential {
constructor(options?: InteractiveBrowserCredentialOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
getToken(scopes: string | string[], _options?: GetTokenOptions): Promise<AccessToken | null>;
mohsin-mehmood marked this conversation as resolved.
Show resolved Hide resolved
}

// @public
Expand Down Expand Up @@ -188,7 +192,7 @@ export class UsernamePasswordCredential implements TokenCredential {
// @public
export class VisualStudioCodeCredential implements TokenCredential {
constructor(options?: VisualStudioCodeCredentialOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
getToken(scopes: string | string[], _options?: GetTokenOptions): Promise<AccessToken | null>;
}

// @public
Expand Down
6 changes: 1 addition & 5 deletions sdk/identity/identity/src/client/identityClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
RequestPrepareOptions,
GetTokenOptions,
createPipelineFromOptions,
isNode,
OperationArguments,
OperationSpec,
RawHttpHeaders,
HttpHeaders
isNode
} from "@azure/core-http";
import { INetworkModule, NetworkRequestOptions, NetworkResponse } from "@azure/msal-node";

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

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

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredential, AccessToken } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { credentialLogger, formatError } from "../util/logging";

Expand All @@ -28,22 +26,12 @@ export class AuthorizationCodeCredential implements TokenCredential {
redirectUri: string,
options?: TokenCredentialOptions
);
constructor(
tenantId: string | "common",
clientId: string,
clientSecretOrAuthorizationCode: string,
authorizationCodeOrRedirectUri: string,
redirectUriOrOptions: string | TokenCredentialOptions | undefined,
options?: TokenCredentialOptions
) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

public getToken(
scopes: string | string[],
options?: GetTokenOptions
): Promise<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

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

import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { AccessToken, TokenCredential } from "@azure/core-http";
import { credentialLogger, formatError } from "../util/logging";

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

export class AzureCliCredential implements TokenCredential {
constructor(options?: TokenCredentialOptions) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null> {
getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/identity/identity/src/credentials/azureCliCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ export class AzureCliCredential implements TokenCredential {
* Gets the access token from Azure CLI
* @param resource The resource to use when getting the token
*/
protected async getAzureCliAccessToken(resource: string) {
protected async getAzureCliAccessToken(
resource: string
): Promise<{ stdout: string; stderr: string; error: Error | null }> {
return new Promise((resolve, reject) => {
try {
child_process.exec(
`az account get-access-token --output json --resource ${resource}`,
{ cwd: getSafeWorkingDir() },
(error, stdout, stderr) => {
resolve({ stdout: stdout, stderr: stderr });
resolve({ stdout: stdout, stderr: stderr, error });
}
);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

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

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { TokenCredential, AccessToken } from "@azure/core-http";
import { credentialLogger, formatError } from "../util/logging";

const BrowserNotSupportedError = new Error(
Expand All @@ -13,20 +10,12 @@ const BrowserNotSupportedError = new Error(
const logger = credentialLogger("ClientCertificateCredential");

export class ClientCertificateCredential implements TokenCredential {
constructor(
tenantId: string,
clientId: string,
certificatePath: string,
options?: TokenCredentialOptions
) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

public getToken(
scopes: string | string[],
options?: GetTokenOptions
): Promise<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

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

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { DeviceCodePromptCallback } from "./deviceCodeCredential";
import { TokenCredentialOptions } from "../client/identityClient";
import { TokenCredential, AccessToken } from "@azure/core-http";
import { credentialLogger, formatError } from "../util/logging";

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

export class DeviceCodeCredential implements TokenCredential {
constructor(
tenantId: string | "organizations",
clientId: string,
userPromptCallback: DeviceCodePromptCallback,
options?: TokenCredentialOptions
) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

public getToken(
scopes: string | string[],
options?: GetTokenOptions
): Promise<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
12 changes: 5 additions & 7 deletions sdk/identity/identity/src/credentials/deviceCodeCredential.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { AccessToken, TokenCredential, GetTokenOptions, delay } from "@azure/core-http";
import { TokenCredentialOptions, IdentityClient } from "../client/identityClient";
import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { createSpan } from "../util/tracing";
import { credentialLogger, formatSuccess } from "../util/logging";
import { AuthenticationError, AuthenticationErrorName } from "../client/errors";
import { credentialLogger } from "../util/logging";
import { AuthenticationErrorName } from "../client/errors";
import { CanonicalCode } from "@opentelemetry/api";

import { PublicClientApplication, DeviceCodeRequest } from "@azure/msal-node";
Expand Down Expand Up @@ -55,7 +55,6 @@ export function defaultDeviceCodePromptCallback(deviceCodeInfo: DeviceCodeInfo):
* that the user can enter into https://microsoft.com/devicelogin.
*/
export class DeviceCodeCredential implements TokenCredential {
private identityClient: IdentityClient;
private pca: PublicClientApplication;
private tenantId: string;
private clientId: string;
Expand All @@ -79,7 +78,6 @@ export class DeviceCodeCredential implements TokenCredential {
userPromptCallback: DeviceCodePromptCallback = defaultDeviceCodePromptCallback,
options?: TokenCredentialOptions
) {
this.identityClient = new IdentityClient(options);
this.tenantId = tenantId;
this.clientId = clientId;
this.userPromptCallback = userPromptCallback;
Expand Down Expand Up @@ -117,7 +115,7 @@ export class DeviceCodeCredential implements TokenCredential {
* TokenCredential implementation might make.
*/
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null> {
const { span, options: newOptions } = createSpan("DeviceCodeCredential-getToken", options);
const { span } = createSpan("DeviceCodeCredential-getToken", options);

const scopeArray = typeof scopes === "object" ? scopes : [scopes];

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

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

import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { AccessToken, TokenCredential } from "@azure/core-http";
import { credentialLogger, formatError } from "../util/logging";

const BrowserNotSupportedError = new Error(
Expand All @@ -13,12 +10,12 @@ const BrowserNotSupportedError = new Error(
const logger = credentialLogger("EnvironmentCredential");

export class EnvironmentCredential implements TokenCredential {
constructor(options?: TokenCredentialOptions) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null> {
getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
InteractiveBrowserCredentialOptions,
AuthenticationRecord
} from "./interactiveBrowserCredentialOptions";
import { credentialLogger, formatError } from "../util/logging";
import { TokenCredentialOptions, IdentityClient } from "../client/identityClient";
import { credentialLogger } from "../util/logging";
import { IdentityClient } from "../client/identityClient";
import { DefaultTenantId, DeveloperSignOnClientId } from "../constants";
import { Socket } from "net";

Expand All @@ -21,7 +21,6 @@ import {
Configuration
} from "@azure/msal-node";
import open from "open";
import path from "path";
import http from "http";
import { CredentialUnavailable } from "../client/errors";

Expand Down Expand Up @@ -105,7 +104,7 @@ export class InteractiveBrowserCredential implements TokenCredential {
*/
public getToken(
scopes: string | string[],
options?: GetTokenOptions
_options?: GetTokenOptions
): Promise<AccessToken | null> {
const scopeArray = typeof scopes === "object" ? scopes : [scopes];

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

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

import { AccessToken, GetTokenOptions, TokenCredential } from "@azure/core-http";
import { AccessToken, TokenCredential } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { credentialLogger, formatError } from "../util/logging";

Expand All @@ -15,18 +13,12 @@ const logger = credentialLogger("ManagedIdentityCredential");
export class ManagedIdentityCredential implements TokenCredential {
constructor(clientId: string, options?: TokenCredentialOptions);
constructor(options?: TokenCredentialOptions);
constructor(
clientIdOrOptions: string | TokenCredentialOptions | undefined,
options?: TokenCredentialOptions
) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

public async getToken(
scopes: string | string[],
options?: GetTokenOptions
): Promise<AccessToken | null> {
public async getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

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

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredentialOptions } from "../client/identityClient";
import { TokenCredential, AccessToken } from "@azure/core-http";
import { credentialLogger, formatError } from "../util/logging";

const BrowserNotSupportedError = new Error(
Expand All @@ -13,15 +10,12 @@ const BrowserNotSupportedError = new Error(
const logger = credentialLogger("VisualStudioCodeCredential");

export class VisualStudioCodeCredential implements TokenCredential {
constructor(options?: TokenCredentialOptions) {
constructor() {
logger.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}

public getToken(
scopes: string | string[],
options?: GetTokenOptions
): Promise<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

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

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredential, AccessToken, GetTokenOptions } from "@azure/core-http";
import { TokenCredentialOptions, IdentityClient } from "../client/identityClient";
import fs from "fs";
import os from "os";
Expand Down Expand Up @@ -142,7 +140,7 @@ export class VisualStudioCodeCredential implements TokenCredential {
*/
public async getToken(
scopes: string | string[],
options?: GetTokenOptions
_options?: GetTokenOptions
): Promise<AccessToken | null> {
await this.prepareOnce();
if (!keytar) {
Expand Down
2 changes: 2 additions & 0 deletions sdk/identity/identity/test/internal/identityClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ describe("IdentityClient", function() {
assert(new IdentityClient({ authorityHost: "https://correct.url" }));

delete process.env.AZURE_AUTHORITY_HOST;

return;
});

it("returns a usable error when the authentication response doesn't contain a body", async () => {
Expand Down
6 changes: 4 additions & 2 deletions sdk/identity/identity/test/mockAzureCliCredentialClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export class MockAzureCliCredentialClient extends AzureCliCredential {
* command.
* @param resource The resources to use when accessing token
*/
protected getAzureCliAccessToken(_resource: string): Promise<{ stdout: string; stderr: string }> {
protected getAzureCliAccessToken(
_resource: string
): Promise<{ stdout: string; stderr: string; error: Error | null }> {
return new Promise((resolve) => {
resolve({ stdout: this.stdout, stderr: this.stderr });
resolve({ stdout: this.stdout, stderr: this.stderr, error: null });
});
}
}
Loading