Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add a new strict-mode configuration option #719

Closed
wants to merge 1 commit into from

Conversation

vectro
Copy link
Contributor

@vectro vectro commented Feb 28, 2023

This new configuration option disables some functionality that could be perceived as creating risks to production environments.

To begin with, that includes:

  • The checkout and rebase commands
  • Running revert without a change specified ("Revert All Changes" function).

lib/App/Sqitch.pm Outdated Show resolved Hide resolved
t/rebase.t Outdated Show resolved Hide resolved
lib/sqitch-config.pod Outdated Show resolved Hide resolved
lib/App/Sqitch/Role/RevertDeployCommand.pm Outdated Show resolved Hide resolved
@@ -484,6 +484,25 @@ by C<core.top_dir>.
The file name extension on deploy, revert, and verify SQL scripts. Defaults to
C<sql>.

=item C<core.strict>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the docs here, but I think the option and config need to be documented for every command they apply to. Should include, at least, these files, I think:

lib/sqitch-deploy.pod
lib/sqitch-revert-usage.pod
lib/sqitch-rebase.pod
lib/sqitch-revert.pod
lib/sqitch-deploy-usage.pod
lib/sqitch-checkout-usage.pod
lib/sqitch-checkout.pod
lib/sqitch-rebase-usage.pod
lib/App/Sqitch/Command/revert.pm
lib/App/Sqitch/Command/deploy.pm

The main pod files for each command also include a "Configuration Variables" that should have the strict mode documented -- anywhere the string no_prompt appears.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to extend the documentation of course, but in some of the cases that you listed I'm not sure what I would say.

  • sqitch-deploy.pod, sqitch-deploy-usage.pod, and deploy.pm: I don't think this change affects the deploy command at all?
  • sqitch-deploy-usage.pod, sqitch-checkout-usage.pod, sqitch-revert-usage.pod, and sqitch-rebase-usage.pod: These files don't seem to currently describe configuration options at all. Are you proposing to add new sections?
  • deploy.pm and revert.pm: It looks to me like these are only documenting the attributes, not the configuration, is that wrong? I don't think this PR changes any of the attributes for these two modules.

The main pod files for each command also include a "Configuration Variables" that should have the strict mode documented -- anywhere the string no_prompt appears.

I think this is covered by your suggestions above, but let me know if you disagree.

I will push a change to sqitch-rebase.pod, sqitch-revert.pod, sqitch-checkout.pod in the meantime.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Right, not deploy, sorry.
  • I see options listed in the -usage.pod files; new ones like --strict that apply to each command should be added (this is related to my other request not to make it a global option I guess).
  • Yeah, if you move the option to revert.pm it would then need to be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I don't think we are adding new options here, only new configuration variables.

Unless there is something which I don't understand that automatically creates options from configuration settings?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. In that case it should probably follow the cascading configuration pattern of

  1. --strict
  2. $cmd.strict
  3. target.$name.strict
  4. engine.$name.strict
  5. core.strict

Most of that resolution is done in App::Sqitch::Target, using the _fetch method:

sub _fetch {
my ($self, $key) = @_;
my $config = $self->_config;
return $config->get( key => "target." . $self->name . ".$key" )
|| do {
my $ekey = $self->engine_key;
$ekey ? $config->get( key => "engine.$ekey.$key") : ();
} || $config->get( key => "core.$key");
}

I think it'd be fine to do so in a subsequent PR.

theory
theory previously approved these changes Mar 19, 2023
lib/App/Sqitch/Command/revert.pm Outdated Show resolved Hide resolved
@@ -484,6 +484,25 @@ by C<core.top_dir>.
The file name extension on deploy, revert, and verify SQL scripts. Defaults to
C<sql>.

=item C<core.strict>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. In that case it should probably follow the cascading configuration pattern of

  1. --strict
  2. $cmd.strict
  3. target.$name.strict
  4. engine.$name.strict
  5. core.strict

Most of that resolution is done in App::Sqitch::Target, using the _fetch method:

sub _fetch {
my ($self, $key) = @_;
my $config = $self->_config;
return $config->get( key => "target." . $self->name . ".$key" )
|| do {
my $ekey = $self->engine_key;
$ekey ? $config->get( key => "engine.$ekey.$key") : ();
} || $config->get( key => "core.$key");
}

I think it'd be fine to do so in a subsequent PR.

Copy link
Collaborator

@theory theory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, did some thinking through of this proposal again, and here's where I'm at:

  • Like no_prompt, strict should be configured as a revert variable only, revert.strict. And just as no_prompt can be set by -y, so too can strict be set by --strict, but also by --no-strict. There is no need for core.strict because it applies to no other actions other than revert.
  • Why not allow the rebase command to succeed when strict is enabled as long as to_change is set?
  • The checkout command always has an implicit target: the most recent common change between the current and target branches. Why disable it?
  • The --strict option must be documented for every command where it's relevant. Based on the -y option, that's:
    • lib/sqitch-checkout-usage.pod
    • lib/sqitch-checkout.pod
    • lib/sqitch-rebase-usage.pod
    • lib/sqitch-rebase.pod
    • lib/sqitch-revert-usage.pod
    • lib/sqitch-revert.pod
  • Likewise, the revert.strict config variable should be documented anywhere revert.no_prompt is documented, which appears to be:
    • lib/sqitch-rebase.pod
    • lib/sqitch-revert.pod
    • lib/sqitch-checkout.pod
    • lib/App/Sqitch/Role/RevertDeployCommand.pm
    • lib/App/Sqitch/Command/revert.pm

Depending on where we come down on the affect on rebase and checkout, we may want to also add support for rebase.strict and checkout.strict, again just like no_prompt, but that may be excessive.

What do you think?

@vectro
Copy link
Contributor Author

vectro commented Mar 24, 2023

Hi David,

Do you mind saying more about the use case that you imagine for the --strict and --no-strict command line options?

In my mind, the purpose of the strict mode is to prevent the accidental use of potentially dangerous features, either by users who are not familiar with Sqitch, or by users who might be familiar with these commands but targeting the wrong environment. In other words, it's to protect users from accidentally doing the wrong thing.

From that perspective I don't understand the situation where someone would want to enable or disable this on the command line. If you want the strict behavior, I would think you especially want it in situations where people didn't think to ask for it.

Ian

@theory
Copy link
Collaborator

theory commented Mar 24, 2023

Ah yes, I was working off the assumption that almost every configuration in Sqitch also has an option; overlooked that your PR does not.

In that case, though, I think it makes sense to follow the prompt_accept configuration, which does not have an equivalent option, and is set via revert.prompt_accept' (no core.prompt_accept), and overridden by checkout.prompt_acceptorrebase.prompt_accept`.

It might be useful to extend these two options to targets, too, as I mentioned earlier, but not necessary here.

@vectro
Copy link
Contributor Author

vectro commented Mar 27, 2023

It might be useful to extend these two options to targets

I agree, but maybe we can do that in a subsequent MR?

@theory
Copy link
Collaborator

theory commented Mar 27, 2023

I agree, but maybe we can do that in a subsequent MR?

Yes, absolutely.

@vectro
Copy link
Contributor Author

vectro commented Mar 28, 2023

Why not allow the rebase command to succeed when strict is enabled as long as to_change is set?

I guess my belief is that this command is good for rapid development but that when it comes to production deployments (where reverting can cause data loss) it would be better to be more explicit about what changes should be reverted. The whole idea of reverting and then re-deploying seems to me like an exceptional workflow in a production environment — even though it could happen from time to time, it's better to be explicit about it.

(Assuming you meant onto-change, let me know if I misunderstood the suggestion)

@vectro
Copy link
Contributor Author

vectro commented Mar 28, 2023

The checkout command always has an implicit target: the most recent common change between the current and target branches. Why disable it?

It's less about the possibility that all changes would be reverted and more about the possibility than anything could be reverted without the operator having the specific intention to revert those specific changes. In other words, "implied target change" is probably usually better than "revert everything", but still risky.

functionality that could be perceived as creating risks to production
environments.
@vectro
Copy link
Contributor Author

vectro commented Mar 28, 2023

@theory What do you think about this latest attempt?

@theory
Copy link
Collaborator

theory commented Apr 1, 2023

(Assuming you meant onto-change, let me know if I misunderstood the suggestion)

Yes, that's what I meant, was thinking about it from the POV of consistency. This is part of why I've been thinking it'd be useful to support the option at the target level, as you would want strict enabled for a prod target but not a dev target. That said, we can leave it as revert.strict and the disabling behavior, and recommend that it be used at the --user or --system config level. You'd enable it on whatever box was responsible for production reverts.

@theory
Copy link
Collaborator

theory commented Apr 1, 2023

@theory What do you think about this latest attempt?

Looks good, I think it's almost there. I'll pull it down and give it a through review this weekend. Thanks!

@theory theory mentioned this pull request Apr 3, 2023
@theory
Copy link
Collaborator

theory commented Apr 3, 2023

Have a look at #735, @vectro. If it looks good to you I'll merge it (which will also merge this PR). Thanks!

@theory
Copy link
Collaborator

theory commented Apr 10, 2023

Closing in favor of #735, which includes your commit.

@theory theory closed this Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants