Tie together the database-driven session handling with the worker and add relevant CLI comands (#370)
This commit is contained in:
1 parent
fd8ceb6cc4
commit
07a7e9750a
57 files changed
+2548
-826
No files matched your search
+12
-13
@@ -58,11 +58,12 @@ type Config struct {
|
||||
// per-call, regardless of any value set in Token.
|
||||
RecoveryKmsWrapper wrapping.Wrapper
|
||||
|
||||
// HttpClient is the HTTP client to use. Boundary sets sane defaults for
|
||||
// the http.Client and its associated http.Transport created in
|
||||
// DefaultConfig. If you must modify Boundary's defaults, it is
|
||||
// suggested that you start with that client and modify as needed rather
|
||||
// than start with an empty client (or http.DefaultClient).
|
||||
// HttpClient is the HTTP client to use. Boundary sets sane defaults for the
|
||||
// http.Client and its associated http.Transport created in DefaultConfig.
|
||||
// If you must modify Boundary's defaults, it is suggested that you start
|
||||
// with that client and modify as needed rather than start with an empty
|
||||
// client (or http.DefaultClient). Currently if the client is cloned the
|
||||
// same HttpClient is used.
|
||||
HttpClient *http.Client
|
||||
|
||||
// TLSConfig contains TLS configuration information. After modifying these
|
||||
@@ -86,19 +87,16 @@ type Config struct {
|
||||
// The CheckRetry function to use; a default is used if not provided
|
||||
CheckRetry retryablehttp.CheckRetry
|
||||
|
||||
// Limiter is the rate limiter used by the client.
|
||||
// If this pointer is nil, then there will be no limit set.
|
||||
// In contrast, if this pointer is set, even to an empty struct,
|
||||
// then that limiter will be used. Note that an empty Limiter
|
||||
// is equivalent blocking all events.
|
||||
// Limiter is the rate limiter used by the client. If this pointer is nil,
|
||||
// then there will be no limit set. In contrast, if this pointer is set,
|
||||
// even to an empty struct, then that limiter will be used. Note that an
|
||||
// empty Limiter is equivalent blocking all events. Currently if the client
|
||||
// is cloned the same limiter is used.
|
||||
Limiter *rate.Limiter
|
||||
|
||||
// OutputCurlString causes the actual request to return an error of type
|
||||
// *OutputStringError. Type asserting the error message will allow
|
||||
// fetching a cURL-compatible string for the operation.
|
||||
//
|
||||
// Note: It is not thread-safe to set this and make concurrent requests
|
||||
// with the same client. Cloning a client will not clone this value.
|
||||
OutputCurlString bool
|
||||
|
||||
// SRVLookup enables the client to lookup the host through DNS SRV lookup
|
||||
@@ -561,6 +559,7 @@ func (c *Client) Clone() *Client {
|
||||
Backoff: config.Backoff,
|
||||
CheckRetry: config.CheckRetry,
|
||||
Limiter: config.Limiter,
|
||||
OutputCurlString: config.OutputCurlString,
|
||||
SRVLookup: config.SRVLookup,
|
||||
}
|
||||
if config.TLSConfig != nil {
|
||||
|
||||
@@ -31,6 +31,7 @@ type fieldInfo struct {
|
||||
GenerateSdkOption bool
|
||||
SubtypeName string
|
||||
Query bool
|
||||
SkipDefault bool
|
||||
}
|
||||
|
||||
type structInfo struct {
|
||||
@@ -338,6 +339,14 @@ var inputStructs = []*structInfo{
|
||||
sliceSubTypes: map[string]string{
|
||||
"HostSets": "hostSetIds",
|
||||
},
|
||||
extraOptions: []fieldInfo{
|
||||
{
|
||||
Name: "HostId",
|
||||
ProtoName: "host_id",
|
||||
FieldType: "string",
|
||||
SkipDefault: true,
|
||||
},
|
||||
},
|
||||
versionEnabled: true,
|
||||
typeOnCreate: true,
|
||||
createResponseTypes: true,
|
||||
@@ -347,4 +356,14 @@ var inputStructs = []*structInfo{
|
||||
outFile: "targets/tcp_target_attributes.gen.go",
|
||||
subtypeName: "TcpTarget",
|
||||
},
|
||||
{
|
||||
inProto: &targets.SessionAuthorization{},
|
||||
outFile: "targets/session_authorization.gen.go",
|
||||
subtypeName: "SessionAuthorization",
|
||||
},
|
||||
{
|
||||
inProto: &targets.WorkerInfo{},
|
||||
outFile: "targets/worker_info.gen.go",
|
||||
subtypeName: "WorkerInfo",
|
||||
},
|
||||
}
|
||||
@@ -62,6 +62,8 @@ func parsePBs() {
|
||||
name = fmt.Sprintf("%s.%s", pkg, name)
|
||||
}
|
||||
fi.FieldType = sliceText + ptr + name
|
||||
case protoreflect.BytesKind:
|
||||
fi.FieldType = "[]byte"
|
||||
default:
|
||||
fi.FieldType = sliceText + k.String()
|
||||
}
|
||||
|
||||
@@ -728,7 +728,7 @@ func With{{ .SubtypeName }}{{ .Name }}(in{{ .Name }} {{ .FieldType }}) Option {
|
||||
o.postMap["{{ .ProtoName }}"] = in{{ .Name }}
|
||||
{{ end }} }
|
||||
}
|
||||
|
||||
{{ if ( not .SkipDefault ) }}
|
||||
func Default{{ .SubtypeName }}{{ .Name }}() Option {
|
||||
return func(o *options) { {{ if ( not ( eq .SubtypeName "" ) ) }}
|
||||
raw, ok := o.postMap["attributes"]
|
||||
@@ -743,6 +743,7 @@ func Default{{ .SubtypeName }}{{ .Name }}() Option {
|
||||
{{ end }} }
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
`))
|
||||
|
||||
func makeSlice(strs ...string) []string {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package targets
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
)
|
||||
|
||||
type SessionAuthorizationResult struct {
|
||||
Item *SessionAuthorization
|
||||
responseBody *bytes.Buffer
|
||||
responseMap map[string]interface{}
|
||||
}
|
||||
|
||||
func (n SessionAuthorizationResult) GetItem() interface{} {
|
||||
return n.Item
|
||||
}
|
||||
|
||||
func (n SessionAuthorizationResult) GetResponseBody() *bytes.Buffer {
|
||||
return n.responseBody
|
||||
}
|
||||
|
||||
func (n SessionAuthorizationResult) GetResponseMap() map[string]interface{} {
|
||||
return n.responseMap
|
||||
}
|
||||
|
||||
func (c *Client) Authorize(ctx context.Context, targetId string, opt ...Option) (*SessionAuthorizationResult, *api.Error, error) {
|
||||
if targetId == "" {
|
||||
return nil, nil, fmt.Errorf("empty targetId value passed into Authorize request")
|
||||
}
|
||||
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:authorize", targetId), opts.postMap, apiOpts...)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating Authorize request: %w", err)
|
||||
}
|
||||
|
||||
if len(opts.queryMap) > 0 {
|
||||
q := url.Values{}
|
||||
for k, v := range opts.queryMap {
|
||||
q.Add(k, v)
|
||||
}
|
||||
req.URL.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during Authorize call: %w", err)
|
||||
}
|
||||
|
||||
sar := new(SessionAuthorizationResult)
|
||||
sar.Item = new(SessionAuthorization)
|
||||
apiErr, err := resp.Decode(sar.Item)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Authorize response: %w", err)
|
||||
}
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
sar.responseBody = resp.Body
|
||||
sar.responseMap = resp.Map
|
||||
return sar, apiErr, nil
|
||||
}
|
||||
@@ -93,6 +93,12 @@ func DefaultDescription() Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithHostId(inHostId string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["host_id"] = inHostId
|
||||
}
|
||||
}
|
||||
|
||||
func WithName(inName string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = inName
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package targets
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/api/scopes"
|
||||
)
|
||||
|
||||
type SessionAuthorization struct {
|
||||
SessionId string `json:"session_id,omitempty"`
|
||||
TargetId string `json:"target_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
CreatedTime time.Time `json:"created_time,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
AuthorizationToken string `json:"authorization_token,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package targets
|
||||
|
||||
type WorkerInfo struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
}
|
||||
Reference in new issue
Block a user