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

Bicep deploy - fix bicep login and filename with space issue #6283

Merged
merged 10 commits into from
Mar 28, 2022

Conversation

bhsubra
Copy link
Contributor

@bhsubra bhsubra commented Mar 24, 2022

  • Fix login issue. This is a workaround for https://github.com/Azure/azure-sdk-for-net/issues/27263. Instead of relying on the sdk to get the credentials, we will now get the token from subscription and pass it on to language server layer and use it in creating ArmClient. We will also be masking the credentials information in trace logs.
  • Fix filename with space issue

@bhsubra bhsubra marked this pull request as draft March 24, 2022 18:27
@bhsubra bhsubra marked this pull request as ready for review March 24, 2022 19:11
@@ -74,7 +72,9 @@ export class DeployCommand implements Command {
}

const documentPath = documentUri.fsPath;
const textDocument = TextDocumentIdentifier.create(documentUri.fsPath);
const textDocument = TextDocumentIdentifier.create(
encodeURIComponent(documentUri.path)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles scenario when there are spaces in folder name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to add comment (spaces or other special characters)

@bhsubra bhsubra linked an issue Mar 24, 2022 that may be closed by this pull request
@bhsubra bhsubra changed the title Bicep deploy - fix bicep login issue Bicep deploy - fix bicep login and filename with space Mar 24, 2022
@bhsubra bhsubra changed the title Bicep deploy - fix bicep login and filename with space Bicep deploy - fix bicep login and filename with space issue Mar 24, 2022
@bhsubra bhsubra force-pushed the dev/bhsubra/FixLoginIssueDuringDeploy branch from 93ed93e to 1b5962d Compare March 25, 2022 05:27
@bhsubra bhsubra closed this Mar 25, 2022
@bhsubra bhsubra reopened this Mar 25, 2022
'Params: {\n "textDocument": {\n "uri": "someUri"\n }, "token": "eyJ0eXAi",\n "expiresOnTimestamp": "1648143343698"\n}';
const actual = removePropertiesWithPossibleUserInfoInDeployParams(value);
const expected =
'Params: {\n "textDocument": {\n "uri": "someUri"\n }, "token": "<REDACTED: token>",\n "expiresOnTimestamp": "<REDACTED: expiresOnTimestamp>"\n}';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we really need to redact timestamp?


public appendLine(value: string): void {
const updatedValue =
removePropertiesWithPossibleUserInfoInDeployParams(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not thrilled about this implementation, but it's good enough for now. And at least it's clear what it's doing.

{
public class CredentialFromTokenAndTimeStamp : TokenCredential
{
private AccessToken _accessToken;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit]: The convention for our repo is to not use the _ prefix in field names.

export function removePropertiesWithPossibleUserInfoInDeployParams(
value: string
): string {
const deployParamsPattern = new RegExp('.*"token":\\s*"(?<token>.*)"');
Copy link
Contributor

@shenglol shenglol Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use /.*"token":\\s*"(?<token>.*)"/ instead of the RegExp constructor so V8 can cache it. An alternative way is to make the regex a file level constant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, using a regex literal is better.

import { AccessToken } from "@azure/identity";
import { AzLoginTreeItem } from "../tree/AzLoginTreeItem";
import { AzManagementGroupTreeItem } from "../tree/AzManagementGroupTreeItem";
import { AzResourceGroupTreeItem } from "../tree/AzResourceGroupTreeItem";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit]: Consider creating a barrel index.ts under the tree folder to simplify the imports (can be done in a seperate PR though).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shenglol Frankly I'm not convinced this is worth the effort. What advantage does it give?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a way to simplify the imports, so instead of doing

import { X } from "foo/x";
import { Y } from "foo/y;
import { Z } from "foo/z;

we can just do

import { X, Y, Z } from "foo";

I don't have a strong opinion on this but thought this can save a few of lines.

@bhsubra bhsubra requested a review from shenglol March 25, 2022 23:12
Copy link
Contributor

@shenglol shenglol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@bhsubra bhsubra merged commit 8780a2d into main Mar 28, 2022
@bhsubra bhsubra deleted the dev/bhsubra/FixLoginIssueDuringDeploy branch March 28, 2022 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deployment fails if filename contains a space
3 participants