예제 #1
0
        protected virtual async Task <SecretStore> GetEnvironmentSecretStore(DeploymentEnvironment env)
        {
            if (env.SecretStore == null || String.IsNullOrEmpty(env.SecretStore.Value))
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Strings.Command_EnvironmentHasNoSecretStore,
                                                        env.Name));
            }
            if (!String.Equals(env.SecretStore.Type, DpapiSecretStoreProvider.AppModelTypeName, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Strings.Command_UnknownSecretStoreType,
                                                        env.SecretStore.Type));
            }
            var store = await(new DpapiSecretStoreProvider(env.SecretStore.Value).Open(env));

            if (!store.Exists())
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Strings.Command_SecretStoreNotCreated,
                                                        env.Name));
            }
            return(store);
        }
예제 #2
0
        public ContainerRegistry(Construct scope, string id, DeploymentEnvironment env) : base(scope, id)
        {
            var repositoryName = $"demo-{env.ToString().ToLower()}";

            Registry = new Repository(this, repositoryName, new RepositoryProps
            {
                RepositoryName = repositoryName,
                RemovalPolicy  = RemovalPolicy.DESTROY
            });
            //TODO: need a rule to kill all untagged images...need tags!!!
            // ecr.AddLifecycleRule(new LifecycleRule
            // {
            //     RulePriority = 1,
            //     MaxImageCount = 1,
            //     Description = "all images must be tagged, or they will be deleted",
            //     TagStatus = TagStatus.UNTAGGED
            // });

            //TODO: Rule so only valid tag names are used
            // eg. <service>-master-gitHash
            // hello-master-38fde3d
            // ecr.AddLifecycleRule(new LifecycleRule
            // {
            //     RulePriority = 1,
            //     Description = "keep it clean, only 10 images of a tag are allowed",
            //     MaxImageCount = 10,
            //     TagPrefixList = new [] {"prod-*", "master-*"},
            //     TagStatus = TagStatus.TAGGED
            // });
        }
예제 #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((DeploymentEnvironment?.GetHashCode() ?? 0) * 397) ^ (ServiceName?.GetHashCode() ?? 0));
     }
 }
예제 #4
0
        private static string GetCertSubjectName(DeploymentEnvironment environment)
        {
            switch (environment)
            {
            case DeploymentEnvironment.CI:
                return("*.ci.eshopworld.net");

            case DeploymentEnvironment.Sand:
                return("*.sandbox.eshopworld.com");

            case DeploymentEnvironment.Test:
                return("*.test.eshopworld.net");

            case DeploymentEnvironment.Prep:
                return("*.preprod.eshopworld.net");

            case DeploymentEnvironment.Prod:
                return("*.production.eshopworld.com");

            case DeploymentEnvironment.Development:
                return("localhost");

            default:
                throw new ArgumentOutOfRangeException(nameof(environment), environment, $"The environment {environment} is not recognized");
            }
        }
예제 #5
0
        private static X509Certificate2 GetCertificate(DeploymentEnvironment environment)
        {
            var subject = GetCertSubjectName(environment);
            var store   = new X509Store(StoreName.My, StoreLocation.LocalMachine);

            try
            {
                store.Open(OpenFlags.ReadOnly);
                var certCollection = store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName, $"CN={subject}, OU=Domain Control Validated", true);

                if (certCollection.Count == 0)
                {
                    // TODO: another temporary attempt to find the cert
                    certCollection = store.Certificates.Find(X509FindType.FindBySubjectName, subject, false);
                    if (certCollection.Count > 0)
                    {
                        BigBrother.Write(new ExceptionEvent(new Exception($"Found {subject} using the FindBySubjectName option (cert {certCollection[0].Subject}).")));
                    }
                }

                if (certCollection.Count == 0)
                {
                    throw new Exception($"The certificate for {subject} has not been found.");
                }

                return(certCollection[0]);
            }
            finally
            {
                store.Close();
            }
        }
        public bool AddOrUpdateStaging(DeploymentEnviromentModel dto)
        {
            var website = dto.Website;

            if (website.Stagging == null)
            {
                website.Stagging = new List <DeploymentEnvironment>();
            }
            var websiteEnviroment = website.Stagging.FirstOrDefault(x => x.Id == dto.EnviromentId);

            if (websiteEnviroment != null)
            {
                website.Stagging.Remove(websiteEnviroment);
            }
            else
            {
                websiteEnviroment = new DeploymentEnvironment();
            }
            if (string.IsNullOrEmpty(websiteEnviroment.Id))
            {
                websiteEnviroment.Id = Guid.NewGuid().ToString();
            }
            websiteEnviroment.Git        = dto.Git;
            websiteEnviroment.Url        = dto.Url;
            websiteEnviroment.HostingFee = dto.HostingFee;
            websiteEnviroment.Name       = dto.Name;
            websiteEnviroment.IsDefault  = dto.IsDefault;
            website.Stagging.Add(websiteEnviroment);

            this.AddOrUpdate(website);
            return(true);
        }
예제 #7
0
        internal DemoStack(Construct scope, string id, DeploymentEnvironment env, IStackProps props = null) :
            base(scope, id, props)
        {
            //network
            Vpc = new Network(this, "{id}-supernetwork").Vpc;

            //Kubernetes
            var ecr = new ContainerRegistry(this, $"{id}-container-registry", env);
            var k8  = new KubernetesCluster(this, $"{id}-cluster", Vpc, "democluster");

            if (env == DeploymentEnvironment.Dev || env == DeploymentEnvironment.Sandbox)
            {
                var sandboxCluster = new SpotFleetWorkerGroup(this, id, k8.Master);
            }
            else
            {
                // WARNING: Changing Node Groups is destructive...
                //
                // Process is to add a new node group to production then delete  the old cluster group
                // e.g. api-cluster-v1, api-cluster-v2, etc
                // Kubernetes Compute (e.g. EKS node groups)
                var apiCluster1 = new AutoScalerNodeGroup(this, id, "api-cluster-v1", k8.Master);
                apiCluster1.Node.AddDependency(k8);
            }
        }
예제 #8
0
        public override async Task <PingResult> Ping(DeploymentEnvironment target)
        {
            var url    = _urlSelector(target);
            var client = new HttpClient(
                new WebRequestHandler()
            {
                CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache)
            });

            try
            {
                var resp = await client.GetAsync(url);

                return(HttpResponseResult(url, resp));
            }
            catch (HttpRequestException hrex)
            {
                WebException wex = hrex.InnerException as WebException;
                if (wex != null)
                {
                    return(WebExceptionResult(url, wex));
                }
                return(UnknownErrorResult(url));
            }
            catch (Exception)
            {
                return(UnknownErrorResult(url));
            }
        }
예제 #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = ServiceName.GetHashCode();
         hashCode = (hashCode * 397) ^ (DeploymentEnvironment?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ Zone.GetHashCode();
         return(hashCode);
     }
 }
예제 #10
0
    public void GetDeploymentSubscriptionIdTest(DeploymentEnvironment environmentName, DeploymentEnvironment deploymentEnvironmentName, object resultEnvironmentSubscription)
    {
        Environment.SetEnvironmentVariable(EswDevOpsSdk.EnvironmentEnvVariable, environmentName.ToString(), EnvironmentVariableTarget.Process);
        var expectedSubscriptionId = resultEnvironmentSubscription as string == SierraIntegration
            ? EswDevOpsSdk.SierraIntegrationSubscriptionId
            : EswDevOpsSdk.GetSubscriptionId(deploymentEnvironmentName);

        var subscriptionId = EswDevOpsSdk.GetSierraDeploymentSubscriptionId(deploymentEnvironmentName);

        subscriptionId.Should().Be(expectedSubscriptionId);
    }
 private EnvironmentStatus CreateStatus(DeploymentEnvironment env, IList <PingResult> pings)
 {
     return(new EnvironmentStatus()
     {
         Title = env.Title,
         Name = env.Name,
         Description = env.Description,
         Url = env.Url,
         PingResults = pings ?? new List <PingResult>()
     });
 }
예제 #12
0
        /// <summary>
        /// Gets the deployment package.
        /// </summary>
        /// <param name="project">The K2 project.</param>
        /// <param name="environmentManager">The K2 environment manager.</param>
        /// <param name="IsTest">Will Deployment Package be in Test Mode?</param>
        /// <returns>The Deployment Package</returns>
        public static DeploymentPackage CreateDeploymentPackage(
            Project project, EnvironmentSettingsManager environmentManager,
            string DeploymentLabel, string DeploymentDescription, bool IsTest)
        {
            DeploymentPackage package;

            LogHelper.LogMessage("      -- Creating Deployment Package");
            package = project.CreateDeploymentPackage();

            // Populate Environment Fields
            foreach (EnvironmentInstance env in environmentManager.CurrentTemplate.Environments)
            {
                DeploymentEnvironment depEnv = package.AddEnvironment(env.EnvironmentName);

                foreach (EnvironmentField field in env.EnvironmentFields)
                {
                    depEnv.Properties[field.FieldName] = field.Value;
                }
            }

            LogHelper.LogMessage("   -- Setting Package Info");
            package.SelectedEnvironment        = environmentManager.CurrentEnvironment.EnvironmentName;
            package.DeploymentLabelName        = string.IsNullOrEmpty(DeploymentLabel) ? DateTime.Now.ToString() : DeploymentLabel;
            package.DeploymentLabelDescription = DeploymentDescription;
            package.TestOnly = IsTest;

            LogHelper.LogMessage("      SelectedEnvironment = " + package.SelectedEnvironment);
            LogHelper.LogMessage("      DeploymentLabelName = " + package.DeploymentLabelName);
            LogHelper.LogMessage("      DeploymentLabelDescription = " + package.DeploymentLabelDescription);
            LogHelper.LogMessage("      TestOnly = " + package.TestOnly);

            // Get the Default SmartObject Server in the Environment
            // The prefix "$Field=" is when the value of the SmartObject server is registered in the environment fields collection.
            // this will do a lookup in the environment with the display name of the field, and use the value.
            // If you set the value directly, no lookups will be performed.
            EnvironmentField smartObjectServerField =
                environmentManager.CurrentEnvironment.GetDefaultField(typeof(SmartObjectField));

            LogHelper.LogMessage("   -- Setting SmartObject Server ConnectionString");
            package.SmartObjectConnectionString = "$Field=" + smartObjectServerField.DisplayName;
            LogHelper.LogMessage("      SmartObject Server ConnectionString = " + package.SmartObjectConnectionString);

            // Get the Default Workflow Management Server in the Environment
            EnvironmentField workflowServerField =
                environmentManager.CurrentEnvironment.GetDefaultField(typeof(WorkflowManagementServerField));

            LogHelper.LogMessage("   -- Setting Workflow Management ConnectionString");
            package.WorkflowManagementConnectionString = "$Field=" + workflowServerField.DisplayName;
            LogHelper.LogMessage("      Workflow Management ConnectionString = " + package.WorkflowManagementConnectionString);

            return(package);
        }
        public virtual BODeploymentEnvironment MapEFToBO(
            DeploymentEnvironment ef)
        {
            var bo = new BODeploymentEnvironment();

            bo.SetProperties(
                ef.Id,
                ef.DataVersion,
                ef.JSON,
                ef.Name,
                ef.SortOrder);
            return(bo);
        }
        public virtual DeploymentEnvironment MapBOToEF(
            BODeploymentEnvironment bo)
        {
            DeploymentEnvironment efDeploymentEnvironment = new DeploymentEnvironment();

            efDeploymentEnvironment.SetProperties(
                bo.DataVersion,
                bo.Id,
                bo.JSON,
                bo.Name,
                bo.SortOrder);
            return(efDeploymentEnvironment);
        }
        private async Task <bool> BeUniqueByName(ApiDeploymentEnvironmentRequestModel model, CancellationToken cancellationToken)
        {
            DeploymentEnvironment record = await this.deploymentEnvironmentRepository.ByName(model.Name);

            if (record == null || (this.existingRecordId != default(string) && record.Id == this.existingRecordId))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #16
0
        public async Task <ApiDeploymentEnvironmentResponseModel> ByName(string name)
        {
            DeploymentEnvironment record = await this.deploymentEnvironmentRepository.ByName(name);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.bolDeploymentEnvironmentMapper.MapBOToModel(this.dalDeploymentEnvironmentMapper.MapEFToBO(record)));
            }
        }
예제 #17
0
        protected virtual Datacenter GetDatacenter(DeploymentEnvironment environment, int datacenter, bool required)
        {
            var dc = environment.Datacenters.FirstOrDefault(d => d.Id == datacenter);

            if (dc == null && required)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Strings.Command_UnknownDc,
                                                        environment.Name,
                                                        datacenter));
            }
            return(dc);
        }
        public void MapEFToBOList()
        {
            var mapper = new DALDeploymentEnvironmentMapper();
            DeploymentEnvironment entity = new DeploymentEnvironment();

            entity.SetProperties(BitConverter.GetBytes(1), "A", "A", "A", 1);

            List <BODeploymentEnvironment> response = mapper.MapEFToBO(new List <DeploymentEnvironment>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
예제 #19
0
    public void GeEnvironmentTest(string envValue, DeploymentEnvironment env)
    {
        var prevEnv = Environment.GetEnvironmentVariable(EswDevOpsSdk.EnvironmentEnvVariable);

        Environment.SetEnvironmentVariable(EswDevOpsSdk.EnvironmentEnvVariable, envValue, EnvironmentVariableTarget.Process);
        try
        {
            var currentEnvironment = EswDevOpsSdk.GetEnvironment();
            currentEnvironment.Should().Be(env);
        }
        finally
        {
            Environment.SetEnvironmentVariable(EswDevOpsSdk.EnvironmentEnvVariable, prevEnv, EnvironmentVariableTarget.Process);
        }
    }
        public void MapEFToBO()
        {
            var mapper = new DALDeploymentEnvironmentMapper();
            DeploymentEnvironment entity = new DeploymentEnvironment();

            entity.SetProperties(BitConverter.GetBytes(1), "A", "A", "A", 1);

            BODeploymentEnvironment response = mapper.MapEFToBO(entity);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.SortOrder.Should().Be(1);
        }
        public void MapBOToEF()
        {
            var mapper = new DALDeploymentEnvironmentMapper();
            var bo     = new BODeploymentEnvironment();

            bo.SetProperties("A", BitConverter.GetBytes(1), "A", "A", 1);

            DeploymentEnvironment response = mapper.MapBOToEF(bo);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.SortOrder.Should().Be(1);
        }
        public DeploymentResults Deploy(Project project)
        {
            DeploymentPackage     package     = null;
            DeploymentEnvironment environment = null;

            try
            {
                // Compile the project first before we attempt to deploy it.
                DeploymentResults compileResults = project.Compile();
                if (!compileResults.Successful)
                {
                    // Is the compile was unsuccesfull, return the results
                    return(compileResults);
                }

                // Create a logger that is required by the deployment package
                ProjectLogger logger = new ProjectLogger();
                logger.Verbosity = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic;
                project.SetOutputLogger(logger);

                // Create a new deployment package
                package = project.CreateDeploymentPackage();

                // The deployment package requires at least one environment, so add a default one.
                // When deployment is done via VisualStudio, the environments are automatically set
                // up from the ones available in the Environment Library.
                environment = package.AddEnvironment("Default");
                package.SelectedEnvironment                = environment.Name;
                package.SmartObjectConnectionString        = _smartObjectConnectionString;
                package.WorkflowManagementConnectionString = _workflowManagementConnectionString;

                // Start the deployment
                return(project.Deploy(package));
            }
            finally
            {
                if (package != null)
                {
                    package.Dispose();
                    package = null;
                }
                if (environment != null)
                {
                    environment.Dispose();
                    environment = null;
                }
            }
        }
        public void SetCurrentEnvironment(string name, bool throwOnFailure)
        {
            DeploymentEnvironment env = this[name];

            if (env == null && throwOnFailure)
            {
                throw new KeyNotFoundException(String.Format(
                                                   CultureInfo.CurrentCulture,
                                                   Strings.OperationsSession_UnknownEnvironment,
                                                   name));
            }
            if (env != null)
            {
                CurrentEnvironment = env;
            }
        }
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IDeploymentEnvironmentRepository>();
            var record = new DeploymentEnvironment();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new DeploymentEnvironmentService(mock.LoggerMock.Object,
                                                           mock.RepositoryMock.Object,
                                                           mock.ModelValidatorMockFactory.DeploymentEnvironmentModelValidatorMock.Object,
                                                           mock.BOLMapperMockFactory.BOLDeploymentEnvironmentMapperMock,
                                                           mock.DALMapperMockFactory.DALDeploymentEnvironmentMapperMock);

            ApiDeploymentEnvironmentResponseModel response = await service.Get(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
예제 #25
0
        protected virtual async Task <string> GetSecretOrDefault(DeploymentEnvironment env, string secretName, int?datacenter, string clientOperation)
        {
            var secrets = await GetEnvironmentSecretStore(env);

            if (secrets == null)
            {
                return(null);
            }

            var secret = await secrets.Read(new SecretName(secretName, datacenter), clientOperation);

            if (secret == null)
            {
                return(null);
            }
            return(secret.Value);
        }
        public static DeploymentPackage GetPackage(string environmentServer,
                                                   string destinationTemplate, string destinationEnvironment,
                                                   Project project, bool testOnly)
        {
            //Create connection string to environment server
            var envionmentServerConnection = EnvionmentServerConnection(environmentServer);
            //Retrieve the environments from the server
            EnvironmentSettingsManager environmentManager = new
                                                            EnvironmentSettingsManager(true);

            environmentManager.ConnectToServer(envionmentServerConnection);
            environmentManager.InitializeSettingsManager(true);
            environmentManager.Refresh();

            //Get the template and environment objects.
            EnvironmentTemplate template    = environmentManager.EnvironmentTemplates[destinationTemplate];
            EnvironmentInstance environment = template.Environments[destinationEnvironment];
            //Create the package
            DeploymentPackage package = project.CreateDeploymentPackage();

            //Set all of the environment fields to the package
            DeploymentEnvironment deploymentEnv =
                package.AddEnvironment(environment.EnvironmentName);

            foreach (EnvironmentField field in environment.EnvironmentFields)
            {
                deploymentEnv.Properties[field.FieldName] = field.Value;
            }

            //Set fields on the package
            package.SelectedEnvironment        = destinationEnvironment;
            package.DeploymentLabelName        = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            package.DeploymentLabelDescription =
                "Template: " + destinationTemplate + ",Environment: " + destinationEnvironment;
            package.TestOnly = testOnly;
            //Get the Default SmartObject Server in the Environment
            //environment.GetDefaultField(typeof(SmartObjectField));
            package.SmartObjectConnectionString = envionmentServerConnection;
            //Get the Default Workflow Management Server in the Environment
            //environment.GetDefaultField(typeof(WorkflowManagementServerField));
            package.WorkflowManagementConnectionString = envionmentServerConnection;

            return(package);
        }
예제 #27
0
        /// <summary>
        /// retrieve deployment context
        /// </summary>
        /// <param name="targetEnvironment">the environment to target</param>
        /// <returns>deployment context instance</returns>
        public static DeploymentContext CreateDeploymentContext(DeploymentEnvironment targetEnvironment = DeploymentEnvironment.Prod)
        {
            var regionString = GetEnvironmentVariable(DeploymentRegionEnvVariable);

            if (string.IsNullOrWhiteSpace(regionString))
            {
                throw new DevOpsSDKException(
                          $"Could not find deployment region environment variable. Please make sure that {DeploymentRegionEnvVariable} environment variable exists and has value");
            }

            var parsed = ParseRegionFromString(regionString);

            var preferredRegions = GetRegionSequence(targetEnvironment, parsed)
                                   .Select(i => i.ToRegionName());

            return(new DeploymentContext {
                PreferredRegions = preferredRegions
            });
        }
예제 #28
0
        /// <summary>
        /// Toes the code.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <returns></returns>
        public static string ToCode(this DeploymentEnvironment environment)
        {
            switch (environment)
            {
            case DeploymentEnvironment.ProofOfConcept: return("X");

            case DeploymentEnvironment.Local: return("Z");

            case DeploymentEnvironment.Development: return("D");

            case DeploymentEnvironment.AlphaTesting: return("A");

            case DeploymentEnvironment.BetaTesting: return("B");

            case DeploymentEnvironment.Production: return("P");

            default: throw new ArgumentOutOfRangeException("environment", "unknown target");
            }
        }
예제 #29
0
        /// <summary>
        /// Toes the short name.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <returns></returns>
        public static string ToShortName(this DeploymentEnvironment environment)
        {
            switch (environment)
            {
            case DeploymentEnvironment.ProofOfConcept: return("proof");

            case DeploymentEnvironment.Local: return("local");

            case DeploymentEnvironment.Development: return("develop");

            case DeploymentEnvironment.AlphaTesting: return("alpha");

            case DeploymentEnvironment.BetaTesting: return("beta");

            case DeploymentEnvironment.Production: return("prod");

            default: throw new ArgumentOutOfRangeException("environment", "unknown target");
            }
        }
예제 #30
0
        // ReSharper disable once MemberCanBePrivate.Global
        public static IEnumerable <DeploymentRegion> GetRegionSequence(DeploymentEnvironment environment, DeploymentRegion masterRegion)
        {
            if (environment == DeploymentEnvironment.CI)
            {
                return new[] { DeploymentRegion.WestEurope }
            }
            ;

            //map region to hierarchy
            if (!RegionSequenceMap.ContainsKey(masterRegion))
            {
                throw new DevOpsSDKException($"Unrecognized value for region environmental variable - {masterRegion}");
            }

            var map = RegionSequenceMap[masterRegion];

            return((environment == DeploymentEnvironment.Sand || environment == DeploymentEnvironment.Test ||
                    environment == DeploymentEnvironment.Development)
                ? map.Where(r => r != DeploymentRegion.SoutheastAsia)
                : map);
        }
 protected override SqlConnectionStringBuilder SelectEnvironmentConnection(DeploymentEnvironment env)
 {
     return env.WarehouseDatabase;
 }