[#121] client: Make PrmContainerDelete fields public #141

Merged
fyrchik merged 3 commits from aarifullin/frostfs-sdk-go:master into master 2023-08-05 15:58:16 +00:00
Showing only changes of commit 4996ff619e - Show all commits

View file

@ -486,10 +486,9 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel
return err return err
} }
var cliPrm sdkClient.PrmContainerDelete cliPrm := sdkClient.PrmContainerDelete{
cliPrm.SetContainer(prm.cnrID) ContainerID: &prm.ContainerID,
if prm.stokenSet { Session: prm.Session,
cliPrm.WithinSession(prm.stoken)
} }
start := time.Now() start := time.Now()
@ -503,11 +502,14 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel
return fmt.Errorf("container delete on client: %w", err) return fmt.Errorf("container delete on client: %w", err)
} }
if !prm.waitParamsSet { if prm.WaitParams == nil {
prm.waitParams.setDefaults() prm.WaitParams = defaultWaitParams()
}
if err := prm.WaitParams.CheckValidity(); err != nil {
fyrchik marked this conversation as resolved
Review

Won't private fields be a problem here too?

Won't private fields be a problem here too?
Review

Sorry, I didn't get the point. prm.WaitParams is no longer private

Sorry, I didn't get the point. `prm.WaitParams` is no longer private
Review

Yes, but the WaitParams itself has private fields. I think making them public aligns well with the overall goal.

Yes, but the `WaitParams` itself has private fields. I think making them public aligns well with the overall goal.
Review

Oh. You're right. I'll fix it

Oh. You're right. I'll fix it
return fmt.Errorf("invalid wait parameters: %w", err)
} }
return waitForContainerRemoved(ctx, c, &prm.cnrID, &prm.waitParams) return waitForContainerRemoved(ctx, c, &prm.ContainerID, prm.WaitParams)
} }
// containerEACL invokes sdkClient.ContainerEACL parse response status to error and return result as is. // containerEACL invokes sdkClient.ContainerEACL parse response status to error and return result as is.
@ -1235,6 +1237,17 @@ func (x *WaitParams) checkForPositive() {
} }
} }
// CheckForValid checks if all wait params are non-negative.
func (waitPrm *WaitParams) CheckValidity() error {
if waitPrm.timeout <= 0 {
return errors.New("timeout cannot be negative")
}
if waitPrm.pollInterval <= 0 {
return errors.New("poll interval cannot be negative")
}
return nil
}
type prmContext struct { type prmContext struct {
defaultSession bool defaultSession bool
verb session.ObjectVerb verb session.ObjectVerb
@ -1464,33 +1477,35 @@ func (x *PrmContainerList) SetOwnerID(ownerID user.ID) {
// PrmContainerDelete groups parameters of DeleteContainer operation. // PrmContainerDelete groups parameters of DeleteContainer operation.
type PrmContainerDelete struct { type PrmContainerDelete struct {
cnrID cid.ID ContainerID cid.ID
stoken session.Container Session *session.Container
stokenSet bool
waitParams WaitParams WaitParams *WaitParams
waitParamsSet bool
} }
// SetContainerID specifies identifier of the FrostFS container to be removed. // SetContainerID specifies identifier of the FrostFS container to be removed.
//
// Deprecated: Use PrmContainerDelete.ContainerID instead.
func (x *PrmContainerDelete) SetContainerID(cnrID cid.ID) { func (x *PrmContainerDelete) SetContainerID(cnrID cid.ID) {
x.cnrID = cnrID x.ContainerID = cnrID
} }
// SetSessionToken specifies session within which operation should be performed. // SetSessionToken specifies session within which operation should be performed.
//
// Deprecated: Use PrmContainerDelete.Session instead.
func (x *PrmContainerDelete) SetSessionToken(token session.Container) { func (x *PrmContainerDelete) SetSessionToken(token session.Container) {
x.stoken = token x.Session = &token
x.stokenSet = true
} }
// SetWaitParams specifies timeout params to complete operation. // SetWaitParams specifies timeout params to complete operation.
// If not provided the default one will be used. // If not provided the default one will be used.
// Panics if any of the wait params isn't positive. // Panics if any of the wait params isn't positive.
//
// Deprecated: Use PrmContainerDelete.WaitParams instead.
func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) { func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) {
waitParams.checkForPositive() waitParams.checkForPositive()
x.waitParams = waitParams x.WaitParams = &waitParams
x.waitParamsSet = true
} }
// PrmContainerEACL groups parameters of GetEACL operation. // PrmContainerEACL groups parameters of GetEACL operation.