[#47] authmate, layer: use sdk-go Container impl

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2021-06-23 23:26:48 +03:00
parent 3aa9aceda5
commit 26d6fd95c7
2 changed files with 7 additions and 46 deletions

View file

@ -46,15 +46,7 @@ func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*BucketInfo, er
Name: cid.String(), Name: cid.String(),
} }
) )
res, err = n.pool.GetContainer(ctx, cid, bearerOpt)
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)
if err != nil { if err != nil {
n.log.Error("could not fetch container", n.log.Error("could not fetch container",
zap.Stringer("cid", cid), zap.Stringer("cid", cid),
@ -97,15 +89,7 @@ func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) {
res []*cid.ID res []*cid.ID
rid = api.GetRequestID(ctx) rid = api.GetRequestID(ctx)
) )
res, err = n.pool.ListContainers(ctx, own, bearerOpt)
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)
if err != nil { if err != nil {
n.log.Error("could not fetch container", n.log.Error("could not fetch container",
zap.String("request_id", rid), zap.String("request_id", rid),

View file

@ -30,8 +30,6 @@ import (
const ( const (
defaultAuthContainerBasicACL uint32 = 0b00111100100011001000110011001110 defaultAuthContainerBasicACL uint32 = 0b00111100100011001000110011001110
containerCreationTimeout = 120 * time.Second
containerPollInterval = 5 * time.Second
) )
// Agent contains client communicating with NeoFS and logger. // 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) { 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 { if cid != nil {
// check that container exists // check that container exists
_, err = conn.GetContainer(ctx, cid) _, err := a.pool.GetContainer(ctx, cid)
return cid, err 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.AttributeName, friendlyName),
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10))) 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 { if err != nil {
return nil, err return nil, err
} }
wctx, cancel := context.WithTimeout(ctx, containerCreationTimeout) if err := a.pool.WaitForContainerPresence(ctx, cid, pool.DefaultPollingParams()); err != nil {
defer cancel() return nil, err
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)
}
} }
return cid, nil
} }
// IssueSecret creates an auth token, puts it in the NeoFS network and writes to io.Writer a new secret access key. // IssueSecret creates an auth token, puts it in the NeoFS network and writes to io.Writer a new secret access key.