2022-04-20 09:17:20 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 14:08:53 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/resolver"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2022-04-20 09:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetContainerID decode container id, if it's not a valid container id
|
|
|
|
// then trey to resolve name using provided resolver.
|
|
|
|
func GetContainerID(ctx context.Context, containerID string, resolver *resolver.ContainerResolver) (*cid.ID, error) {
|
|
|
|
cnrID := new(cid.ID)
|
|
|
|
err := cnrID.DecodeString(containerID)
|
|
|
|
if err != nil {
|
2022-09-08 16:00:22 +00:00
|
|
|
cnrID, err = resolver.Resolve(ctx, containerID)
|
2022-04-20 09:17:20 +00:00
|
|
|
}
|
|
|
|
return cnrID, err
|
|
|
|
}
|