Migrate credential-library nomenclature around targets to credential-source (#1413)

See the CHANGELOG entry for more information.

Co-authored-by: Jim <jlambert@hashicorp.com>

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2021-07-27 12:48:36 -04:00
1 parent 528d54b4ad
commit ab6f3eaeb4
36 files changed
+3284 -673

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
// Code generated by "make api"; DO NOT EDIT.
package targets
type CredentialSource struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
CredentialStoreId string `json:"credential_store_id,omitempty"`
Type string `json:"type,omitempty"`
}
+12
View File
@@ -99,6 +99,18 @@ func DefaultApplicationCredentialLibraryIds() Option {
}
}
func WithApplicationCredentialSourceIds(inApplicationCredentialSourceIds []string) Option {
return func(o *options) {
o.postMap["application_credential_source_ids"] = inApplicationCredentialSourceIds
}
}
func DefaultApplicationCredentialSourceIds() Option {
return func(o *options) {
o.postMap["application_credential_source_ids"] = nil
}
}
func WithAttributes(inAttributes map[string]interface{}) Option {
return func(o *options) {
o.postMap["attributes"] = inAttributes
+1
View File
@@ -2,6 +2,7 @@
package targets
type SessionCredential struct {
CredentialSource *CredentialSource `json:"credential_source,omitempty"`
CredentialLibrary *CredentialLibrary `json:"credential_library,omitempty"`
Secret *SessionSecret `json:"secret,omitempty"`
}
+194
View File
@@ -29,6 +29,8 @@ type Target struct {
WorkerFilter string `json:"worker_filter,omitempty"`
ApplicationCredentialLibraryIds []string `json:"application_credential_library_ids,omitempty"`
ApplicationCredentialLibraries []*CredentialLibrary `json:"application_credential_libraries,omitempty"`
ApplicationCredentialSourceIds []string `json:"application_credential_source_ids,omitempty"`
ApplicationCredentialSources []*CredentialSource `json:"application_credential_sources,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
AuthorizedActions []string `json:"authorized_actions,omitempty"`
@@ -397,6 +399,70 @@ func (c *Client) AddCredentialLibraries(ctx context.Context, id string, version
return target, nil
}
func (c *Client) AddCredentialSources(ctx context.Context, id string, version uint32, opt ...Option) (*TargetUpdateResult, error) {
if id == "" {
return nil, fmt.Errorf("empty id value passed into AddCredentialSources request")
}
if c.client == nil {
return nil, errors.New("nil client")
}
opts, apiOpts := getOpts(opt...)
if version == 0 {
if !opts.withAutomaticVersioning {
return nil, errors.New("zero version number passed into AddCredentialSources request")
}
existingTarget, existingErr := c.Read(ctx, id, append([]Option{WithSkipCurlOutput(true)}, opt...)...)
if existingErr != nil {
if api.AsServerError(existingErr) != nil {
return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr)
}
return nil, fmt.Errorf("error performing initial check-and-set read: %w", existingErr)
}
if existingTarget == nil {
return nil, errors.New("nil resource response found when performing initial check-and-set read")
}
if existingTarget.Item == nil {
return nil, errors.New("nil resource found when performing initial check-and-set read")
}
version = existingTarget.Item.Version
}
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:add-credential-sources", id), opts.postMap, apiOpts...)
if err != nil {
return nil, fmt.Errorf("error creating AddCredentialSources 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, fmt.Errorf("error performing client request during AddCredentialSources call: %w", err)
}
target := new(TargetUpdateResult)
target.Item = new(Target)
apiErr, err := resp.Decode(target.Item)
if err != nil {
return nil, fmt.Errorf("error decoding AddCredentialSources response: %w", err)
}
if apiErr != nil {
return nil, apiErr
}
target.response = resp
return target, nil
}
func (c *Client) AddHostSets(ctx context.Context, id string, version uint32, hostSetIds []string, opt ...Option) (*TargetUpdateResult, error) {
if id == "" {
return nil, fmt.Errorf("empty id value passed into AddHostSets request")
@@ -531,6 +597,70 @@ func (c *Client) SetCredentialLibraries(ctx context.Context, id string, version
return target, nil
}
func (c *Client) SetCredentialSources(ctx context.Context, id string, version uint32, opt ...Option) (*TargetUpdateResult, error) {
if id == "" {
return nil, fmt.Errorf("empty id value passed into SetCredentialSources request")
}
if c.client == nil {
return nil, errors.New("nil client")
}
opts, apiOpts := getOpts(opt...)
if version == 0 {
if !opts.withAutomaticVersioning {
return nil, errors.New("zero version number passed into SetCredentialSources request")
}
existingTarget, existingErr := c.Read(ctx, id, append([]Option{WithSkipCurlOutput(true)}, opt...)...)
if existingErr != nil {
if api.AsServerError(existingErr) != nil {
return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr)
}
return nil, fmt.Errorf("error performing initial check-and-set read: %w", existingErr)
}
if existingTarget == nil {
return nil, errors.New("nil resource response found when performing initial check-and-set read")
}
if existingTarget.Item == nil {
return nil, errors.New("nil resource found when performing initial check-and-set read")
}
version = existingTarget.Item.Version
}
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:set-credential-sources", id), opts.postMap, apiOpts...)
if err != nil {
return nil, fmt.Errorf("error creating SetCredentialSources 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, fmt.Errorf("error performing client request during SetCredentialSources call: %w", err)
}
target := new(TargetUpdateResult)
target.Item = new(Target)
apiErr, err := resp.Decode(target.Item)
if err != nil {
return nil, fmt.Errorf("error decoding SetCredentialSources response: %w", err)
}
if apiErr != nil {
return nil, apiErr
}
target.response = resp
return target, nil
}
func (c *Client) SetHostSets(ctx context.Context, id string, version uint32, hostSetIds []string, opt ...Option) (*TargetUpdateResult, error) {
if id == "" {
return nil, fmt.Errorf("empty id value passed into SetHostSets request")
@@ -661,6 +791,70 @@ func (c *Client) RemoveCredentialLibraries(ctx context.Context, id string, versi
return target, nil
}
func (c *Client) RemoveCredentialSources(ctx context.Context, id string, version uint32, opt ...Option) (*TargetUpdateResult, error) {
if id == "" {
return nil, fmt.Errorf("empty id value passed into RemoveCredentialSources request")
}
if c.client == nil {
return nil, errors.New("nil client")
}
opts, apiOpts := getOpts(opt...)
if version == 0 {
if !opts.withAutomaticVersioning {
return nil, errors.New("zero version number passed into RemoveCredentialSources request")
}
existingTarget, existingErr := c.Read(ctx, id, append([]Option{WithSkipCurlOutput(true)}, opt...)...)
if existingErr != nil {
if api.AsServerError(existingErr) != nil {
return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr)
}
return nil, fmt.Errorf("error performing initial check-and-set read: %w", existingErr)
}
if existingTarget == nil {
return nil, errors.New("nil resource response found when performing initial check-and-set read")
}
if existingTarget.Item == nil {
return nil, errors.New("nil resource found when performing initial check-and-set read")
}
version = existingTarget.Item.Version
}
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:remove-credential-sources", id), opts.postMap, apiOpts...)
if err != nil {
return nil, fmt.Errorf("error creating RemoveCredentialSources 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, fmt.Errorf("error performing client request during RemoveCredentialSources call: %w", err)
}
target := new(TargetUpdateResult)
target.Item = new(Target)
apiErr, err := resp.Decode(target.Item)
if err != nil {
return nil, fmt.Errorf("error decoding RemoveCredentialSources response: %w", err)
}
if apiErr != nil {
return nil, apiErr
}
target.response = resp
return target, nil
}
func (c *Client) RemoveHostSets(ctx context.Context, id string, version uint32, hostSetIds []string, opt ...Option) (*TargetUpdateResult, error) {
if id == "" {
return nil, fmt.Errorf("empty id value passed into RemoveHostSets request")