Skip to content

Commit f4bbf2c

Browse files
committed
add flag to the plugin
1 parent e44907d commit f4bbf2c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

internal/flags/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ type Flags struct {
99
// ShowConfigToken determines if the configuration token value should be displayed when accessing the configuration endpoint.
1010
ShowConfigToken bool `json:"show_config_token" mapstructure:"show_config_token"`
1111

12+
// AllowPathOverridePersonalToken determines if the personal token can be overridden by a path override for the username.
13+
AllowPathOverridePersonalToken bool `json:"allow_path_override_personal_token" mapstructure:"allow_path_override_personal_token"`
14+
1215
// AllowRuntimeFlagsChange determines whether runtime flags can be dynamically modified during execution.
1316
AllowRuntimeFlagsChange bool `json:"allow_runtime_flags_change" mapstructure:"allow_runtime_flags_change"`
1417
}
@@ -17,5 +20,6 @@ type Flags struct {
1720
func (f *Flags) FlagSet(fs *flag.FlagSet) *flag.FlagSet {
1821
fs.BoolVar(&f.ShowConfigToken, "show-config-token", false, "Display the token value when reading it's config the configuration endpoint.")
1922
fs.BoolVar(&f.AllowRuntimeFlagsChange, "allow-runtime-flags-change", false, "Allows you to change the flags dynamically at runtime.")
23+
fs.BoolVar(&f.AllowPathOverridePersonalToken, "allow-path-override-personal-token", false, "Allows you to override the personal token for a specific username.")
2024
return fs
2125
}

path_flags.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ var FieldSchemaFlags = map[string]*framework.FieldSchema{
2424
Default: false,
2525
DisplayAttrs: &framework.DisplayAttributes{Name: "Show Config Token"},
2626
},
27+
"allow_path_override_personal_token": {
28+
Type: framework.TypeBool,
29+
Description: "Allow path override for personal token.",
30+
Default: false,
31+
DisplayAttrs: &framework.DisplayAttributes{Name: "Allow Path Override for Personal Token"},
32+
},
2733
}
2834

2935
func (b *Backend) pathFlagsRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (lResp *logical.Response, err error) {
@@ -45,6 +51,11 @@ func (b *Backend) pathFlagsUpdate(ctx context.Context, req *logical.Request, dat
4551
eventData["show_config_token"] = strconv.FormatBool(b.flags.ShowConfigToken)
4652
}
4753

54+
if allowPathOverridePersonalToken, ok := data.GetOk("allow_path_override_personal_token"); ok {
55+
b.flags.AllowPathOverridePersonalToken = allowPathOverridePersonalToken.(bool)
56+
eventData["allow_path_override_personal_token"] = strconv.FormatBool(b.flags.AllowPathOverridePersonalToken)
57+
}
58+
4859
_ = event.Event(ctx, b.Backend, "flags-write", eventData)
4960

5061
var flagData map[string]any

path_flags_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ func TestPathFlags(t *testing.T) {
3131
Operation: logical.UpdateOperation,
3232
Path: gitlab.PathConfigFlags, Storage: l,
3333
Data: map[string]interface{}{
34-
"show_config_token": "true",
34+
"show_config_token": "true",
35+
"allow_path_override_personal_token": "true",
3536
},
3637
})
3738

3839
require.NoError(t, err)
3940
require.NotNil(t, resp)
4041
require.NoError(t, resp.Error())
4142
require.True(t, resp.Data["show_config_token"].(bool))
43+
require.True(t, resp.Data["allow_path_override_personal_token"].(bool))
4244

4345
events.expectEvents(t, []expectedEvent{
4446
{eventType: "gitlab/flags-write"},

0 commit comments

Comments
 (0)