Example #1
0
        public async Task <IActionResult> GetBatchEnvironments([FromRoute] string idOrName)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            var releaseBatch = await GetReleaseBatch(idOrName, true, false);

            if (releaseBatch == null)
            {
                return(HttpNotFound());
            }

            var permissionsToGet = new[] { Permission.EnvironmentView, Permission.DeploymentCreate };

            var environmentsWithPermissions =
                _octopusProxy.GetEnvironmentsWithPermissions(permissionsToGet, releaseBatch.Items.Select(i => i.ProjectId));

            var retVal = new EnvironmentsWithPermissionsResponseBody
            {
                View = environmentsWithPermissions[Permission.EnvironmentView].Select(e => new EnvironmentMapping
                {
                    Id   = e.Id,
                    Name = e.Name
                }).ToList(),
                Deploy = environmentsWithPermissions[Permission.DeploymentCreate].Select(e => new EnvironmentMapping
                {
                    Id   = e.Id,
                    Name = e.Name
                }).ToList(),
            };

            return(Ok(retVal));
        }
        public async Task<IActionResult> GetBatchEnvironments([FromRoute] string idOrName)
        {
            if (!ModelState.IsValid)
            {
                return HttpBadRequest(ModelState);
            }

            var releaseBatch = await GetReleaseBatch(idOrName, true, false);
            if (releaseBatch == null)
            {
                return HttpNotFound();
            }

            var permissionsToGet = new[] { Permission.EnvironmentView, Permission.DeploymentCreate };

            var environmentsWithPermissions =
                _octopusProxy.GetEnvironmentsWithPermissions(permissionsToGet, releaseBatch.Items.Select(i => i.ProjectId));

            var retVal = new EnvironmentsWithPermissionsResponseBody
            {
                View = environmentsWithPermissions[Permission.EnvironmentView].Select(e => new EnvironmentMapping
                {
                    Id = e.Id,
                    Name = e.Name
                }).ToList(),
                Deploy = environmentsWithPermissions[Permission.DeploymentCreate].Select(e => new EnvironmentMapping
                {
                    Id = e.Id,
                    Name = e.Name
                }).ToList(),
            };

            return Ok(retVal);
        }