Containers manage the permissions/access of a group of objects that are being stored. Before being able to store an object, you need to create a container.
Before being able to create a container, you will need to
placementPolicy
)helper.GetCredentialsFromPath
(key
)permissions
)cli
)Before continuing, you will need to get the owner ID from the wallet private key. The owner ID is not the same as the wallet ID or public key. A straight forward way to do this is
//see key retrieval generation for how to get a key
w, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
if err != nil {
return fmt.Errorf("invalid private key")
}
ownerID := owner.NewIDFromNeo3Wallet(w)
print("please help by opening a Pull Request and filling in these code snippets!")
Console.WriteLine("please help by opening a Pull Request and filling in these code snippets!");
Now we can get on with creating a container.
You will need
placementPolicy
)permissions
)containerPolicy, err := policy.Parse(placementPolicy)
if err != nil {
return fmt.Errorf("can't parse placement policy: %w", err)
}
cnr := container.New(
// container policy defines the way objects will be
// placed among storage nodes from the network map
container.WithPolicy(containerPolicy),
// container owner can set BasicACL and remove container
container.WithOwnerID(ownerID),
// read more about basic ACL in specification:
// https://github.com/nspcc-dev/neofs-spec/blob/master/01-arch/07-acl.md
container.WithCustomBasicACL(permissions),
// Attributes are key:value string pairs they are always optional
container.WithAttribute(
container.AttributeTimestamp,
strconv.FormatInt(time.Now().Unix(), 10),
),
print("please help by opening a Pull Request and filling in these code snippets!")
Console.WriteLine("please help by opening a Pull Request and filling in these code snippets!");
Finally we can put
the container on NeoFS. We will receive a response that contains the container’s ID.
response, err := cli.PutContainer(ctx, cnr)
if err != nil {
return fmt.Errorf("can't put container: %w", err)
}
fmt.Println(response.ID())
print("please help by opening a Pull Request and filling in these code snippets!")
Console.WriteLine("please help by opening a Pull Request and filling in these code snippets!");
You can list all the containers owned by a wallet. This will return an array of container IDs
response, err := cli.ListContainers(ctx, wallet.OwnerIDFromPrivateKey(key))
if err != nil {
return fmt.Errorf("can't list container: %w", err)
}
walletList := response.IDList()
print("please help by opening a Pull Request and filling in these code snippets!")
Console.WriteLine("please help by opening a Pull Request and filling in these code snippets!");
You can retrieve a container once you have the ID
response, err := cli.GetContainer(ctx, containerID)
if err != nil {
return fmt.Errorf("can't get container %s: %w", containerID, err)
}
contianeer := response.Container()
print("please help by opening a Pull Request and filling in these code snippets!")
Console.WriteLine("please help by opening a Pull Request and filling in these code snippets!");
From a container, you can find out storage policies, owners and any other meta information about the container itself
Once you have created a container, you will receive the ID of the container as part of the response (see above). Using this ID you can now delete the container with ease
response, err := cli.DeleteContainer(ctx, containerID)
if err != nil {
return nil, fmt.Errorf("can't get container %s: %w", containerID, err)
}
fmt.Printf("deletion response %+v\r\n", response)
print("please help by opening a Pull Request and filling in these code snippets!")
Console.WriteLine("please help by opening a Pull Request and filling in these code snippets!");