public async Task ExecuteAsync(string containerName)
        {
            if (string.IsNullOrWhiteSpace(containerName))
            {
                throw new ArgumentNullException(nameof(containerName));
            }

            _containerValidator.CheckContainerExist(containerName);
            var dockerClient = _dockerClientFactory.GetDockerClient();
            await dockerClient.Containers.StopContainerAsync(containerName, new StopContainerParameters(), CancellationToken.None);
        }
Exemple #2
0
        public async Task ExecuteAsync(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            _containerValidator.CheckContainerExist(name);
            var dockerClient = _dockerClientFactory.GetDockerClient();
            await dockerClient.Containers.StartContainerAsync(name, null);
        }
Exemple #3
0
        public async Task <Profile> ExecuteAsync(
            AddProfileParameter addProfileParameter,
            string domainName)
        {
            if (addProfileParameter == null)
            {
                throw new ArgumentNullException(nameof(addProfileParameter));
            }

            if (string.IsNullOrWhiteSpace(domainName))
            {
                throw new ArgumentNullException(nameof(domainName));
            }

            if (string.IsNullOrWhiteSpace(addProfileParameter.Subject))
            {
                throw new ArgumentNullException(nameof(addProfileParameter.Subject));
            }

            if (string.IsNullOrWhiteSpace(addProfileParameter.Name))
            {
                throw new ArgumentNullException(nameof(addProfileParameter.Name));
            }

            var isExistingProfile = _profileRepository.GetProfileBySubject(addProfileParameter.Subject) != null ||
                                    _profileRepository.GetProfileByName(addProfileParameter.Name) != null;

            if (isExistingProfile)
            {
                throw new IdentityServerException(ErrorCodes.InvalidRequestCode,
                                                  ErrorDescriptions.TheProfileAlreadyExists);
            }

            var newProfile = new Profile
            {
                Subject  = addProfileParameter.Subject,
                Name     = addProfileParameter.Name,
                IsActive = true,
                AuthorizationServerUrl = _endPointConfiguration.GetAuthorizationServer(addProfileParameter.Name),
                ManagerWebSiteApiUrl   = _endPointConfiguration.GetManagerWebSiteApi(addProfileParameter.Name),
                ManagerWebSiteUrl      = _endPointConfiguration.GetManagerWebSite(addProfileParameter.Name)
            };

            var isProfileAdded = _profileRepository.AddProfile(newProfile);

            if (!isProfileAdded)
            {
                return(null);
            }

            var dockerClient  = _dockerClientFactory.GetDockerClient();
            var containerName = newProfile.Name;
            await dockerClient.Containers.CreateContainerAsync(new CreateContainerParameters
            {
                ContainerName = newProfile.Name,
                Config        = new Config
                {
                    Env = new List <string>
                    {
                        string.Format("VIRTUAL_HOST={0}.{1}", containerName, domainName)
                    },
                    Image = ImageName
                }
            });

            return(newProfile);
        }