Exemple #1
0
        public List <Parameter> GetActiveParameters()
        {
            if (string.IsNullOrEmpty(Environment))
            {
                if (Parameters.Any())
                {
                    return(Parameters);
                }

                if (Environments.Any())
                {
                    return(Environments.First().Parameters);
                }
            }
            else
            {
                var environment = Environment.ToLower();
                foreach (var e in Environments)
                {
                    if (!string.IsNullOrEmpty(e.Name) && e.Name.ToLower() == environment)
                    {
                        return(e.Parameters);
                    }
                }
            }

            return(new List <Parameter>());
        }
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            // Always include last run and stats
            queries.Add("includeLastRunAndStats", true.ToString().ToLower());

            if (OnlyActive.IsPresent)
            {
                queries.Add("isActive", true.ToString().ToLower());
            }

            if (OnlyInactive.IsPresent)
            {
                queries.Add("isActive", false.ToString().ToLower());
            }

            if (OnlyDeleted.IsPresent)
            {
                queries.Add("isDeleted", true.ToString().ToLower());
            }

            if (Ids != null && Ids.Any())
            {
                queries.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                queries.Add("names", string.Join(",", Names));
            }

            if (PolicyIds != null && PolicyIds.Any())
            {
                queries.Add("policyIds", string.Join(",", PolicyIds));
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var preparedUrl = $"/public/protectionJobs{queryString}";
            var results     = Session.ApiClient.Get <IEnumerable <Model.ProtectionJob> >(preparedUrl);

            // Hide deleted protection jobs unless explicitly asked for
            if (!OnlyDeleted.IsPresent)
            {
                results = results.Where(x => !(x.Name.StartsWith("_DELETED"))).ToList();
            }
            WriteObject(results, true);
        }
Exemple #3
0
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                qb.Add("environments", string.Join(",", envs));
            }

            if (Ids != null && Ids.Any())
            {
                qb.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                qb.Add("names", string.Join(",", Names));
            }

            var preparedUrl = $"/public/protectionPolicies{qb.Build()}";
            var result      = Session.ApiClient.Get <IEnumerable <Model.ProtectionPolicy> >(preparedUrl);

            WriteObject(result, true);
        }
Exemple #4
0
        public void RemoveEnvironment(ApplicationEnvironment environment)
        {
            Guard.IsNotNull(Environments, "Unload environments");
            Guard.IsTrue(Environments.Any(x => x.Id == environment.Id), "Invalid environment");
            Guard.IsFalse(environment.IsDefault, "You can't delete the default environment");

            Environments.Remove(environment);
        }
Exemple #5
0
        public IEnumerable <Parameter> GetActiveParameters()
        {
            if (!Environments.Any())
            {
                return(Enumerable.Empty <Parameter>());
            }

            return(string.IsNullOrEmpty(Environment) ? Environments.First().Parameters : Environments.First(e => e.Name == Environment).Parameters);
        }
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Id.HasValue)
            {
                var url    = $"/public/protectionSources/objects/{Id.ToString()}";
                var result = Session.ApiClient.Get <Model.ProtectionSource>(url);
                WriteObject(result);
            }
            else
            {
                if (Environments != null && Environments.Any())
                {
                    List <string> environments =
                        Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                    qb.Add("environments", string.Join(",", environments));
                }

                var url     = $"/public/protectionSources/rootNodes{qb.Build()}";
                var results = Session.ApiClient.Get <List <ProtectionSourceNode> >(url);

                // Get the list of all group nodes
                var groups = results.Where(x => x.RegistrationInfo == null).ToList();

                foreach (var group in groups)
                {
                    // Get children for each group node
                    qb = new QuerystringBuilder();
                    qb.Add("id", group.ProtectionSource.Id.ToString());
                    url = $"/public/protectionSources{qb.Build()}";
                    var children = Session.ApiClient.Get <List <ProtectionSourceNode> >(url);
                    children = FlattenNodes(children);

                    foreach (var child in children)
                    {
                        if (child.RegistrationInfo != null)
                        {
                            results.Add(child);
                        }
                    }
                }

                // Skip kView, kAgent, kPuppeteer environment types and group nodes themselves
                results = results.Where(x =>
                                        (x.ProtectionSource.Environment != Model.ProtectionSource.EnvironmentEnum.KAgent) &&
                                        (x.ProtectionSource.Environment != Model.ProtectionSource.EnvironmentEnum.KView) &&
                                        (x.ProtectionSource.Environment != Model.ProtectionSource.EnvironmentEnum.KPuppeteer) &&
                                        (x.RegistrationInfo != null)
                                        ).ToList();

                // Make sure each source id is only listed once as it might repeat under different environments
                var sources = results.GroupBy(x => x.ProtectionSource.Id).Select(y => y.FirstOrDefault());
                WriteObject(sources, true);
            }
        }
Exemple #7
0
        private void CreateProjectDeployments(IList <IDeployment> deployments)
        {
            Deployments = new List <IDeployment>();

            foreach (var deployment in deployments)
            {
                if (Releases.Any(x => x.Id.Contains(deployment.ReleaseId)) && Environments.Any(x => x.Id.Contains(deployment.EnvironmentId)))
                {
                    Deployments.Add(new Deployment(deployment));
                }
            }
        }
Exemple #8
0
        private ApplicationEnvironment AddEnvironment(string name, bool isDefault)
        {
            Guard.IsNotNull(Environments);
            Guard.IsFalse(Environments.Any(x => x.Name == name), "This environment already exits");

            var environment = ApplicationEnvironment.NewEnv(Id, name, isDefault);


            Environments.Add(environment);

            return(environment);
        }
Exemple #9
0
        private bool IsRunningInEnvironment(IDotvvmRequestContext context)
        {
            var provider = context.Services.GetService <IEnvironmentNameProvider>();
            var currentEnvironmentName = provider?.GetEnvironmentName(context);

            if (Environments != null && currentEnvironmentName != null)
            {
                return(Environments.Any(n => EnvironmentsEqual(n, currentEnvironmentName)));
            }

            return(false);
        }
Exemple #10
0
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (StartTime.HasValue)
            {
                queries.Add("startTimeUsecs", StartTime.ToString());
            }

            if (EndTime.HasValue)
            {
                queries.Add("endTimeUsecs", EndTime.ToString());
            }

            if (Search != null)
            {
                queries.Add("search", Search);
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            if (JobIds != null && JobIds.Any())
            {
                queries.Add("jobIds", string.Join(",", JobIds));
            }

            if (RegisteredSourceIds != null && RegisteredSourceIds.Any())
            {
                queries.Add("registeredSourceIds", string.Join(",", RegisteredSourceIds));
            }

            if (StorageDomainIds != null && StorageDomainIds.Any())
            {
                queries.Add("viewBoxIds", string.Join(",", StorageDomainIds));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var url    = $"/public/restore/objects{queryString}";
            var result = Session.ApiClient.Get <ObjectSearchResults>(url);

            WriteObject(result.ObjectSnapshotInfo, true);
        }
Exemple #11
0
        void ExecEnvClone()
        {
            if (!(EnvList.SelectedItem is Environment senv))
            {
                return;
            }

            var name = senv.Name;

            if (Environments.Any(e => e.IsLocal && (e.Name.Equals(name, StringComparison.OrdinalIgnoreCase))))
            {
                var ibox = new InputBox("New environment name:", "Clone Environment", name + " - Copy");

                ibox.Closing += (sender, args) => {
                    var ib = (InputBox)sender;

                    if (ib.DialogResult != true)
                    {
                        return;
                    }

                    name = ib.Text.Trim();
                    if (Environments.Any(e => e.IsLocal && (e.Name.Equals(name, StringComparison.OrdinalIgnoreCase))))
                    {
                        MessageBox.Show(
                            $"Environment '{name}' already exists.\nPlease choose a different name.",
                            Strings.APP_NAME,
                            MessageBoxButton.OK,
                            MessageBoxImage.Error
                            );
                        args.Cancel = true;
                    }
                    ;
                };

                if (ibox.ShowDialog() != true)
                {
                    return;
                }
            }

            var nenv = senv.Clone(name);

            nenv.Dirty = true;
            nenv.Save();

            Environments.Add(nenv);
            EnvList.SelectedItem = Environments.First(e => e.Id == nenv.Id);
        }
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Id.HasValue)
            {
                var url    = $"/public/protectionSources/objects/{Id.ToString()}";
                var result = Session.ApiClient.Get <Model.ProtectionSource>(url);
                WriteObject(result);
            }
            else
            {
                if (IncludeDatastores.IsPresent)
                {
                    qb.Add("includeDatastores", true);
                }

                if (IncludeNetworks.IsPresent)
                {
                    qb.Add("includeNetworks", true);
                }

                if (IncludeVMFolders.IsPresent)
                {
                    qb.Add("includeVMFolders", true);
                }

                if (Environments != null && Environments.Any())
                {
                    List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                    qb.Add("environments", string.Join(",", envs));
                }

                if (ExcludeTypes != null && ExcludeTypes.Any())
                {
                    qb.Add("excludeTypes", ExcludeTypes);
                }

                var url     = $"/public/protectionSources{qb.Build()}";
                var results = Session.ApiClient.Get <IEnumerable <ProtectionSourceNode> >(url);
                results = FlattenNodes(results);

                // Extract ProtectionSource objects
                List <Model.ProtectionSource> sources = results.Select(x => x.ProtectionSource).ToList();

                WriteObject(sources, true);
            }
        }
        /// <inheritdoc />
        protected override bool CheckParameters()
        {
            // check Base-Parameters
            base.CheckParameters();

            if (Environments is null || !Environments.Any())
            {
                Output.WriteError($"no {nameof(Environments)} given -- see help for more information");
                return(false);
            }

            // if environment doesn't contain '/' or contains multiple of them...
            var errEnvironments = Environments.Where(e => !e.Contains('/') ||
                                                     e.IndexOf('/') != e.LastIndexOf('/'))
                                  .ToArray();

            // ... complain about them
            if (errEnvironments.Any())
            {
                Output.WriteError($"given environments contain errors: {string.Join("; ", errEnvironments)}");
                return(false);
            }

            // Structures may be null or empty - but if not, all entries need to be in correct format
            if (Structures?.Any() == true)
            {
                // if environment doesn't contain '/' or contains multiple of them...
                var errStructures = Structures.Where(s => !s.Contains('/') ||
                                                     s.IndexOf('/') != s.LastIndexOf('/'))
                                    .ToArray();

                // ... complain about them
                if (errStructures.Any())
                {
                    Output.WriteError($"given structures contain errors: {string.Join("; ", errStructures)}");
                    return(false);
                }
            }

            return(true);
        }
Exemple #14
0
        public Configuration(
            IReadOnlyCollection <Environment> environments,
            IReadOnlyCollection <Service> services,
            IReadOnlyCollection <CheckBase> checks)
        {
            Environments = environments ?? throw new ArgumentNullException(nameof(environments));
            Services     = services ?? throw new ArgumentNullException(nameof(services));
            Checks       = checks ?? throw new ArgumentNullException(nameof(checks));

            if (Environments.Any(e => e == null))
            {
                throw new ArgumentException("enivornments contains a null");
            }
            if (Services.Any(s => s == null))
            {
                throw new ArgumentException("services contains a null");
            }
            if (Checks.Any(c => c == null))
            {
                throw new ArgumentException("checks contains a null");
            }
        }
Exemple #15
0
        void ExecEnvRename()
        {
            if (!(EnvList.SelectedItem is Environment env))
            {
                return;
            }

            var name = env.Name;
            var ibox = new InputBox("New environment name:", "Rename Environment", name);

            ibox.Closing += (sender, args) => {
                var ib = sender as InputBox;

                if (ib.DialogResult != true)
                {
                    return;
                }

                name = ib.Text.Trim();
                if (Environments.Any(ne => ne.IsLocal && (ne.Name == name)))
                {
                    MessageBox.Show(
                        $"Environment '{name}' already exists.",
                        Strings.APP_NAME,
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                        );
                    args.Cancel = true;
                }
                ;
            };

            if (ibox.ShowDialog() != true)
            {
                return;
            }

            env.Rename(name);
        }
Exemple #16
0
        private string FindUniqueEnvironmentName(string baseName)
        {
            var number = 1;

            while (true)
            {
                var proposedName = string.Format(CultureInfo.CurrentCulture,
                                                 Resources.NewCollectionElementNameFormat,
                                                 baseName,
                                                 number == 1 ? string.Empty : number.ToString(CultureInfo.CurrentCulture)).Trim();

                if (
                    Environments.Any(
                        x => x.NameProperty != null && x.NameProperty.BindableProperty.BindableValue == proposedName))
                {
                    number++;
                }
                else
                {
                    return(proposedName);
                }
            }
        }
        /// <inheritdoc />
        protected override bool CheckParameters()
        {
            // check Base-Parameters
            if (!base.CheckParameters())
            {
                return(false);
            }

            if (Environments is null || !Environments.Any())
            {
                Output.WriteError($"no {nameof(Environments)} given -- see help for more information");
                return(false);
            }

            // if environment doesn't contain '/' or contains multiple of them...
            var errEnvironments = Environments.Where(e => !e.Contains('/') ||
                                                     e.IndexOf('/') != e.LastIndexOf('/'))
                                  .ToArray();

            // ... complain about them
            if (errEnvironments.Any())
            {
                Output.WriteError($"given environments contain errors: {string.Join("; ", errEnvironments)}");
                return(false);
            }

            // if UseInputEnvironment is given we have to check for the correct format
            if (!string.IsNullOrWhiteSpace(UseInputEnvironment) &&
                (!UseInputEnvironment.Contains('/') ||
                 UseInputEnvironment.IndexOf('/') != UseInputEnvironment.LastIndexOf('/')))
            {
                Output.WriteError("parameter '-u|--use-environment' is invalid, see 'compare --help' for the required format");
                return(false);
            }

            return(true);
        }
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Environments != null && Environments.Any())
            {
                qb.Add("environments", string.Join(",", Environments));
            }

            if (Ids != null && Ids.Any())
            {
                qb.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                qb.Add("names", string.Join(",", Names));
            }

            var preparedUrl = $"/public/protectionPolicies{qb.Build()}";
            var result      = Session.ApiClient.Get <IEnumerable <Models.ProtectionPolicy> >(preparedUrl);

            WriteObject(result, true);
        }
 public override bool HasTaskGroups()
 {
     return(Environments.Any(e => e.DeployPhases.Any(d => d.WorkflowTasks.Any(w => w.DefinitionType == "metaTask"))));
 }
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (StartTime.HasValue)
            {
                if (false == IsValidTime(StartTime))
                {
                    WriteObject("Invalid start time : " + StartTime.ToString());
                    return;
                }
                queries.Add("startTimeUsecs", StartTime.ToString());
            }

            if (EndTime.HasValue)
            {
                if (false == IsValidTime(EndTime))
                {
                    WriteObject("Invalid end time : " + EndTime.ToString());
                    return;
                }
                queries.Add("endTimeUsecs", EndTime.ToString());
            }

            if (Search != null)
            {
                queries.Add("search", Search);
            }

            if (FolderOnly != null && FolderOnly.HasValue)
            {
                queries.Add("folderOnly", FolderOnly.ToString());
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            if (JobIds != null && JobIds.Any())
            {
                queries.Add("jobIds", string.Join(",", JobIds));
            }

            if (SourceIds != null && SourceIds.Any())
            {
                queries.Add("sourceIds", string.Join(",", SourceIds));
            }

            if (RegisteredSourceIds != null && RegisteredSourceIds.Any())
            {
                queries.Add("registeredSourceIds", string.Join(",", RegisteredSourceIds));
            }

            if (StorageDomainIds != null && StorageDomainIds.Any())
            {
                queries.Add("viewBoxIds", string.Join(",", StorageDomainIds));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var url    = $"/public/restore/files{queryString}";
            var result = Session.ApiClient.Get <FileSearchResults>(url);

            WriteObject(result.Files, true);
        }
Exemple #21
0
 private bool AgentGroupIsSuppliedButNoMatchingFound(string agentGroup)
 => !string.IsNullOrWhiteSpace(agentGroup) && !Environments.Any(a => a.AgentGroup == agentGroup);
Exemple #22
0
        /// <inheritdoc />
        public EntityStorageVM(EntitiyStorage model) : base(model)
        {
            CreatureCollectionAccess = Helper.ReadOnlyObservableCollection <CreatureVM> .Create();

            EnvironmentCollectionAccess = Helper.ReadOnlyObservableCollection <EnvironmentVM> .Create();

            Creatures               = CreatureCollectionAccess.Collection;
            Environments            = EnvironmentCollectionAccess.Collection;
            EntityDependentCommands = new Collection <DelegateCommand>();

            AddCreatureCommand       = new DelegateCommand <CreatureVM>(AddCreature, o => true);
            RemoveCreatureCommand    = new DelegateCommand <CreatureVM>(RemoveCreature, o => Creatures.Any());
            ClearCreaturesCommand    = new DelegateCommand <CreatureVM>(ClearCreatures, o => Creatures.Any());
            AddEnvironmentCommand    = new DelegateCommand <EnvironmentVM>(AddEnvironment, o => true);
            RemoveEnvironmentCommand = new DelegateCommand <EnvironmentVM>(RemoveEnvironment, o => Environments.Any());
            ClearEnvironmentsCommand = new DelegateCommand <EnvironmentVM>(ClearEnvironments, o => Environments.Any());
        }
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (StartTime.HasValue)
            {
                queries.Add("startTimeUsecs", StartTime.ToString());
            }

            if (EndTime.HasValue)
            {
                queries.Add("endTimeUsecs", EndTime.ToString());
            }

            if (Search != null)
            {
                queries.Add("search", Search);
            }

            if (FolderOnly != null && FolderOnly.HasValue)
            {
                queries.Add("folderOnly", FolderOnly.ToString());
            }

            if (Environments != null && Environments.Any())
            {
                queries.Add("environments", string.Join(",", Environments));
            }

            if (JobIds != null && JobIds.Any())
            {
                queries.Add("jobIds", string.Join(",", JobIds));
            }

            if (SourceIds != null && SourceIds.Any())
            {
                queries.Add("sourceIds", string.Join(",", SourceIds));
            }

            if (RegisteredSourceIds != null && RegisteredSourceIds.Any())
            {
                queries.Add("registeredSourceIds", string.Join(",", RegisteredSourceIds));
            }

            if (StorageDomainIds != null && StorageDomainIds.Any())
            {
                queries.Add("viewBoxIds", string.Join(",", StorageDomainIds));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var url    = $"/public/restore/files{queryString}";
            var result = Session.ApiClient.Get <FileSearchResults>(url);

            WriteObject(result.Files, true);
        }
 public override bool HasVariableGroups()
 {
     return(Environments.Any(e => e.VariableGroups != null));
 }