public async Task <VariableSetResource> Get(ProjectResource projectResource, string gitRef = null)
        {
            if (ProjectHasVariablesInGit(projectResource))
            {
                if (gitRef is not null)
                {
                    return(await client.Get <VariableSetResource>(projectResource.Link("Variables"), new { gitRef }));
                }

                return(await client.Get <VariableSetResource>(projectResource.Link("SensitiveVariables")));
            }

            return(await client.Get <VariableSetResource>(projectResource.Link("Variables")));
        }
Example #2
0
        public async Task <DeploymentSettingsResource> Get(ProjectResource projectResource)
        {
            if (projectResource.PersistenceSettings is GitPersistenceSettingsResource vcsResource)
            {
                return(await Get(projectResource, vcsResource.DefaultBranch));
            }

            return(await client.Get <DeploymentSettingsResource>(projectResource.Link("DeploymentSettings")));
        }
        public DeploymentProcessResource Get(ProjectResource projectResource)
        {
            if (projectResource.PersistenceSettings is GitPersistenceSettingsResource vcsResource)
            {
                return(Get(projectResource, vcsResource.DefaultBranch));
            }

            return(Client.Get <DeploymentProcessResource>(projectResource.Link("DeploymentProcess")));
        }
        public DeploymentProcessResource Get(ProjectResource projectResource, string gitRef)
        {
            if (!projectResource.IsVersionControlled)
            {
                throw new NotSupportedException(
                          $"Database backed projects require using the overload that does not include a gitRef parameter.");
            }

            return(Client.Get <DeploymentProcessResource>(projectResource.Link("DeploymentProcess"), new { gitRef }));
        }
        public DeploymentSettingsResource Get(ProjectResource project)
        {
            string gitRef = null;

            if (project.PersistenceSettings is GitPersistenceSettingsResource vcsResource)
            {
                gitRef = vcsResource.DefaultBranch;
            }
            return(client.Get <DeploymentSettingsResource>(project.Link("DeploymentSettings"), new { gitRef }));
        }
        public async Task <DeploymentProcessResource> Get(ProjectResource projectResource, string gitref = null)
        {
            if (!string.IsNullOrWhiteSpace(gitref))
            {
                var branchResource = await repository.Projects.Beta().GetVersionControlledBranch(projectResource, gitref);

                return(await client.Get <DeploymentProcessResource>(branchResource.Link("DeploymentProcess")));
            }

            return(await client.Get <DeploymentProcessResource>(projectResource.Link("DeploymentProcess")));
        }
        public DeploymentSettingsResource Get(ProjectResource projectResource, string gitref = null)
        {
            if (!string.IsNullOrWhiteSpace(gitref))
            {
                var branchResource = repository.Projects.Beta().GetVersionControlledBranch(projectResource, gitref);

                return(client.Get <DeploymentSettingsResource>(branchResource.Link("DeploymentSettings")));
            }

            return(client.Get <DeploymentSettingsResource>(projectResource.Link("DeploymentSettings")));
        }
        /// <summary>
        /// Gets the Channels of the passed Project
        /// </summary>
        /// <param name="client">The Repository this is tacked on to.</param>
        /// <param name="project">The Project to get Channels of</param>
        /// <returns></returns>
        internal static IEnumerable <ChannelResource> GetProjectChannels(this IOctopusClient client, ProjectResource project)
        {
            List <ChannelResource> channels = new List <ChannelResource>();

            client.Paginate <ChannelResource>(project.Link(ResourceStrings.ChannelLink), new { }, page =>
            {
                channels.AddRange(page.Items);
                return(true);
            });
            return(channels);
        }
Example #9
0
        public async Task <ConvertProjectToVersionControlledResponse> ConvertToVersionControlled(ProjectResource project, VersionControlSettingsResource versionControlSettings,
                                                                                                 string commitMessage)
        {
            var payload = new ConvertProjectToVersionControlledCommand
            {
                VersionControlSettings = versionControlSettings,
                CommitMessage          = commitMessage
            };

            var url      = project.Link("ConvertToVcs");
            var response = await client.Post <ConvertProjectToVersionControlledCommand, ConvertProjectToVersionControlledResponse>(url, payload);

            return(response);
        }
        public DeploymentProcessResource Modify(ProjectResource projectResource, DeploymentProcessResource resource, string commitMessage = null)
        {
            if (!projectResource.IsVersionControlled)
            {
                return(client.Update(projectResource.Link("DeploymentProcess"), resource));
            }

            var commitResource = new CommitResource <DeploymentProcessResource>
            {
                Resource      = resource,
                CommitMessage = commitMessage
            };

            client.Put(resource.Link("Self"), commitResource);
            return(client.Get <DeploymentProcessResource>(resource.Link("Self")));
        }
Example #11
0
 public VersionControlBranchResource[] GetVersionControlledBranches(ProjectResource projectResource)
 {
     return(client.Get <VersionControlBranchResource[]>(projectResource.Link("Branches")));
 }
 public Task <ProjectTriggerResource> FindByName(ProjectResource project, string name)
 {
     return(FindByName(name, path: project.Link("Triggers")));
 }
 public Task <ChannelResource> FindByName(ProjectResource project, string name)
 {
     return(FindByName(name, path: project.Link("Channels")));
 }
Example #14
0
 public RunbookResource FindByName(ProjectResource project, string name)
 {
     return(FindByName(name, path: project.Link("Runbooks")));
 }
Example #15
0
 public VersionControlBranchResource GetVersionControlledBranch(ProjectResource projectResource, string branch)
 {
     return(client.Get <VersionControlBranchResource>(projectResource.Link("Branches"), new { name = branch }));
 }
Example #16
0
 public ResourceCollection <VersionControlBranchResource> GetVersionControlledBranches(ProjectResource projectResource)
 {
     return(client.Get <ResourceCollection <VersionControlBranchResource> >(projectResource.Link("Branches")));
 }
Example #17
0
        public static void OctoImportVariables(this ICakeContext context,
                                               string octopusServerEndpoint,
                                               string octopusProjectName,
                                               string octopusApiKey,
                                               IEnumerable <OctoVariable> variables,
                                               bool clearAllNonSensitiveExistingVariables = false)
        {
            try
            {
                IOctopusAsyncClient client = new OctopusClientFactory().CreateAsyncClient(new OctopusServerEndpoint(octopusServerEndpoint, octopusApiKey)).Result;
                var octopus = new OctopusAsyncRepository(client);

                ProjectResource project = octopus.Projects.FindByName(octopusProjectName).Result;

                VariableSetResource variableSet = octopus.VariableSets.Get(project.Link("Variables")).Result;

                if (clearAllNonSensitiveExistingVariables)
                {
                    context.Log.Information($"Deleting all nonsensitive variables...");

                    List <VariableResource> sensitiveVariables = variableSet.Variables.Where(variable => variable.IsSensitive).ToList();

                    variableSet.Variables.Clear();

                    sensitiveVariables.ForEach(sensitiveVariable => { variableSet.Variables.Add(sensitiveVariable); });

                    context.Log.Information($"Deleting operation finished.");
                }

                foreach (OctoVariable variable in variables)
                {
                    var newVariable = new VariableResource
                    {
                        Name        = variable.Name,
                        Value       = variable.Value,
                        IsSensitive = variable.IsSensitive,
                        Type        = variable.IsSensitive ? VariableType.Sensitive : VariableType.String,
                        IsEditable  = variable.IsEditable,
                        Scope       = CreateScopeSpesification(variable, variableSet)
                    };

                    string scopeNames = CreateScopeInformationsForLogging(variable);

                    VariableResource existingVariable = variableSet.Variables.FirstOrDefault(x => x.Name == variable.Name && x.Scope.Equals(newVariable.Scope));
                    if (existingVariable != null)
                    {
                        context.Log.Information($"Variable: ({variable.Name}), Scopes:({scopeNames}) already exists in octopus, trying to update...");

                        variableSet.AddOrUpdateVariableValue(existingVariable.Name, newVariable.Value, newVariable.Scope, newVariable.IsSensitive);

                        context.Log.Information($"Variable: ({variable.Name}), Scopes:({scopeNames}) updated successfully...");
                    }
                    else
                    {
                        context.Log.Information($"New Variable: ({variable.Name}), Scopes:({scopeNames}) detected, trying to add...");

                        variableSet.Variables.Add(newVariable);

                        context.Log.Information($"New Variable: ({variable.Name}), Scopes:({scopeNames}) added successfully...");
                    }
                }

                octopus.VariableSets.Modify(variableSet).Wait();
                octopus.VariableSets.Refresh(variableSet).Wait();

                context.Log.Information($"Variables are all successfully set.");
            }
            catch (Exception exception)
            {
                throw new CakeException(exception.Message, exception.InnerException);
            }
        }
Example #18
0
        public async Task <ConvertProjectVariablesToGitResponse> MigrateVariablesToGit(ProjectResource projectResource, string branch, string commitMessage)
        {
            if (ProjectHasVariablesInGit(projectResource))
            {
                throw new NotSupportedException("Project variables have already been migrated to Git");
            }

            var command = new ConvertProjectVariablesToGitCommand
            {
                Branch        = branch,
                CommitMessage = commitMessage
            };

            if (!projectResource.HasLink("MigrateVariablesToGit"))
            {
                throw new NotSupportedException("Git variables migration is not available for this project");
            }

            return(await client.Post <ConvertProjectVariablesToGitCommand, ConvertProjectVariablesToGitResponse>(projectResource.Link("MigrateVariablesToGit"), command));
        }