Exemplo n.º 1
0
        public async Task <InvokeResult> AddRemoteDeploymentAsync(RemoteDeployment host, EntityHeader org, EntityHeader user)
        {
            ValidationCheck(host, Actions.Create);
            await AuthorizeAsync(host, AuthorizeResult.AuthorizeActions.Create, user, org);

            await _repo.AddRemoteDeploymentAsync(host);

            return(InvokeResult.Success);
        }
Exemplo n.º 2
0
        public async Task <InvokeResult> UpdateRemoteDeploymentAsync(RemoteDeployment host, EntityHeader org, EntityHeader user)
        {
            ValidationCheck(host, Actions.Update);

            await AuthorizeAsync(host, AuthorizeResult.AuthorizeActions.Update, user, org);

            host.LastUpdatedDate = DateTime.UtcNow.ToJSONString();
            host.LastUpdatedBy   = user;
            await _repo.UpdateRemoteeDeploymentAsync(host);

            return(InvokeResult.Success);
        }
Exemplo n.º 3
0
        public HttpResponseMessage Install(string sessionGuid)
        {
            if (!SessionManager.SessionExists(sessionGuid))
            {
                // Session doesn't exist.
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid session."));
            }

            string apiKey = null;

            try
            {
                // Get the users ip address.
                string ipAddress = HttpContext.Current.Request.UserHostAddress;

                // Get the api key from the header.
                apiKey = Request.Headers.GetValues("x-api-key").FirstOrDefault();

                // Get the session.
                Session sessionObj = SessionManager.GetSession(sessionGuid);

                // Create a deploy operation.
                RemoteDeployment deployOperation = new RemoteDeployment(sessionObj, ipAddress, apiKey);

                // Deploy.
                deployOperation.Deploy();
            }
            catch (Exception ex)
            {
                EventLogManager.Log("REMOTE_EXCEPTION", EventLogSeverity.Warning, null, ex);

                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, "Operation started."));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a remote service based on the specified schema and deploys it on Azure
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="schema"></param>
        /// <returns></returns>
        public async Task <RemoteDeployment> Create(string appId, string schemaPath, ProjectRunArgs projectRunArgs)
        {
            await InitClient();

            SchemaValidator.ValidateSchema(schemaPath);

            var project = new RemoteProject();

            project.AppId           = appId;
            project.SubScriptionId  = azure.SubscriptionId;
            project.TenantId        = tenantId;
            project.SeedData        = projectRunArgs.SeedData;
            project.LocalSchemaPath = schemaPath;

            var deployment = new RemoteDeployment();

            deployment.Project        = project;
            deployment.StartedAt      = DateTimeOffset.Now;
            deployment.DeploymentName = $"dep{appId}";

            var rgName             = $"rg{appId}";
            var storageAccountName = $"st{appId}";
            var shareName          = $"share{appId}";

            project.ResourceGroup      = rgName;
            project.StorageAccountName = storageAccountName;
            project.AzureFileShare     = shareName;


            var region = Region.USCentral;

            project.Region = region.Name;

            await azure.ResourceGroups.Define(rgName).WithRegion(region).CreateAsync();

            // create storage account
            var storage = await azure.StorageAccounts.Define(storageAccountName).WithRegion(region)
                          .WithExistingResourceGroup(rgName)
                          .WithAccessFromAllNetworks()
                          .CreateAsync();

            var stKey = storage.GetKeys().First().Value;

            project.StorageAccountKey = stKey;

            var storageConnString = $"DefaultEndpointsProtocol=https;AccountName={storage.Name};AccountKey={stKey}";
            var shareClient       = new ShareClient(storageConnString, shareName);
            await shareClient.CreateAsync();

            // upload CSDL
            await UploadSchema(shareClient, schemaPath, RemoteCsdlFileDir, RemoteCsdlFileName);

            var template     = TemplateHelper.CreateDeploymentTemplate(project, image);
            var templateJson = JsonSerializer.Serialize(template);
            await azure.Deployments.Define(deployment.DeploymentName)
            .WithExistingResourceGroup(rgName)
            .WithTemplate(templateJson)
            .WithParameters("{}")
            .WithMode(Microsoft.Azure.Management.ResourceManager.Fluent.Models.DeploymentMode.Incremental)
            .CreateAsync();

            deployment.FinishedAt = DateTimeOffset.Now;

            return(deployment);
        }
 public Task <InvokeResult> UpdateHostAsync([FromBody] RemoteDeployment deployment)
 {
     SetUpdatedProperties(deployment);
     return(_manager.UpdateRemoteDeploymentAsync(deployment, OrgEntityHeader, UserEntityHeader));
 }
 public Task <InvokeResult> AddHostAsync([FromBody] RemoteDeployment deployment)
 {
     return(_manager.AddRemoteDeploymentAsync(deployment, OrgEntityHeader, UserEntityHeader));
 }