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
@@ -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