How to create a (Azure CLI) command line application in Angular - c#

How to a create command line (CLI) project. I like to add Azure CLI commands to end users in my Angular project. Presently I am tyring to do using C#. So please help me how to do CLI in Angular or C# to integrate my Azure CLI commands

You could run Azure CLI in C# like this:
string strCmdText;
strCmdText = "/C az login";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
/C: Carries out the command specified by string and then terminates.

Angular cannot directly run the CLI commands as this would be a security flaw in the browser.
If you were to acquire a user token from an app registration, you could call Microsoft Graph APIs on behalf of a user. Very detailed explanation on how to do this here: https://learn.microsoft.com/en-us/graph/tutorials/angular
The other option is to call a C# Web API and run Microsoft Graph or the Azure CLI from the web server. Microsoft Graph SDK is the preferred mechanism from C#, but you could also use System.Diagnostics.Process to launch and run Azure CLI commands.

Related

Azure Webjob: Git clone directly to remote

Im running a Windows-based App Service.
Im running a backup of a fairly large git repo and I'm wanting to clone directly to Azure Blob/File/S3. Cloning locally leads to an out-of-memory exception. I realise that you can mount azure storage, but this is just for Linux based apps.
Im using LibGit2Sharp ti run the Repository.Clone function. I've tried mapping a network drive on my Azure Webjob, but I get an "Access Denied"
When you create azure web app, if you choose option of Publish is Code, like below. It don't support net use command. These webapp are running in standard sandbox env.
Solution:
Create your web app like below. Docker Container will solve your problem.
Although the container webapp also runs in the sandbox environment, you can customize many configurations.
In local, I test net use command, which is same as windows container app.

Is it possible to install c++ compiler in azure app service

I have azure app service on Windows and I want to install c++ compiler on it.
I need the c++ compiler to compile and run c++ code runtime. The user submit some code(console application) I compile it and then run it with different inputs. I run command like g++ file.cpp for compilation and file.exe in cmd using Process class in c#.
Is there a way to connect remotely to my azure app service and install the c++ compiler? Or are there some other ways to install c++ compiler on azure app service?
No, you cannot install software (like your compiler) in an Azure App Service. https://stackoverflow.com/a/36185208/1537195
You would need to go to something like either your own container (see for example Azure Web App for Containers or Azure Container Instances) or host your custom code inside a VM.

How to use Azure CloudShell for Continuous Deployment

I am using CloudShell to deploy Azure Services using PowerShell Scripts. It's a great experience.Now I want to use CloudShell to automate deployment. I am maintaining a solution in TFS/VSTS.
Is there any way or workaround to call OR to get the CloudShell instance or to run Powershell on CloudShell using some Batch command or C# or else.
Is any CloudShell API exist to use CloudShell service from .Net
No, there's no API behind the CloudShell, but its just a bash shell that's using Azure CLI and Azure Powershell. You can use those on your own.
You can access the open source project for Azure Cloud Shell on github and run the Azure Cloud Shell container locally using docker. Not sure this meets your need, but it's a cool option nonetheless.
As per my knowledge, Azure Cloud is an interactive, browser-accessible for managing Azure resources. You cannot use Azure Cloud Shell for Continuous Deployment.
Note: Azure Cloud Shell is an interactive, browser-accessible shell for managing Azure resources. It gives you the flexibility of choosing the shell experience that best suits the way you work. Linux users can opt for a Bash experience, while Windows users can opt for PowerShell.
For more details, refer "Overview of Azure Cloud Shell (Preview)"

How to restart Azure Web App programmatically

Is any way to restart the Azure Web App programmatically, i.e. Kudu or some another kind?
I'v found that it is possible using Management Libraries, but it is not applicable for me since I can't create application in AD.
Powershell:
Restart-AzureRmWebApp -ResourceGroupName xxx -Name xxx
or using the provider operation:
Invoke-AzureRmResourceAction -ResourceGroupName xxx -ResourceType 'Microsoft.Web/sites' -ResourceName xxx `
-ApiVersion '2015-08-01' -Action 'Restart' -Force
Azure Cli (nodejs, depreciated):
azure webapp restart --resource-group xxx --name xxx
Azure Cli (python):
az appservice web restart --resource-group xxx --name xxx
or you can use Rest Api
I'm assuming you're looking for this feature because you or folks on your team don't have elevated permissions on the Azure Portal.
Creating scripts will work, but it still requires someone to be comfortable with running command lines.
The best way I found to do this is with VSTS pipeline. A few clicks and it's restarted. A simple and awesome way to build a devops culture.
Check out this answer, which uses a LogicApp to make it a nice lightweight way to restart your web-app: https://stackoverflow.com/a/59633629/44815

How to run Office365 powershell in Azure Webjob?

I have a program which uses Office 365 Powershell to query O365 information. it works fine. Now, we want to use Azure and put this part into a webjob.
Now, we can pass the credentail into the powershell (using C# code), but when it runs as a webjob, it always shows error, see the screen shot. It says that the cmdlet is not recognized.
I know even on our local machine, we will need to install Windows Azure Active Directory Module to run Office365 powershell. Could the error be because in the Azure, it does not have this module?
So the question is: is there a way to install/integrate this into Azure webjob? or, is there other way that we could run Office 365 powershell in Azure webjob?
Thanks

Categories

Resources