Skip to content

Commit

Permalink
Accept reason parameter upon flag update command execution (#22)
Browse files Browse the repository at this point in the history
* Accept reason parameter upon flag update command execution

* Escape query param
  • Loading branch information
z4kn4fein committed May 7, 2024
1 parent 9bc2872 commit f72341f
Show file tree
Hide file tree
Showing 31 changed files with 113 additions and 53 deletions.
1 change: 1 addition & 0 deletions docs/configcat-flag-percentage-clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ configcat flag % clear -i <flag-id> -e <environment-id>
| ------ | ----------- |
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment from where the rules must be deleted |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-percentage-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ configcat flag % update -i <flag-id> -e <environment-id> 30:true 70:false
| ------ | ----------- |
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment where the update must be applied |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-targeting-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ configcat flag targeting create -i <flag-id> -e <environment-id> -a Email -c con
| `--flag-value`, `-f` | The value to serve when the comparison matches, it must respect the setting type |
| `--segment-id`, `-si` | ID of the Segment used in the rule |
| `--segment-comparator`, `-sc` | The segment comparison operator<br/><br/>*Possible values*: `isIn`, `isNotIn` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-targeting-move.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ configcat flag targeting move -i <flag-id> -e <environment-id> --from 0 --to 1
| `--environment-id`, `-e` | ID of the Environment where the move must be applied |
| `--from` | The position of the targeting rule to move |
| `--to` | The desired position of the targeting rule |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-targeting-rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ configcat flag targeting rm -i <flag-id> -e <environment-id> -p 1
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment from where the rule must be deleted |
| `--position`, `-p` | The position of the targeting rule to delete |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-targeting-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ configcat flag targeting update -i <flag-id> -e <environment-id> -p 1 -a Email -
| `--flag-value`, `-f` | The value to serve when the comparison matches, it must respect the setting type |
| `--segment-id`, `-si` | ID of the Segment used in the rule |
| `--segment-comparator`, `-sc` | The segment comparison operator<br/><br/>*Possible values*: `isIn`, `isNotIn` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configcat flag-v2 targeting condition add prerequisite -i <flag-id> -e <environm
| `--comparator`, `-c` | The operator which defines the relation between the evaluated value of the prerequisite flag and the comparison value<br/><br/>*Possible values*: `doesNotEqual`, `equals` |
| `--prerequisite-id`, `-pi` | ID of the prerequisite flag that the condition is based on |
| `--prerequisite-value`, `-pv` | The evaluated value of the prerequisite flag is compared to. It must respect the prerequisite flag's setting type |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-condition-add-segment.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configcat flag-v2 targeting condition add segment -i <flag-id> -e <environment-i
| `--rule-position`, `-rp` | The position of the targeting rule to which the condition is added |
| `--comparator`, `-c` | The operator which defines the expected result of the evaluation of the segment<br/><br/>*Possible values*: `isIn`, `isNotIn` |
| `--segment-id`, `-si` | ID of the segment that the condition is based on |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-condition-add-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configcat flag-v2 targeting condition add user -i <flag-id> -e <environment-id>
| `--attribute`, `-a` | The User Object attribute that the condition is based on |
| `--comparator`, `-c` | The operator which defines the relation between the comparison attribute and the comparison value<br/><br/>*Possible values*: `arrayContainsAnyOf`, `arrayDoesNotContainAnyOf`, `containsAnyOf`, `dateTimeAfter`, `dateTimeBefore`, `doesNotContainAnyOf`, `isNotOneOf`, `isOneOf`, `numberDoesNotEqual`, `numberEquals`, `numberGreater`, `numberLess`, `numberLessOrEquals`, `semVerGreater`, `semVerGreaterOrEquals`, `semVerIsNotOneOf`, `semVerIsOneOf`, `semVerLess`, `semVerLessOrEquals`, `sensitiveArrayContainsAnyOf`, `sensitiveArrayDoesNotContainAnyOf`, `sensitiveIsNotOneOf`, `sensitiveIsOneOf`, `sensitiveTextDoesNotEqual`, `sensitiveTextEndsWithAnyOf`, `sensitiveTextEquals`, `sensitiveTextNotEndsWithAnyOf`, `sensitiveTextNotStartsWithAnyOf`, `sensitiveTextStartsWithAnyOf`, `textDoesNotEqual`, `textEndsWithAnyOf`, `textEquals`, `textNotEndsWithAnyOf`, `textNotStartsWithAnyOf`, `textStartsWithAnyOf` |
| `--comparison-value`, `-cv` | The value that the User Object attribute is compared to. Can be a double, string, or value-hint list in the format: `<value>:<hint>` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-condition-rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ configcat flag-v2 targeting condition rm -i <flag-id> -e <environment-id> -rp 1
| `--environment-id`, `-e` | ID of the Environment where the condition must be removed |
| `--rule-position`, `-rp` | The position of the targeting rule |
| `--condition-position`, `-cp` | The position of the condition to remove |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-percentage-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ configcat flag-v2 targeting % attribute -i <flag-id> -e <environment-id>
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment from where the rules must be deleted |
| `--attribute-name`, `-n` | The User Object attribute which serves as the basis of percentage options evaluation |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-percentage-clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ configcat flag-v2 targeting % clear -i <flag-id> -e <environment-id>
| ------ | ----------- |
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment from where the rule must be deleted |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-percentage-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ configcat flag-v2 targeting % update -i <flag-id> -e <environment-id> -po 30:tru
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment where the update must be applied |
| `-po`, `--percentage-options` | Format: `<percentage>:<value>`, e.g., `30:true 70:false` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ configcat flag-v2 targeting rule create prerequisite -i <flag-id> -e <environmen
| `--prerequisite-value`, `-pv` | The evaluated value of the prerequisite flag is compared to. It must respect the prerequisite flag's setting type |
| `--served-value`, `-sv` | The value associated with the targeting rule. Leave it empty if the targeting rule has percentage options. It must respect the setting type |
| `-po`, `--percentage-options` | Format: `<percentage>:<value>`, e.g., `30:true 70:false` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-rule-create-segment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configcat flag-v2 targeting rule create segment -i <flag-id> -e <environment-id>
| `--segment-id`, `-si` | ID of the segment that the condition is based on |
| `--served-value`, `-sv` | The value associated with the targeting rule. Leave it empty if the targeting rule has percentage options. It must respect the setting type |
| `-po`, `--percentage-options` | Format: `<percentage>:<value>`, e.g., `30:true 70:false` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-rule-create-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ configcat flag-v2 targeting rule create user -i <flag-id> -e <environment-id> -a
| `--comparison-value`, `-cv` | The value that the User Object attribute is compared to. Can be a double, string, or value-hint list in the format: `<value>:<hint>` |
| `--served-value`, `-sv` | The value associated with the targeting rule. Leave it empty if the targeting rule has percentage options. It must respect the setting type |
| `-po`, `--percentage-options` | Format: `<percentage>:<value>`, e.g., `30:true 70:false` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-rule-move.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ configcat flag-v2 targeting rule mv -i <flag-id> -e <environment-id> --from 1 --
| `--environment-id`, `-e` | ID of the Environment where the rule should be moved |
| `--from` | The position of the targeting rule to move |
| `--to` | The desired position of the targeting rule |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-targeting-rule-rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ configcat flag-v2 targeting rule rm -i <flag-id> -e <environment-id> -rp 1
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment where the rule must be removed |
| `--rule-position`, `-rp` | The position of the targeting rule to remove |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configcat flag-v2 targeting rule usv -i <flag-id> -e <environment-id> -rp 1 -sv
| `--rule-position`, `-rp` | The position of the targeting rule |
| `--served-value`, `-sv` | The value associated with the targeting rule. Leave it empty if the targeting rule has percentage options. It must respect the setting type |
| `-po`, `--percentage-options` | Format: `<percentage>:<value>`, e.g., `30:true 70:false` |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-v2-value-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ configcat flag-v2 value update -i <flag-id> -e <environment-id> -f true
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment where the update must be applied |
| `--flag-value`, `-f` | The value to serve, it must respect the setting type |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
1 change: 1 addition & 0 deletions docs/configcat-flag-value-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ configcat flag value update -i <flag-id> -e <environment-id> -f true
| `--flag-id`, `-i`, `--setting-id` | ID of the Feature Flag or Setting |
| `--environment-id`, `-e` | ID of the Environment where the update must be applied |
| `--flag-value`, `-f` | The value to serve, it must respect the setting type |
| `--reason`, `-r` | The reason note for the Audit Log if the Product's 'Config changes require a reason' preference is turned on |
| `--verbose`, `-v`, `/v` | Print detailed execution information |
| `--non-interactive`, `-ni` | Turn off progress rendering and interactive features |
| `-h`, `/h`, `--help`, `-?`, `/?` | Show help and usage information |
Expand Down
15 changes: 8 additions & 7 deletions src/ConfigCat.Cli.Services/Api/FlagValueClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ConfigCat.Cli.Models.Api;
using System;
using ConfigCat.Cli.Models.Api;
using ConfigCat.Cli.Models.Configuration;
using ConfigCat.Cli.Services.Json;
using ConfigCat.Cli.Services.Rendering;
Expand All @@ -14,9 +15,9 @@ public interface IFlagValueClient
{
Task<FlagValueModel> GetValueAsync(int settingId, string environmentId, CancellationToken token);

Task ReplaceValueAsync(int settingId, string environmentId, FlagValueModel model, CancellationToken token);
Task ReplaceValueAsync(int settingId, string environmentId, string reason, FlagValueModel model, CancellationToken token);

Task UpdateValueAsync(int settingId, string environmentId, List<JsonPatchOperation> operations, CancellationToken token);
Task UpdateValueAsync(int settingId, string environmentId, string reason, List<JsonPatchOperation> operations, CancellationToken token);
}

public class FlagValueClient(
Expand All @@ -29,18 +30,18 @@ public class FlagValueClient(
public Task<FlagValueModel> GetValueAsync(int settingId, string environmentId, CancellationToken token) =>
this.GetAsync<FlagValueModel>(HttpMethod.Get, $"v1/environments/{environmentId}/settings/{settingId}/value", token);

public async Task ReplaceValueAsync(int settingId, string environmentId, FlagValueModel model, CancellationToken token)
public async Task ReplaceValueAsync(int settingId, string environmentId, string reason, FlagValueModel model, CancellationToken token)
{
this.Output.Write($"Updating Flag Value... ");
await this.SendAsync(HttpMethod.Put, $"v1/environments/{environmentId}/settings/{settingId}/value", model, token);
await this.SendAsync(HttpMethod.Put, $"v1/environments/{environmentId}/settings/{settingId}/value{(string.IsNullOrWhiteSpace(reason)? string.Empty : $"?reason={Uri.EscapeDataString(reason)}")}", model, token);
this.Output.WriteSuccess();
this.Output.WriteLine();
}

public async Task UpdateValueAsync(int settingId, string environmentId, List<JsonPatchOperation> operations, CancellationToken token)
public async Task UpdateValueAsync(int settingId, string environmentId, string reason, List<JsonPatchOperation> operations, CancellationToken token)
{
this.Output.Write($"Updating Flag Value... ");
await this.SendAsync(HttpMethod.Patch, $"v1/environments/{environmentId}/settings/{settingId}/value", operations, token);
await this.SendAsync(HttpMethod.Patch, $"v1/environments/{environmentId}/settings/{settingId}/value{(string.IsNullOrWhiteSpace(reason)? string.Empty : $"?reason={Uri.EscapeDataString(reason)}")}", operations, token);
this.Output.WriteSuccess();
this.Output.WriteLine();
}
Expand Down

0 comments on commit f72341f

Please sign in to comment.