<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saravanan Lakshmanan</title>
    <description>The latest articles on DEV Community by Saravanan Lakshmanan (@ssan79).</description>
    <link>https://dev.to/ssan79</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3664193%2Fd9c2c198-7a95-4837-ac92-11e6c783fabf.jpeg</url>
      <title>DEV Community: Saravanan Lakshmanan</title>
      <link>https://dev.to/ssan79</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ssan79"/>
    <language>en</language>
    <item>
      <title>Azure CLI internals and how it works</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Tue, 16 Dec 2025 06:09:07 +0000</pubDate>
      <link>https://dev.to/ssan79/azure-cli-internals-and-how-it-works-330o</link>
      <guid>https://dev.to/ssan79/azure-cli-internals-and-how-it-works-330o</guid>
      <description>&lt;p&gt;Azure CLI is a command line tool built with Python that sends REST API requests to Azure Resource Manager. The tool packages command modules, a core engine, authentication logic, and an HTTP pipeline. Each command follows a consistent pattern: parse input, authenticate, build a request model, send the request to Azure, and return structured output in JSON or table format.&lt;br&gt;
**&lt;br&gt;
Architecture overview**&lt;br&gt;
Azure CLI has two major layers: the CLI core and the command modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The CLI core includes:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Command loader&lt;/p&gt;

&lt;p&gt;Parser engine&lt;/p&gt;

&lt;p&gt;Authentication subsystem&lt;/p&gt;

&lt;p&gt;HTTP pipeline&lt;/p&gt;

&lt;p&gt;Output formatter&lt;/p&gt;

&lt;p&gt;Telemetry engine&lt;/p&gt;

&lt;p&gt;Command modules provide commands for specific Azure services such as Compute, Storage, Key Vault, and Networking. Each module maps its commands to operations in the Azure REST API or the Azure SDK for Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Command loading&lt;/strong&gt;&lt;br&gt;
The CLI core identifies installed command modules during startup. The loader reads the command table that each module exposes. The command table maps a command name to an operation handler. For example, “az vm create” maps to a Python function in the Compute module that prepares the request body for the Virtual Machines REST API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parsing and command routing&lt;/strong&gt;&lt;br&gt;
The CLI uses the knack parser (part of the azure-cli-core package). The parser resolves the command group, maps flags and arguments to parameters, applies default values, and validates required parameters. After parsing, the router identifies the function that implements the command.&lt;/p&gt;

&lt;p&gt;Error messages, argument conflicts, and type conversions are handled in the parser before any network call is made.&lt;/p&gt;

&lt;p&gt;Request construction&lt;br&gt;
Once the target handler function runs, it builds a request model using either:&lt;/p&gt;

&lt;p&gt;Direct REST payloads, or&lt;/p&gt;

&lt;p&gt;Azure SDK for Python data models such as ComputeManagementClient, StorageManagementClient, or KeyVaultManagementClient.&lt;/p&gt;

&lt;p&gt;Older parts of Azure CLI use handwritten REST calls. Newer modules use the Azure SDK for Python, which generates clients from the swagger-based Azure REST API definitions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication flow&lt;/strong&gt;&lt;br&gt;
Authentication is managed by the Azure Identity library. The CLI stores authentication tokens in the Azure CLI token cache file located in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`

Linux and macOS: ~/.azure/msal_token_cache.jsonWindows: %USERPROFILE%.azure\msal_token_cache.json
Azure CLI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;supports:&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Device login&lt;/p&gt;

&lt;p&gt;Browser-based login&lt;/p&gt;

&lt;p&gt;Service principal with secret&lt;/p&gt;

&lt;p&gt;Service principal with certificate&lt;/p&gt;

&lt;p&gt;Managed identity when running inside Azure&lt;/p&gt;

&lt;p&gt;Azure CLI uses MSAL to obtain and refresh tokens. Tokens are added to the Authorization header as “Bearer ” in every request to Azure Resource Manager.&lt;/p&gt;

&lt;p&gt;HTTP pipeline&lt;br&gt;
The CLI uses the msrest pipeline or Azure Core pipeline, depending on whether the command uses older or newer SDK clients. The pipeline consists of:&lt;/p&gt;

&lt;p&gt;Authentication policy&lt;/p&gt;

&lt;p&gt;User agent policy&lt;/p&gt;

&lt;p&gt;Retry policy&lt;/p&gt;

&lt;p&gt;HTTP logging policy&lt;/p&gt;

&lt;p&gt;Transport layer (Requests library by default)&lt;/p&gt;

&lt;p&gt;Each request is sent to: &lt;a href="https://management.azure.com/?api-version=Azure" rel="noopener noreferrer"&gt;https://management.azure.com/?api-version=Azure&lt;/a&gt; Resource Manager validates the token, processes the request, and returns a JSON response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output formatting&lt;/strong&gt;&lt;br&gt;
Azure CLI supports JSON, JSONC, table, TSV, and YAML. Formatting is handled by the CLI core after the HTTP response is received. Table and TSV formats rely on flattening rules that convert nested REST responses into simple rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Internals mind map&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywfne3vhr8koui9pohnb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywfne3vhr8koui9pohnb.png" alt=" " width="800" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Azure CLI differs from Azure Portal?&lt;/strong&gt;&lt;br&gt;
Azure Portal is a graphical interface built on top of the same Azure Resource Manager REST APIs. Both tools trigger the same backend operations. The difference lies in how actions are executed and exposed to the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution path&lt;/strong&gt;&lt;br&gt;
Azure CLI constructs and sends REST calls directly from your machine or Cloud Shell.&lt;/p&gt;

&lt;p&gt;Azure Portal sends REST calls through user actions in the browser, which are translated by the portal’s front end into REST API calls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State handling&lt;/strong&gt;&lt;br&gt;
Azure CLI is stateless per command. Each command is independent.&lt;/p&gt;

&lt;p&gt;Azure Portal maintains client state within the browser session. It tracks UI context, browsing history, and cached resource metadata.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automation capability&lt;/strong&gt;&lt;br&gt;
Azure CLI can be used inside scripts, pipelines, scheduled jobs, and automation servers. Azure Portal is manual and interaction based.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovery and guidance&lt;/strong&gt;&lt;br&gt;
Azure Portal offers visual menus, blades, and step based wizards for many resources. Azure CLI presents documentation and inline help using “az find”, “az  –help”, and autogenerated examples.&lt;br&gt;
**&lt;br&gt;
Resource update model**&lt;br&gt;
Azure CLI updates resources through patch or put operations based on REST API service rules. Azure Portal may combine several operations behind one UI action. For example, creating a VM with defaults triggers multiple backend requests for NIC, VNet, IP, Disk, and VM objects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhz8cz6y2j9me0msdydl5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhz8cz6y2j9me0msdydl5.png" alt=" " width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;• Azure CLI vs Azure Portal

• Architecture

• CLI: Local Python tool

• Portal: Browser SPA on top of ARM

• Input

• CLI: Commands and flags

• Portal: UI actions

• Execution

• CLI: Direct REST calls

• Portal: Frontend orchestrated REST calls

• Automation

• CLI: Scripts and pipelines

• Portal: Manual

• Output

• CLI: JSON, table, YAML

• Portal: Charts, cards, forms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>architecture</category>
      <category>azure</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
