Garrard.AzureLib 0.0.6

dotnet add package Garrard.AzureLib --version 0.0.6
                    
NuGet\Install-Package Garrard.AzureLib -Version 0.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Garrard.AzureLib" Version="0.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Garrard.AzureLib" Version="0.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Garrard.AzureLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Garrard.AzureLib --version 0.0.6
                    
#r "nuget: Garrard.AzureLib, 0.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Garrard.AzureLib&version=0.0.6
                    
Install Garrard.AzureLib as a Cake Addin
#tool nuget:?package=Garrard.AzureLib&version=0.0.6
                    
Install Garrard.AzureLib as a Cake Tool

Garrard.AzureLib

Garrard.AzureLib is a .NET library that provides operations for working with Azure resources.

Installation

To install Garrard.AzureLib, you can use the NuGet package manager. Run the following command in the Package Manager Console:

Install-Package Garrard.AzureLib -Version 0.0.6

Or add the following package reference to your project file:

<PackageReference Include="Garrard.AzureLib" Version="0.0.6" />

Or use the dotnet add command:

dotnet add package Garrard.AzureLib --version 0.0.6

Usage

Here is an example of how to use Garrard.AzureLib in your project:

using Garrard.AzureLib;

class Program
{
    static async Task Main(string[] args)
    {
        // Installs missing dependencies
        
        await Helpers.CheckAndInstallDependenciesAsync(Console.WriteLine);
        var credentialsResult = await EntraIdOperations.ObtainAzureCredentialsAsync(Console.WriteLine);
        if (credentialsResult.IsFailure)
        {
            Console.WriteLine(credentialsResult.Error);
            return;
        }

        // checks if SP has Directory.ReadWrite.All access. Exists early if user and not SP.
        
        var checkDirectoryReadWriteAllAccessAsync = await EntraIdOperations.CheckIfServicePrincipalHasDirectoryReadWriteAllAccessAsync(Console.WriteLine);
        if (checkDirectoryReadWriteAllAccessAsync.IsFailure)
        {
            Console.WriteLine(checkDirectoryReadWriteAllAccessAsync.Error);
            return;
        }

        var (subscriptionId, tenantId, billingAccountId, enrollmentAccountId, spnName) = credentialsResult.Value;
        string groupName = "example-group";
        string scope = "/";
        Result<string> clientIdResult = await EntraIdOperations.GetClientIdAsync(spnName, Console.WriteLine);
        if (clientIdResult.IsFailure)
        {
            Console.WriteLine(clientIdResult.Error);
            return;
        }
        string clientId = clientIdResult.Value;
        await EntraIdOperations.AssignSubscriptionCreatorRoleAsync(clientId, tenantId, billingAccountId, enrollmentAccountId, Console.WriteLine);
        await EntraIdOperations.CreateGroupAsync(groupName, Console.WriteLine);
        await EntraIdOperations.AddSpToGroupAsync(spnName, groupName, clientId, Console.WriteLine);
        await EntraIdOperations.AssignOwnerRoleToGroupAsync(groupName, clientId, scope, Console.WriteLine);
        await EntraIdOperations.AddApiPermissionAsync(clientId, ApiPermissions.APPLICATION_READWRITE_ALL);
        var apiPermissionsResult = await EntraIdOperations.AddApiPermissionsAsync(clientId, Console.WriteLine);
        if (apiPermissionsResult.IsFailure)
        {
            Console.WriteLine(apiPermissionsResult.Error);
        }

         var isGlobalAdministratorAsync = await Garrard.AzureLib.EntraIdOperations.IsGlobalAdministratorAsync(Console.WriteLine);

        if (isGlobalAdministratorAsync.IsFailure)
        {
            Console.WriteLine(isGlobalAdministratorAsync.Error);
        }
    }
}

Features

  • Check and install dependencies
  • Obtain Azure credentials
  • Get client ID
  • Assign Subscription Creator Role to Service Principal (Required for EA and Subscription Vending)
    • Your User Security Principal first needs to be assinged as Billing Administrator for your Tenant.
  • Create an EntraID Group
  • Add Service Principal to a EntraID Group
  • Assign Owner Role to EntraID Group
  • Assign a Role to an EntraID Group
  • Add API permissions
  • Grant Admin Consent to Service Principal
  • Checks if the Service Principal has Directory.ReadWrite.All permission
  • Checks if the current user is a Global Administrator

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.6 213 a month ago
0.0.5 188 a month ago
0.0.4 138 a month ago

Please refer to the README