feat(az): add tenant name

This commit is contained in:
Jan De Dobbeleer 2024-07-11 21:13:12 +02:00 committed by Jan De Dobbeleer
parent 415d310c69
commit fb9d447c87
2 changed files with 45 additions and 35 deletions

View file

@ -39,6 +39,7 @@ type AzureSubscription struct {
User *AzureUser `json:"user"` User *AzureUser `json:"user"`
IsDefault bool `json:"isDefault"` IsDefault bool `json:"isDefault"`
TenantID string `json:"tenantId"` TenantID string `json:"tenantId"`
TenantDisplayName string `json:"tenantDisplayName"`
EnvironmentName string `json:"environmentName"` EnvironmentName string `json:"environmentName"`
HomeTenantID string `json:"homeTenantId"` HomeTenantID string `json:"homeTenantId"`
ManagedByTenants []any `json:"managedByTenants"` ManagedByTenants []any `json:"managedByTenants"`
@ -67,6 +68,7 @@ type AzurePowerShellSubscription struct {
} `json:"Subscription"` } `json:"Subscription"`
Tenant struct { Tenant struct {
ID string `json:"Id"` ID string `json:"Id"`
Name string `json:"Name"`
} `json:"Tenant"` } `json:"Tenant"`
} }
@ -126,10 +128,12 @@ func (a *Az) getModuleSubscription() bool {
if len(envSubscription) == 0 { if len(envSubscription) == 0 {
return false return false
} }
var config AzurePowerShellSubscription var config AzurePowerShellSubscription
if err := json.Unmarshal([]byte(envSubscription), &config); err != nil { if err := json.Unmarshal([]byte(envSubscription), &config); err != nil {
return false return false
} }
a.IsDefault = true a.IsDefault = true
a.EnvironmentName = config.Environment.Name a.EnvironmentName = config.Environment.Name
a.TenantID = config.Tenant.ID a.TenantID = config.Tenant.ID
@ -140,7 +144,10 @@ func (a *Az) getModuleSubscription() bool {
Name: config.Subscription.ExtendedProperties.Account, Name: config.Subscription.ExtendedProperties.Account,
Type: config.Account.Type, Type: config.Account.Type,
} }
a.TenantDisplayName = config.Tenant.Name
a.Origin = "PWSH" a.Origin = "PWSH"
return true return true
} }

View file

@ -16,19 +16,21 @@ initializing Oh My Posh.
## Sample Configuration ## Sample Configuration
import Config from '@site/src/components/Config.js'; import Config from "@site/src/components/Config.js";
<Config data={{ <Config
"type": "az", data={{
"style": "powerline", type: "az",
"powerline_symbol": "\uE0B0", style: "powerline",
"foreground": "#000000", powerline_symbol: "\uE0B0",
"background": "#9ec3f0", foreground: "#000000",
"template": " \uebd8 {{ .EnvironmentName }}", background: "#9ec3f0",
"properties": { template: " \uebd8 {{ .EnvironmentName }}",
"source": "pwsh" properties: {
} source: "pwsh",
}}/> },
}}
/>
## Properties ## Properties
@ -49,7 +51,7 @@ import Config from '@site/src/components/Config.js';
### Properties ### Properties
| Name | Type | Description | | Name | Type | Description |
| ------------------ | --------- | -------------------------------------------------------------- | | -------------------- | --------- | -------------------------------------------------------------- |
| `.EnvironmentName` | `string` | Azure environment name | | `.EnvironmentName` | `string` | Azure environment name |
| `.HomeTenantID` | `string` | home tenant id | | `.HomeTenantID` | `string` | home tenant id |
| `.ID` | `string` | subscription id | | `.ID` | `string` | subscription id |
@ -57,6 +59,7 @@ import Config from '@site/src/components/Config.js';
| `.Name` | `string` | subscription name | | `.Name` | `string` | subscription name |
| `.State` | `string` | subscription state | | `.State` | `string` | subscription state |
| `.TenantID` | `string` | tenant id | | `.TenantID` | `string` | tenant id |
| `.TenantDisplayName` | `string` | tenant name |
| `.User.Name` | `string` | user name | | `.User.Name` | `string` | user name |
| `.User.Type` | `string` | user type | | `.User.Type` | `string` | user type |
| `.Origin` | `string` | where we received the information from, can be `CLI` or `PWSH` | | `.Origin` | `string` | where we received the information from, can be `CLI` or `PWSH` |