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

#712: Azure CLI integration #741

Merged
merged 19 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
2 changes: 2 additions & 0 deletions documentation/LICENSE.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ The following table shows the components that may be used. The column `inclusion
|https://helm.sh/[helm]|Optional|https://github.com/devonfw/ide/blob/master/LICENSE[ASL 2.0]
|https://terraform.io/[terraform]|Optional|https://github.com/hashicorp/terraform/blob/main/LICENSE[Mozilla Public License 2.0]
|https://www.graalvm.org/[GraalVM] |Optional|https://github.com/oracle/graal/blob/master/LICENSE[GPLv2] (with the “Classpath” Exception)
|https://github.com/Azure/azure-cli[AzureCLI] |Optional| https://github.com/Azure/azure-cli/blob/dev/LICENSE[MIT]

|=======================

== Apache Software License - Version 2.0
Expand Down
50 changes: 50 additions & 0 deletions documentation/az.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
:toc:
toc::[]

= Azure CLI

The Azure CLI commandlet allows to install and use https://github.com/Azure/azure-cli[Azure CLI].

*ATTENTION:*
Currently this feature is new and therefore experimental.
It may change in incompatible ways in the next releases until we reach a stable state.
We hope that all is working fine for you.
However, do not expect everything to work out of the box.
In case you are facing issues (e.g. network problems with Cisco AnyConnect, etc.) please give us feedback so we can improve.
alfeilex marked this conversation as resolved.
Show resolved Hide resolved

The arguments (`devon az «args»`) are explained by the following table:

.Usage of `devon az`
[options="header"]
|=======================
|*Argument(s)* |*Meaning*
|`setup` |setup Azure CLI (install and verify) as per above flow.
|`«args»` |call Azure CLI with the specified arguments. Call `az help` for details or use `az` directly as preferred." (`«args»`)
|=======================

== Setup
The `az` commandlet will install Azure CLI automatically. Windows user must confirm the User Access Control to run the installation as administrator.
Please note that besides the sandbox concept of devonfw-ide this is a global installation on your system.
When uninstalling Azure CLI, you may have to manually uninstall.

**Uninstall process instructions:**

- https://docs.microsoft.com/de-de/cli/azure/install-azure-cli-windows?tabs=azure-cli#uninstall[Windows]

- https://docs.microsoft.com/de-de/cli/azure/install-azure-cli-linux?pivots=script#uninstall[MacOS and Linux]

== Requirements
**MacOS and Linux users requires the following software:**

- https://www.python.org/downloads/[Python 3.6.x, 3.7.x oder 3.8.x]
- https://sourceware.org/libffi/[libffi]
- https://www.openssl.org/source/[OpenSSL 1.0.2]
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
alfeilex marked this conversation as resolved.
Show resolved Hide resolved

== Configuration File
The configuration file is located at `conf/.azure`. Don't forget to set the environment variables of your IDE with `devon` before setting new configurations for Azure.

== Usage
After the installation is complete, you may need to restart the console. Run `az help` from any shell of your OS directly to get started and use the online documentations and resources on the web to get familiar with Azure CLI. It is not our intention to repeat this here.

Please note that the `az` commandlet is a link:cli.asciidoc#command-wrapper[command wrapper].

3 changes: 2 additions & 1 deletion documentation/cli.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ However, when you automate and want to avoid "command not found" errors, you can

The following commandlets are currently available:

* link:az.asciidoc[az]
* link:build.asciidoc[build]
* link:cobigen.asciidoc[cobigen]
* link:docker.asciidoc[docker]
Expand All @@ -73,4 +74,4 @@ The following commandlets are currently available:
* link:sonar.asciidoc[sonar]
* link:terraform.asciidoc[terraform]
* link:vscode.asciidoc[vscode]
* link:yarn.asciidoc[yarn]
* link:yarn.asciidoc[yarn]
2 changes: 2 additions & 0 deletions documentation/devonfw-ide-usage.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ include::variables.asciidoc[leveloffset=2]

include::cli.asciidoc[leveloffset=2]

include::az.asciidoc[leveloffset=3]

include::build.asciidoc[leveloffset=3]

include::docker.asciidoc[leveloffset=3]
Expand Down
1 change: 1 addition & 0 deletions documentation/scripts.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This directory is the heart of the `devonfw-ide` and contains the required link:
----
/scripts
├──/ https://github.com/devonfw/ide/tree/master/scripts/src/main/resources/scripts/command[command]
│ ├── link:az.asciidoc[az]
│ ├── link:build.asciidoc[build]
│ ├── link:docker.asciidoc[docker]
│ ├── link:eclipse.asciidoc[eclipse]
Expand Down
136 changes: 136 additions & 0 deletions scripts/src/main/resources/scripts/command/az
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env bash

# autocompletion list
if [ "${1}" = "shortlist" ]
then
if [ -z "${2}" ]
then
echo "setup help"
fi
exit
fi

if [ -n "${DEVON_IDE_TRACE}" ]; then set -vx; fi
# shellcheck source=scripts/functions
source "$(dirname "${0}")"/../functions

function doSetup() {
if doIsAzureInstalled
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
then
if [ "${1}" != "silent" ] && ! doIsQuiet
then
doEcho "Azure CLI is already installed at $(command -v az)"
fi
else
doRequireNotBatch
if doIsWindows
then
# Get leatest release
if [ -z "${AZURECLI_VERSION}" ]
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
then
doEcho "Getting latest release..."
AZURECLI_VERSION=$(curl -s https://api.github.com/repos/Azure/azure-cli/releases/latest | awk -F ":" '/tag_name/ {print $2}'| awk -F "\"" '{print $2}' | awk -F "-" '{print $3}')
fi
local version="${AZURECLI_VERSION}"
doDownload "-" "" "az" "${version}"
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
# Install Azure CLI for Windows
doEcho "Installing Azure CLI for Windows..."
modifyPathStructure
installOnWindows
else doFail "Sorry, Azure CLI installation support is not yet implemented for your OS. Please install manually or help devonfw-ide to support it for your OS by contributing a pull-request."
fi
fi
}

# modify a filepath for powershell path syntax e.g. /c/... -> c:/...
function modifyPathStructure(){
modifiedPath=${DEVON_DOWNLOAD_DIR}
partition=$(echo "${modifiedPath}" | cut -f2 -d'/'):'/' # -> <partition>:/
modifiedPath=${partition}$(echo "${modifiedPath}" | cut -f3- -d'/')
modifiedPath="${modifiedPath//'/'/'\'}"
}

# Install Azure CLI for Windows via Powershell Command
function installOnWindows(){
powershell.exe -Command "Start-Process msiexec.exe -verb runas -Wait -ArgumentList '/I ${modifiedPath}\az-${version}-windows.msi /QB-!'" &> /dev/null || exit_code=$?
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
if [[ -z "${exit_code}" ]]
then
setConfigDir
doEcho "Azure CLI has been installed and is ready to use. \n\n******** IMPORTANT ******** \nRestart the console to use Azure CLI regular."
else
read -r -p "You must run the installation with administration rights. Would you like to start the installation again? (Y/n)" answer
case ${answer:0:1} in
y|Y )
doEcho "\nInstalling Azure CLI for Windows..."
exit_code=""
installOnWindows
;;
* )
doEcho "The installation has been canceled."
;;
esac
fi
}

# Set directory for azure cli configuration file
function setConfigDir() {
azurecli_export="export AZURE_CONFIG_DIR=${DEVON_IDE_HOME}/conf/.azure"
if ! grep -q "${azurecli_export}" "${DEVON_IDE_HOME}/conf/devon.properties"
then
doRunCommand "export AZURE_CONFIG_DIR=${DEVON_IDE_HOME}/conf/.azure"
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
echo -e "\n${azurecli_export}" >> "${DEVON_IDE_HOME}/conf/devon.properties"
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
doEcho "Location of Azure's configuration file is set to ${DEVON_IDE_HOME}/conf/.azure"
fi
alfeilex marked this conversation as resolved.
Show resolved Hide resolved

}

# OS independet check if Azure CLI is installed
function doIsAzureInstalled() {
if command -v az &> /dev/null
then
return
else
return 255
fi
}

function doRun() {
doSetup silent
doEcho "Running: Azure CLI ${*}"
setConfigDir
az "${@}"
}

# CLI
case ${1} in
"help" | "-h")
echo "Install Azure CLI."
echo
echo "Arguments:"
echo " setup install Azure CLI on your machine (global installation)."
echo " <<args>> call Azure CLI with the specified arguments. Call az --help for details or use Azure CLI directly as preferred."
echo
;;

"setup" | "s")
doEcho "Installing Azure CLI..."
doSetup
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
;;

"")
if ! doIsAzureInstalled
then
doEcho "Installing Azure CLI..."
doSetup
else doRun "${@}"
fi
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
;;

*)
if doIsAzureInstalled
then
doRun "${@}"
else doEcho "Unknown argument "
fi
alfeilex marked this conversation as resolved.
Show resolved Hide resolved
;;
esac