Add TargetAliasAuthorizeSessionArgumentsHostId api options (#4397)
* Add host id api option
This commit is contained in:
1 parent
ba21e076bb
commit
a6c96d69ae
3 files changed
+79
-17
No files matched your search
@@ -0,0 +1,43 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package aliases
|
||||
|
||||
func WithTargetAliasAuthorizeSessionArgumentsHostId(hid string) Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
attrVal := raw.(map[string]interface{})
|
||||
argRaw, ok := attrVal["authorize_session_arguments"]
|
||||
if !ok {
|
||||
argRaw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
argVal := argRaw.(map[string]interface{})
|
||||
argVal["host_id"] = hid
|
||||
attrVal["authorize_session_arguments"] = argVal
|
||||
|
||||
o.postMap["attributes"] = attrVal
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultTargetAliasAuthorizeSessionArgumentsHostId() Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
attrVal := raw.(map[string]interface{})
|
||||
argRaw, ok := attrVal["authorize_session_arguments"]
|
||||
if !ok {
|
||||
argRaw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
argVal := argRaw.(map[string]interface{})
|
||||
argVal["host_id"] = nil
|
||||
attrVal["authorize_session_arguments"] = argVal
|
||||
|
||||
o.postMap["attributes"] = attrVal
|
||||
}
|
||||
}
|
||||
@@ -100,14 +100,6 @@ func extraTargetFlagsFuncImpl(c *TargetCommand, set *base.FlagSets, f *base.Flag
|
||||
}
|
||||
|
||||
func extraTargetFlagHandlingFuncImpl(c *TargetCommand, _ *base.FlagSets, opts *[]aliases.Option) bool {
|
||||
var attributes map[string]any
|
||||
addAttribute := func(name string, value any) {
|
||||
if attributes == nil {
|
||||
attributes = make(map[string]any)
|
||||
}
|
||||
attributes[name] = value
|
||||
}
|
||||
|
||||
switch c.flagValue {
|
||||
case "":
|
||||
case "null":
|
||||
@@ -126,14 +118,9 @@ func extraTargetFlagHandlingFuncImpl(c *TargetCommand, _ *base.FlagSets, opts *[
|
||||
switch c.flagAuthorizeSessionHostId {
|
||||
case "":
|
||||
case "null":
|
||||
addAttribute("authorize_session_arguments", nil)
|
||||
*opts = append(*opts, aliases.DefaultTargetAliasAuthorizeSessionArgumentsHostId())
|
||||
default:
|
||||
asa := aliases.AuthorizeSessionArguments{HostId: c.flagAuthorizeSessionHostId}
|
||||
addAttribute("authorize_session_arguments", asa)
|
||||
}
|
||||
|
||||
if attributes != nil {
|
||||
*opts = append(*opts, aliases.WithAttributes(attributes))
|
||||
*opts = append(*opts, aliases.WithTargetAliasAuthorizeSessionArgumentsHostId(c.flagAuthorizeSessionHostId))
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -10,10 +10,13 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/aliases"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
_ "github.com/hashicorp/boundary/internal/daemon/controller/handlers/targets/tcp"
|
||||
)
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
@@ -88,6 +91,12 @@ func TestCrud(t *testing.T) {
|
||||
client := tc.Client()
|
||||
token := tc.Token()
|
||||
client.SetToken(token.Token)
|
||||
|
||||
tarResp, err := targets.NewClient(client).Create(tc.Context(), "tcp", "p_1234567890", targets.WithName("target"), targets.WithTcpTargetDefaultPort(22))
|
||||
require.NoError(err)
|
||||
require.NotNil(tarResp)
|
||||
tar := tarResp.Item
|
||||
|
||||
aliasClient := aliases.NewClient(client)
|
||||
|
||||
checkAlias := func(step string, u *aliases.Alias, err error, wantedName string, wantedVersion uint32) {
|
||||
@@ -101,14 +110,37 @@ func TestCrud(t *testing.T) {
|
||||
assert.EqualValues(wantedVersion, u.Version)
|
||||
}
|
||||
|
||||
u, err := aliasClient.Create(tc.Context(), "target", "alias.value", scopeId)
|
||||
u, err := aliasClient.Create(tc.Context(), "target", "alias.value", scopeId,
|
||||
aliases.WithDestinationId(tar.Id),
|
||||
aliases.WithTargetAliasAuthorizeSessionArgumentsHostId("hst_1234567890"))
|
||||
assert.NoError(err)
|
||||
require.NotNil(u)
|
||||
checkAlias("create", u.Item, err, "alias.value", 1)
|
||||
|
||||
attrs, err := aliases.AttributesMapToTargetAliasAttributes(u.Item.Attributes)
|
||||
assert.NoError(err)
|
||||
require.NotNil(attrs)
|
||||
require.NotNil(attrs.AuthorizeSessionArguments)
|
||||
assert.Equal("hst_1234567890", attrs.AuthorizeSessionArguments.HostId)
|
||||
|
||||
u, err = aliasClient.Read(tc.Context(), u.Item.Id)
|
||||
checkAlias("read", u.Item, err, "alias.value", 1)
|
||||
|
||||
u, err = aliasClient.Update(tc.Context(), u.Item.Id, u.Item.Version, aliases.WithValue("bar"))
|
||||
u, err = aliasClient.Update(tc.Context(), u.Item.Id, u.Item.Version, aliases.WithValue("bar"), aliases.WithTargetAliasAuthorizeSessionArgumentsHostId("hst_0987654321"))
|
||||
assert.NoError(err)
|
||||
require.NotNil(u)
|
||||
checkAlias("update", u.Item, err, "bar", 2)
|
||||
attrs, err = aliases.AttributesMapToTargetAliasAttributes(u.Item.Attributes)
|
||||
assert.NoError(err)
|
||||
require.NotNil(attrs)
|
||||
require.NotNil(attrs.AuthorizeSessionArguments)
|
||||
assert.Equal("hst_0987654321", attrs.AuthorizeSessionArguments.HostId)
|
||||
|
||||
u, err = aliasClient.Update(tc.Context(), u.Item.Id, u.Item.Version, aliases.WithValue("bar"), aliases.DefaultTargetAliasAuthorizeSessionArgumentsHostId())
|
||||
assert.NoError(err)
|
||||
require.NotNil(u)
|
||||
checkAlias("update", u.Item, err, "bar", 3)
|
||||
assert.Nil(u.Item.Attributes)
|
||||
|
||||
_, err = aliasClient.Delete(tc.Context(), u.Item.Id)
|
||||
require.NoError(err)
|
||||
|
||||
Reference in new issue
Block a user