mirror of https://github.com/status-im/consul.git
Stop use of templated-policy and templated-policy-file simultaneously (#19389)
This commit is contained in:
parent
3b806d41c0
commit
ea91e58045
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
cli: stop simultaneous usage of -templated-policy and -templated-policy-file when creating a role or token.
|
||||||
|
```
|
|
@ -94,6 +94,13 @@ func (c *cmd) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.templatedPolicyFile) != 0 && len(c.templatedPolicy) != 0 {
|
||||||
|
c.UI.Error("Cannot combine the use of templated-policy flag with templated-policy-file. " +
|
||||||
|
"To create a role with a single templated policy and simple use case, use -templated-policy. " +
|
||||||
|
"For multiple templated policies and more complicated use cases, use -templated-policy-file")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
client, err := c.http.APIClient()
|
client, err := c.http.APIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
||||||
|
|
|
@ -115,6 +115,22 @@ func TestRoleCreateCommand_Pretty(t *testing.T) {
|
||||||
|
|
||||||
require.Len(t, role.NodeIdentities, 1)
|
require.Len(t, role.NodeIdentities, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("prevent templated-policy and templated-policy-file simultaneous use", func(t *testing.T) {
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
cmd := New(ui)
|
||||||
|
|
||||||
|
code := cmd.Run([]string{
|
||||||
|
"-http-addr=" + a.HTTPAddr(),
|
||||||
|
"-token=root",
|
||||||
|
"-name=role-with-node-identity",
|
||||||
|
"-templated-policy=builtin/node",
|
||||||
|
"-var=name:" + a.Config.NodeName,
|
||||||
|
"-templated-policy-file=test.hcl",
|
||||||
|
})
|
||||||
|
require.Equal(t, 1, code)
|
||||||
|
require.Contains(t, ui.ErrorWriter.String(), "Cannot combine the use of templated-policy flag with templated-policy-file.")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRoleCreateCommand_JSON(t *testing.T) {
|
func TestRoleCreateCommand_JSON(t *testing.T) {
|
||||||
|
|
|
@ -105,6 +105,13 @@ func (c *cmd) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.templatedPolicyFile) != 0 && len(c.templatedPolicy) != 0 {
|
||||||
|
c.UI.Error("Cannot combine the use of templated-policy flag with templated-policy-file. " +
|
||||||
|
"To create a token with a single templated policy and simple use case, use -templated-policy. " +
|
||||||
|
"For multiple templated policies and more complicated use cases, use -templated-policy-file")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
client, err := c.http.APIClient()
|
client, err := c.http.APIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
||||||
|
|
|
@ -128,6 +128,21 @@ func TestTokenCreateCommand_Pretty(t *testing.T) {
|
||||||
require.Equal(t, a.Config.NodeName, nodes[0].Node)
|
require.Equal(t, a.Config.NodeName, nodes[0].Node)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("prevent templated-policy and templated-policy-file simultaneous use", func(t *testing.T) {
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
cmd := New(ui)
|
||||||
|
|
||||||
|
code := cmd.Run(append([]string{
|
||||||
|
"-http-addr=" + a.HTTPAddr(),
|
||||||
|
"-token=root",
|
||||||
|
"-templated-policy=builtin/node",
|
||||||
|
"-var=name:" + a.Config.NodeName,
|
||||||
|
"-templated-policy-file=test.hcl",
|
||||||
|
}, "-format=json"))
|
||||||
|
require.Equal(t, 1, code)
|
||||||
|
require.Contains(t, ui.ErrorWriter.String(), "Cannot combine the use of templated-policy flag with templated-policy-file.")
|
||||||
|
})
|
||||||
|
|
||||||
// create with accessor and secret
|
// create with accessor and secret
|
||||||
t.Run("predefined-ids", func(t *testing.T) {
|
t.Run("predefined-ids", func(t *testing.T) {
|
||||||
token := run(t, []string{
|
token := run(t, []string{
|
||||||
|
|
Loading…
Reference in New Issue