forked from TrueCloudLab/frostfs-s3-gw
[#47] authmate, layer: use sdk-go Container impl
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
3aa9aceda5
commit
26d6fd95c7
2 changed files with 7 additions and 46 deletions
|
@ -46,15 +46,7 @@ func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*BucketInfo, er
|
|||
Name: cid.String(),
|
||||
}
|
||||
)
|
||||
|
||||
conn, _, err := n.pool.Connection()
|
||||
if err != nil {
|
||||
n.log.Error("failed to get connection from the pool",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
res, err = conn.GetContainer(ctx, cid, bearerOpt)
|
||||
res, err = n.pool.GetContainer(ctx, cid, bearerOpt)
|
||||
if err != nil {
|
||||
n.log.Error("could not fetch container",
|
||||
zap.Stringer("cid", cid),
|
||||
|
@ -97,15 +89,7 @@ func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) {
|
|||
res []*cid.ID
|
||||
rid = api.GetRequestID(ctx)
|
||||
)
|
||||
|
||||
conn, _, err := n.pool.Connection()
|
||||
if err != nil {
|
||||
n.log.Error("failed to get connection from the pool",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
res, err = conn.ListContainers(ctx, own, bearerOpt)
|
||||
res, err = n.pool.ListContainers(ctx, own, bearerOpt)
|
||||
if err != nil {
|
||||
n.log.Error("could not fetch container",
|
||||
zap.String("request_id", rid),
|
||||
|
|
|
@ -30,8 +30,6 @@ import (
|
|||
|
||||
const (
|
||||
defaultAuthContainerBasicACL uint32 = 0b00111100100011001000110011001110
|
||||
containerCreationTimeout = 120 * time.Second
|
||||
containerPollInterval = 5 * time.Second
|
||||
)
|
||||
|
||||
// Agent contains client communicating with NeoFS and logger.
|
||||
|
@ -78,14 +76,9 @@ type (
|
|||
)
|
||||
|
||||
func (a *Agent) checkContainer(ctx context.Context, cid *cid.ID, friendlyName string) (*cid.ID, error) {
|
||||
conn, _, err := a.pool.Connection()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cid != nil {
|
||||
// check that container exists
|
||||
_, err = conn.GetContainer(ctx, cid)
|
||||
_, err := a.pool.GetContainer(ctx, cid)
|
||||
return cid, err
|
||||
}
|
||||
|
||||
|
@ -100,31 +93,15 @@ func (a *Agent) checkContainer(ctx context.Context, cid *cid.ID, friendlyName st
|
|||
container.WithAttribute(container.AttributeName, friendlyName),
|
||||
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10)))
|
||||
|
||||
cid, err = conn.PutContainer(ctx, cnr)
|
||||
cid, err = a.pool.PutContainer(ctx, cnr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wctx, cancel := context.WithTimeout(ctx, containerCreationTimeout)
|
||||
defer cancel()
|
||||
ticker := time.NewTimer(containerPollInterval)
|
||||
defer ticker.Stop()
|
||||
wdone := wctx.Done()
|
||||
done := ctx.Done()
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return nil, ctx.Err()
|
||||
case <-wdone:
|
||||
return nil, wctx.Err()
|
||||
case <-ticker.C:
|
||||
_, err = conn.GetContainer(ctx, cid)
|
||||
if err == nil {
|
||||
return cid, nil
|
||||
}
|
||||
ticker.Reset(containerPollInterval)
|
||||
}
|
||||
if err := a.pool.WaitForContainerPresence(ctx, cid, pool.DefaultPollingParams()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cid, nil
|
||||
}
|
||||
|
||||
// IssueSecret creates an auth token, puts it in the NeoFS network and writes to io.Writer a new secret access key.
|
||||
|
|
Loading…
Reference in a new issue