Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

IRunbookRepository.CreateOrModify seems to be completely broken when creating new runbooks #652

Open
ronnieoverby opened this issue Apr 18, 2022 · 0 comments

Comments

@ronnieoverby
Copy link

ronnieoverby commented Apr 18, 2022

Unless I'm mistaken, a new runbook can never be created when using the runbook repositories CreateOrModify method because a retention policy is required but there's no means to supply one.

Example

var clientFactory = new OctopusClientFactory();

using var client = await clientFactory.CreateAsyncClient(
	new OctopusServerEndpoint("https://octopus.whatever.com", "******************************"));

var project = await client.Repository.Projects.Get("Projects-1234");

var editor = await client.Repository.Runbooks.CreateOrModify(project, $"test_{Environment.TickCount}", "This shouldn't exist, yet!"); // <- OctopusValidationException

Error:

[OctopusValidationException]
There was a problem with your request.

  • Please assign a run retention policy to the Runbook.

Here's an extension method I've created to replace the broken CreateOrModify(…) method:

public static class OctopusClientExtensions
{
    /// <summary>
    /// This is analogous to the out-of-the-box CreateOrModify method, which seems to be broken at the moment.
    /// This version supports modifying the resource prior to being saved.
    /// The shipped implementation of the method fails to create a new runbook because retention policy is required,
    /// but there's no means of supplying one.
    ///
    /// The delegate is provided a tuple with the runbook resource and a boolean indicating if the runbook is being created
    /// for the first time.
    /// </summary>
    public static async Task<RunbookResource> CreateOrModify(this IRunbookRepository repository, ProjectResource project, string name,
        Action<(RunbookResource Runbook, bool IsNew)> mutate)
    {
        var runbook = await repository.FindByName(project, name).ConfigureAwait(false);

        if (runbook == null)
        {
            runbook = new RunbookResource
            {
                ProjectId = project.Id,
                Name = name
            };

            mutate?.Invoke((runbook, true));
            return await repository.Create(runbook);
        }

        mutate?.Invoke((runbook, false));
        return await repository.Modify(runbook);
    }
}

Please let me know if I'm simply using the client incorrectly!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant