Code Monkey home page Code Monkey logo

Comments (33)

yungez avatar yungez commented on May 17, 2024 1

@chrmarti thanks for replying. We need a way to run commands and show user the output.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

There is currently no way to do this. What kind of commands do you want to send? Could you use the Azure SDK to achieve the same? The Account extension has API with the credentials object for the Azure SDK.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

I guess I cannot use Azure SDK to do that. I would like to send some terraform command to the cloud shell.

from vscode-azure-account.

vscodebot avatar vscodebot commented on May 17, 2024

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

@chrmarti thanks for reopen it. If this can be supported, there is no need for me to copy-paste your cloud shell code to my extension.

As far as I know, there are several extensions that are using azure cloud shell. It will be great if we can get the terminal instance from azure-account-extension.

from vscode-azure-account.

yungez avatar yungez commented on May 17, 2024

we have same request on cloud shell sdk supporting. We're building vscode ansible extension, ansible is also runnable from cloudshell. we'd like to see features like:

  1. upload files to cloudshell
  2. get cloud shell terminal instance or at least cloud shell connection status.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

Are you looking for a way to only run commands or do you also need the terminal UI to show the user the output and maybe collect input?

I'm not aware of a way to upload files to the Cloud Shell. @jluk Is there a REST API for that?

from vscode-azure-account.

jluk avatar jluk commented on May 17, 2024

There is not today, but this is something we have been reviewing. Adding @yangl900 as FYI.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

I have pushed (not published yet) a draft of such an API. Let me know if that looks like it would cover your use case: https://github.com/Microsoft/vscode-azure-account/blob/1686b7cb6f544732723da70bd87fc164d44ccb93/src/azure-account.api.d.ts#L29

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Hi @chrmarti I've tested the new API on my machine. And that works! Really appreciated!

About the upload files to Cloud Shell. If it is impossible for now. Could we add more fields about the cloud shell's storage account information in the returned CloudShell object. Then we can do the uploading by ourselves.

What we need are:

  1. the resource group of the storage account
  2. the storage account name
  3. the fileshare name
  4. the storage account key

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

I would not feel comfortable exposing these details from the Cloud Shell's configuration. I have instead added a session property to this experimental API that you can use to look up the configuration yourself. You could copy the following code to do so:

  1. Extract a token from the session: https://github.com/Microsoft/vscode-azure-account/blob/b78b7ecba7c395990ad17f906de907835442338e/src/cloudConsole.ts#L321
  2. Fetch the configuration: https://github.com/Microsoft/vscode-azure-account/blob/b78b7ecba7c395990ad17f906de907835442338e/src/cloudConsoleLauncher.ts#L28

Hope that works for you. I have also reduced the number of status values and made the terminal and session properties promises.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

@chrmarti I agree with what you said. I'll try for this ASAP and tells you if it works on my side. Thanks.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

@jdneo Just published a bugfix release of the extension that includes this experimental API. We can promote it to 'stable' (moving it up from the 'experimental' property) after this round of feedback.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Hi @chrmarti

I changed my code according to your suggestion as following:

...
const accountAPI: AzureAccount = vscode.extensions
                .getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;

const cloudShell: CloudShell =  accountAPI.experimental.createCloudShell("Linux");
this.tfTerminal.terminal = await cloudShell.terminal;

const storageAccount: IStorageAccount = await getStorageAccountforCloudShell(cloudShell);
...

And this is the screenshot when I debug my code:
image

As you can see, though we await for the terminal, but after the promise is resolved, the status of cloudshell is still connecting. Is this by design?

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

Yes, the terminal is available while the connection is still being set up (we show progress messages in the terminal during connection setup). You should be able to access the storage account as soon as the session promise resolves (which is also while the status is still 'Connecting').

Before sending text to the terminal, you would probably wait for the status to change to 'Connected'. (Also note that the terminal will not show until you call .show() on it, which you can do immediately or later, as works best for you.)

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

I could add a waitForConnection function returning a Promise<boolean> that resolves to true when the connection is available and false when the connection failed. That would align with other parts of the API and make it easier to start sending text.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Thanks, waitForConnection() looks good to me.

And FYI, just as you said, the the storage account can be accessed as soon as the session promise resolves.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

You could use this code until the next release:

async function waitForConnection(cloudShell: CloudShell) {
	const handleStatus = () => {
		switch(cloudShell.status) {
			case 'Connecting':
				return new Promise<boolean>(resolve => {
					const subs = cloudShell.onStatusChanged(() => {
						subs.dispose();
						resolve(handleStatus());
					});
				});
			case 'Connected':
				return true;
			case 'Disconnected':
				return false;
			default:
				const status: never = cloudShell.status;
				throw new Error(`Unexpected status '${status}'`);
		}
	};
	return handleStatus();
}

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Thanks for the information.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Hi @chrmarti . May I ask when will you remove the experimental property for this API. I'm thinking that if I published the extension using this API, the extension may break when the Azure-Account is updated to remvoe the experimental property. Do you have any suggestions on this?

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

@jdneo I can move it up when you confirm that it works for your use cases.

@yungez Did you have a chance to give it a try?

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Yes it works fine for my use cases now. Thanks!

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

Took the opportunity of a bug fix release to move this out of experimental.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

@jdneo I have pushed an addition to the API for uploading files to the master branch. Could you check if that will work for you: https://github.com/Microsoft/vscode-azure-account/blob/f0846fc601554ddb3f945e34e6a85551b705fca7/src/azure-account.api.d.ts#L57

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

@chrmarti Awesome! I'm trying to local generate the vsix file and install the extension locally, but it always need me to reload the VS Code, seems the extension cannot be started up. Do you have any idea on that?


Oh, that is because the engines defined in package.json is an unreleased version of vscode. After change it to 1.21.0, everything works fine. I'll check the new API later.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

@jdneo The extension uses new API from 1.22. It should run fine with the 1.22 insiders release of VS Code.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

Thanks for the information. I was just directly calling the Azure: Upload to Cloud Shell to understand the behavior, but seems nothing happened. 😢

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

Is there anything in the console? (Help > Toggle Developer Tools)

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

yes, Bad progress location: undefined

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

Maybe you need to rebuild the vsix with the engine set to 1.22 first? I just tried and it works for me.

from vscode-azure-account.

jdneo avatar jdneo commented on May 17, 2024

I see. Just as you have said. After rebuilding the vsix and install it in VS Code Insider, everything works fine.

I just have one question:

Seems currently we will always upload files to the $HOME folder. Is it possible that if we can specify the path for each file. For example clouddrive/myprojet/file.txt. Here clouddrive is the Azure File Share mounted by Cloud Shell.

from vscode-azure-account.

chrmarti avatar chrmarti commented on May 17, 2024

That seems to be a limitation of the Upload API. @jluk Is there a way to upload files to a different folder than the home folder?

from vscode-azure-account.

jluk avatar jluk commented on May 17, 2024

Not right now, bash supports pushing to $home and PS supports pushing to $clouddrive. We'll be improving this down the road, but this is the case for now.

from vscode-azure-account.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.