Giter VIP home page Giter VIP logo

azure-api-sh's Introduction

Sample Shell scripts for Microsoft's Azure API

Pre-requisites:

  1. Tools already installed:
  • curl
  • jq
  • Azure Cli (v2.0) (az)
  1. Existing user with enough permissions for creating Azure API access "Service Principal" for APPs

Example:

  1. Create with Azure CLI (v2.0), having APP "get_billing_az" with secret: "modifythispass", "Reader" role with 1 year of valid login. (Note that script "create_app_login.sh" executes the following actions by asking needed info and creating azure_login.cfg):

$ az login # Log with your own credentials

$ az ad sp create-for-rbac --name get_billing_az --password modifythispass --role Reader --years 1 -o json

  1. Take note of tenant_id and app_id
  2. Modify APPs permissions [*]:

[*] Reference: https://github.com/Azure/azure-docs-cli-python/blob/master/docs-ref-conceptual/create-an-azure-service-principal-azure-cli.md


ToDo:

  1. The user should be assigned to a custom role with access only to list resources, get price listing, get consumption (Current permissions: Reader).

Restrictions should apply to /resources, /providers/Microsoft.Commerce/RateCard, /providers/Microsoft.Commerce/UsageAggregates

  1. Instead of using password, it's better to use certificates (Advanced).

For retrieving again the info from created Service Principal:

  • Tenant Id. (It will show info about current logged account, including tenant id)

az account list --output json --query '[].{Name:name, SubscriptionId:id, TenantId:tenantId}' | jq -r '.[].TenantId'

  • App Id. (It will show your AppId assigned value)

az ad sp list --display-name "<app_name>" | jq -r '.[].appId'

  • For removing Service Principal Account:

az ad sp delete --id <app_id>

  • Subscription Id:

az account list | jq -r '.[].id'

  • azure_login.cfg format:

app_id="<your registered app id>"
client_secret="modifythispass"
subscription_id="<your subscription id>"
tenant_id="<your tenant id>"

References: https://medium.com/@mauridb/calling-azure-rest-api-via-curl-eb10a06127


Available scripts:

EXECUTE FIRST! (MANDATORY):
Use as needed (optional):

azure-api-sh's People

Contributors

pcarboni avatar

Watchers

Diego Dell'Era avatar Toby Matejovsky avatar David Waizer avatar Gustavo Arjones avatar James Cloos avatar Borislav Iordanov avatar Sue avatar Pablo Romanelli avatar Juan Marcos Enriquez avatar

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.