Giter Site home page Giter Site logo

csmclient's Introduction

CSMClient

CSMClient facilitates getting token and CSM resource access. The simplest use case is to acquire token CSMClient.exe login and http GET CSM resource such as CSMClient.exe get https://management.azure.com/subscriptions?api-version=2014-04-01

Check out wiki for more details.

Login and get tokens
    CSMClient.exe login ([Prod|Current|Dogfood|Next])

Call CSM api
    CSMClient.exe [get|post|put|delete] [url] ([user])

Copy token to clipboard
    CSMClient.exe token [tenant] ([user])

List token cache
    CSMClient.exe listcache ([Prod|Current|Dogfood|Next])

Clear token cache
    CSMClient.exe clearcache ([Prod|Current|Dogfood|Next])

Note: The tokens are cached at %USERPROFILE%\.csm folder.

CSMClient.Authentication

There are 2 main objects, AAD.PersistentAuthHelper and AAD.AuthHelper. They both use AAD for authentication. However, the PersistentAuthHelper keeps a cache under %UserProfile%\.csm for the credentials so you don't have to enter them everytime. AuthHelper on the other hand, keeps its cache in memory.

CSMClient.Core.DynamicClient

DynamicClient is a library that facilitates getting tokens and doing CSM operations. The client is used through Dynamic Typing in .NET

private static void Main(string[] args)
{
    var csmClient = DynamicClient.GetDynamicClient(apiVersion: "2014-04-01", authHelper: new PersistentAuthHelper(AzureEnvironments.Prod));

    var sitesResponse = (HttpResponseMessage) csmClient.Subscriptions["{subscriptionId}"].ResourceGroups["{resourceGroupName}"].Providers["Microsoft.Web"].Sites.Get();

    if (sitesResponse.IsSuccessStatusCode)
    {
        var sites = sitesResponse.Content.ReadAsAsync<JArray>().Result;

        Func<object, bool> p = s => s.ToString().Equals("West US", StringComparison.OrdinalIgnoreCase);

        foreach (dynamic site in sites.Where(t => p(t["location"])))
        {
            Console.WriteLine(site.name);
        }
    }
    else
    {
        Console.WriteLine(sitesResponse.Content.ReadAsStringAsync().Result);
    }
}

The make up of the call is similar to the way CSM Urls are constructed. For example if the Url looks like this https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{webSiteName}/slots/{slotName}/config/web

then the DynamicCsmClient will be .Subscriptions["{subscriptionId}"].ResourceGroups["{resourceGroupName}"].Providers["Microsoft.Web"].Sites["{webSiteName}"].Slots["{slotName}"].Config["web"]

Note: Capitalization is optional .Subscriptions[""] == .subscription[""] also the distinction between [] and . is also optional .Config["web"] == .Config.Web. However, some names like subscription Ids which are usually GUIDs are not valid C# identifiers so you will have to use the indexer notation.

csmclient's People

Contributors

suwatch avatar ahmelsayed avatar

Watchers

 avatar James Cloos 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.