chore(API): add set/remove alias suffix API definitions (#6757)
* chore: add set/remove alias suffix API definitions * fix(test): revert alias_test changes * revert alias_test.go changes
This commit is contained in:
1 parent
6f03523372
commit
969bd5f66d
8 files changed
+891
-46
No files matched your search
@@ -353,3 +353,140 @@ func (c *Client) DetachStoragePolicy(ctx context.Context, scopeId string, versio
|
||||
s.Response = resp
|
||||
return s, nil
|
||||
}
|
||||
|
||||
type (
|
||||
SetAliasSuffixResult = ScopeReadResult
|
||||
RemoveAliasSuffixResult = ScopeReadResult
|
||||
)
|
||||
|
||||
// SetAliasSuffix sets the alias suffix on the provided scopeId.
|
||||
func (c *Client) SetAliasSuffix(ctx context.Context, scopeId string, version uint32, aliasSuffix string, opt ...Option) (*SetAliasSuffixResult, error) {
|
||||
if scopeId == "" {
|
||||
return nil, errors.New("empty scopeId value passed into SetAliasSuffix request")
|
||||
}
|
||||
if aliasSuffix == "" {
|
||||
return nil, errors.New("empty aliasSuffix value passed into SetAliasSuffix 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 SetAliasSuffix request")
|
||||
}
|
||||
existingScope, existingErr := c.Read(ctx, scopeId, 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 existingScope == nil {
|
||||
return nil, errors.New("nil resource response found when performing initial check-and-set read")
|
||||
}
|
||||
if existingScope.Item == nil {
|
||||
return nil, errors.New("nil resource found when performing initial check-and-set read")
|
||||
}
|
||||
version = existingScope.Item.Version
|
||||
}
|
||||
|
||||
opts.postMap["version"] = version
|
||||
opts.postMap["alias_suffix"] = aliasSuffix
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("scopes/%s:set-alias-suffix", url.PathEscape(scopeId)), opts.postMap, apiOpts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating SetAliasSuffix 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 SetAliasSuffix call: %w", err)
|
||||
}
|
||||
|
||||
s := new(SetAliasSuffixResult)
|
||||
s.Item = new(Scope)
|
||||
apiErr, err := resp.Decode(s.Item)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding SetAliasSuffixResult response: %w", err)
|
||||
}
|
||||
if apiErr != nil {
|
||||
return nil, apiErr
|
||||
}
|
||||
s.Response = resp
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// RemoveAliasSuffix removes the alias suffix from the provided scopeId if one is set.
|
||||
func (c *Client) RemoveAliasSuffix(ctx context.Context, scopeId string, version uint32, opt ...Option) (*RemoveAliasSuffixResult, error) {
|
||||
if scopeId == "" {
|
||||
return nil, errors.New("empty scopeId value passed into RemoveAliasSuffix 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 RemoveAliasSuffix request")
|
||||
}
|
||||
existingScope, existingErr := c.Read(ctx, scopeId, 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 existingScope == nil {
|
||||
return nil, errors.New("nil resource response found when performing initial check-and-set read")
|
||||
}
|
||||
if existingScope.Item == nil {
|
||||
return nil, errors.New("nil resource found when performing initial check-and-set read")
|
||||
}
|
||||
version = existingScope.Item.Version
|
||||
}
|
||||
|
||||
opts.postMap["version"] = version
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("scopes/%s:remove-alias-suffix", url.PathEscape(scopeId)), opts.postMap, apiOpts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating RemoveAliasSuffix 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 RemoveAliasSuffix call: %w", err)
|
||||
}
|
||||
|
||||
s := new(RemoveAliasSuffixResult)
|
||||
s.Item = new(Scope)
|
||||
apiErr, err := resp.Decode(s.Item)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding RemoveAliasSuffixResult response: %w", err)
|
||||
}
|
||||
if apiErr != nil {
|
||||
return nil, apiErr
|
||||
}
|
||||
s.Response = resp
|
||||
return s, nil
|
||||
}
|
||||
Reference in new issue
Block a user