Exemple #1
0
        private static readonly string APIVERSION = "2016-08-31-preview"; // "2015-06-01-preview";

        /// <summary>
        /// Creates the client to read data from the ratecard REST API. Uses user authentication for
        /// authentication. Opens a popup to enter user and password
        /// </summary>
        /// <param name="azureIdentity">the service credentials</param>
        /// <param name="environment">the azure environment</param>
        /// <param name="subscription">the subscription details</param>
        public RateCardClient(AzureIdentity azureIdentity, AzureEnvironment environment, Subscription subscription)
            : base(azureIdentity, environment, subscription)
        {
        }
Exemple #2
0
 /// <summary>
 /// Gets tokaen for the query
 /// </summary>
 /// <returns>JWT token</returns>
 protected Task <string> GetTokenAsync()
 {
     return(AzureIdentity.GetTokenAsync(Subscription.Authority, Environment.ResourceManagerEndpoint));
 }
Exemple #3
0
 /// <summary>
 /// Creates the client to read data from the billing REST APIs.
 /// </summary>
 /// <param name="azureIdentity">the service credentials</param>
 /// <param name="environment">the azure environment</param>
 /// <param name="subscription">the subscription details</param>
 public Client(AzureIdentity azureIdentity, AzureEnvironment environment, Subscription subscription)
 {
     AzureIdentity = azureIdentity ?? throw new ArgumentNullException(nameof(azureIdentity));
     Environment   = environment ?? throw new ArgumentNullException(nameof(environment));
     Subscription  = subscription ?? throw new ArgumentNullException(nameof(subscription));
 }
Exemple #4
0
        public static async Task RunOrchestration(
            [OrchestrationTrigger] IDurableOrchestrationContext functionContext,
            ILogger log)
        {
            (OrchestratorContext orchestratorContext, ProjectCreateCommand command) = functionContext.GetInput <(OrchestratorContext, ProjectCreateCommand)>();

            var user      = command.User;
            var project   = command.Payload;
            var teamCloud = orchestratorContext.TeamCloud;

            functionContext.SetCustomStatus("Creating Project...");

            project.TeamCloudId = teamCloud.Id;
            project.TeamCloudApplicationInsightsKey = teamCloud.ApplicationInsightsKey;
            project.ProviderVariables = teamCloud.Configuration.Providers.Select(p => (p.Id, p.Variables)).ToDictionary(t => t.Id, t => t.Variables);

            // Add project to db and add new project to teamcloud in db
            project = await functionContext.CallActivityAsync <Project>(nameof(ProjectCreateActivity), project);

            // TODO: Create identity (service principal) for Project

            var projectIdentity = new AzureIdentity
            {
                Id     = Guid.NewGuid(),
                AppId  = "",
                Secret = ""
            };

            project = await functionContext.CallActivityAsync <Project>(nameof(ProjectUpdateActivity), project);

            var resourceGroup = new AzureResourceGroup
            {
                SubscriptionId    = teamCloud.Configuration.Azure.SubscriptionId,
                ResourceGroupName = $"{teamCloud.Configuration.Azure.ResourceGroupNamePrefix}{project.Name}", // TODO validate/clean
                Region            = teamCloud.Configuration.Azure.Region
            };

            // Create new resource group for project
            resourceGroup.Id = await functionContext.CallActivityAsync <Guid>(nameof(AzureResourceGroupCreateActivity), project);

            // Assign resource group to project
            project.ResourceGroup = resourceGroup;

            project = await functionContext.CallActivityAsync <Project>(nameof(ProjectUpdateActivity), project);

            var projectContext = new ProjectContext(teamCloud, project, command.User);

            functionContext.SetCustomStatus("Creating Project Resources...");

            // TODO: call create on all providers (handeling dependencies)
            // var tasks = teamCloud.Configuration.Providers.Select(p =>
            //                 functionContext.CallHttpAsync(HttpMethod.Post, p.Location, JsonConvert.SerializeObject(projectContext)));

            // await Task.WhenAll(tasks);

            functionContext.SetCustomStatus("Initializing Project Resources...");

            // TODO: call init on all providers (handeling dependencies)
            // var tasks = teamCloud.Configuration.Providers.Select(p =>
            //                 functionContext.CallHttpAsync(HttpMethod.Post, p.Location, JsonConvert.SerializeObject(projectContext)));

            // await Task.WhenAll(tasks);

            functionContext.SetOutput(project);

            //return true;
        }