Skip to content

Commit

Permalink
Feat/object locking (#1277)
Browse files Browse the repository at this point in the history
* feat: add data structures for object-locking

To be used in commands

Co-authored-by: Rafael Oliveira <ra.ph@live.com>

* feat: add object-locking commands to bucket level

sets default behavior of objects in bucket

Co-authored-by: Rafael Oliveira <ra.ph@live.com>

* feat: add object-locking command in object level

manipulate isolate objects to prevent deletion

Co-authored-by: Rafael Oliveira <ra.ph@live.com>

* feat: add object-locking command in object level

manipulate isolate objects to prevent deletion

Co-authored-by: Rafael Oliveira <ra.ph@live.com>

---------

Co-authored-by: Rafael Oliveira <ra.ph@live.com>
  • Loading branch information
GuiLorencato and Rafael Oliveira authored Dec 27, 2024
1 parent 54ed1ab commit 50c54d8
Show file tree
Hide file tree
Showing 17 changed files with 680 additions and 26 deletions.
1 change: 1 addition & 0 deletions mgc/cli/docs/object-storage/buckets/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Usage:
- delete Delete an existing Bucket
- label Label-related commands
- list List all existing Buckets
- object-lock Object locking commands
- policy Policy-related commands
- public-url Get bucket public url
- versioning Manage bucket versioning
Expand Down
35 changes: 35 additions & 0 deletions mgc/cli/docs/object-storage/buckets/object-lock/get/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Get object locking configuration for the specified bucket

## Usage:
```bash
Usage:
./mgc object-storage buckets object-lock get [dst] [flags]
```

## Product catalog:
- Flags:
- --dst string Specifies the bucket whose ACL is being requested (required)
- -h, --help help for get

## Other commands:
- Global Flags:
- --api-key string Use your API key to authenticate with the API
- --chunk-size integer Chunk size to consider when doing multipart requests. Specified in Mb (range: 8 - 5120) (default 8)
- -U, --cli.retry-until string Retry the action with the same parameters until the given condition is met. The flag parameters
- use the format: 'retries,interval,condition', where 'retries' is a positive integer, 'interval' is
- a duration (ex: 2s) and 'condition' is a 'engine=value' pair such as "jsonpath=expression"
- -t, --cli.timeout duration If > 0, it's the timeout for the action execution. It's specified as numbers and unit suffix.
- Valid unit suffixes: ns, us, ms, s, m and h. Examples: 300ms, 1m30s
- --debug Display detailed log information at the debug level
- --no-confirm Bypasses confirmation step for commands that ask a confirmation from the user
- -o, --output string Change the output format. Use '--output=help' to know more details.
- -r, --raw Output raw data, without any formatting or coloring
- --region enum Region to reach the service (one of "br-mgl1", "br-ne1" or "br-se1") (default "br-se1")
- --server-url uri Manually specify the server to use
- --workers integer Number of routines that spawn to do parallel operations within object_storage (min: 1) (default 5)

## Flags:
```bash

```

33 changes: 33 additions & 0 deletions mgc/cli/docs/object-storage/buckets/object-lock/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Object locking commands

## Usage:
```bash
Usage:
./mgc object-storage buckets object-lock [flags]
./mgc object-storage buckets object-lock [command]
```

## Product catalog:
- Commands:
- get Get object locking configuration for the specified bucket
- set set number of either days or years to lock new objects for

## Other commands:
- Flags:
- -h, --help help for object-lock

## Flags:
```bash
Global Flags:
--api-key string Use your API key to authenticate with the API
-U, --cli.retry-until string Retry the action with the same parameters until the given condition is met. The flag parameters
use the format: 'retries,interval,condition', where 'retries' is a positive integer, 'interval' is
a duration (ex: 2s) and 'condition' is a 'engine=value' pair such as "jsonpath=expression"
-t, --cli.timeout duration If > 0, it's the timeout for the action execution. It's specified as numbers and unit suffix.
Valid unit suffixes: ns, us, ms, s, m and h. Examples: 300ms, 1m30s
--debug Display detailed log information at the debug level
--no-confirm Bypasses confirmation step for commands that ask a confirmation from the user
-o, --output string Change the output format. Use '--output=help' to know more details.
-r, --raw Output raw data, without any formatting or coloring
```
38 changes: 38 additions & 0 deletions mgc/cli/docs/object-storage/buckets/object-lock/set/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# set number of either days or years to lock new objects for

## Usage:
```bash
Usage:
./mgc object-storage buckets object-lock set [dst] [flags]
```

## Product catalog:
- Examples:
- ./mgc object-storage buckets object-lock set --days=30 --dst="my-bucket" --years=5

## Other commands:
- Flags:
- --days integer Number of days to lock new objects for. Cannot be used alongside 'years'
- --dst string Name of the bucket to set object locking for its objects (required)
- -h, --help help for set
- --years integer Number of years to lock new objects for. Cannot be used alongside 'days'

## Flags:
```bash
Global Flags:
--api-key string Use your API key to authenticate with the API
--chunk-size integer Chunk size to consider when doing multipart requests. Specified in Mb (range: 8 - 5120) (default 8)
-U, --cli.retry-until string Retry the action with the same parameters until the given condition is met. The flag parameters
use the format: 'retries,interval,condition', where 'retries' is a positive integer, 'interval' is
a duration (ex: 2s) and 'condition' is a 'engine=value' pair such as "jsonpath=expression"
-t, --cli.timeout duration If > 0, it's the timeout for the action execution. It's specified as numbers and unit suffix.
Valid unit suffixes: ns, us, ms, s, m and h. Examples: 300ms, 1m30s
--debug Display detailed log information at the debug level
--no-confirm Bypasses confirmation step for commands that ask a confirmation from the user
-o, --output string Change the output format. Use '--output=help' to know more details.
-r, --raw Output raw data, without any formatting or coloring
--region enum Region to reach the service (one of "br-mgl1", "br-ne1" or "br-se1") (default "br-se1")
--server-url uri Manually specify the server to use
--workers integer Number of routines that spawn to do parallel operations within object_storage (min: 1) (default 5)
```
1 change: 1 addition & 0 deletions mgc/cli/docs/object-storage/objects/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Usage:
- list List all objects from a bucket
- move Moves one object from source to destination
- move-dir Moves objects from source to destination
- object-lock Object locking commands
- presign Generate a pre-signed URL for accessing an object
- public-url Get object public url
- sync Synchronizes a local path with a bucket
Expand Down
35 changes: 35 additions & 0 deletions mgc/cli/docs/object-storage/objects/object-lock/get/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Get object locking configuration for the specified object

## Usage:
```bash
Usage:
./mgc object-storage objects object-lock get [dst] [flags]
```

## Product catalog:
- Flags:
- --dst uri Specifies the object whose lock is being requested (required)
- -h, --help help for get

## Other commands:
- Global Flags:
- --api-key string Use your API key to authenticate with the API
- --chunk-size integer Chunk size to consider when doing multipart requests. Specified in Mb (range: 8 - 5120) (default 8)
- -U, --cli.retry-until string Retry the action with the same parameters until the given condition is met. The flag parameters
- use the format: 'retries,interval,condition', where 'retries' is a positive integer, 'interval' is
- a duration (ex: 2s) and 'condition' is a 'engine=value' pair such as "jsonpath=expression"
- -t, --cli.timeout duration If > 0, it's the timeout for the action execution. It's specified as numbers and unit suffix.
- Valid unit suffixes: ns, us, ms, s, m and h. Examples: 300ms, 1m30s
- --debug Display detailed log information at the debug level
- --no-confirm Bypasses confirmation step for commands that ask a confirmation from the user
- -o, --output string Change the output format. Use '--output=help' to know more details.
- -r, --raw Output raw data, without any formatting or coloring
- --region enum Region to reach the service (one of "br-mgl1", "br-ne1" or "br-se1") (default "br-se1")
- --server-url uri Manually specify the server to use
- --workers integer Number of routines that spawn to do parallel operations within object_storage (min: 1) (default 5)

## Flags:
```bash

```

33 changes: 33 additions & 0 deletions mgc/cli/docs/object-storage/objects/object-lock/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Object locking commands

## Usage:
```bash
Usage:
./mgc object-storage objects object-lock [flags]
./mgc object-storage objects object-lock [command]
```

## Product catalog:
- Commands:
- get Get object locking configuration for the specified object
- set set number of either days or years to lock new objects for

## Other commands:
- Flags:
- -h, --help help for object-lock

## Flags:
```bash
Global Flags:
--api-key string Use your API key to authenticate with the API
-U, --cli.retry-until string Retry the action with the same parameters until the given condition is met. The flag parameters
use the format: 'retries,interval,condition', where 'retries' is a positive integer, 'interval' is
a duration (ex: 2s) and 'condition' is a 'engine=value' pair such as "jsonpath=expression"
-t, --cli.timeout duration If > 0, it's the timeout for the action execution. It's specified as numbers and unit suffix.
Valid unit suffixes: ns, us, ms, s, m and h. Examples: 300ms, 1m30s
--debug Display detailed log information at the debug level
--no-confirm Bypasses confirmation step for commands that ask a confirmation from the user
-o, --output string Change the output format. Use '--output=help' to know more details.
-r, --raw Output raw data, without any formatting or coloring
```
37 changes: 37 additions & 0 deletions mgc/cli/docs/object-storage/objects/object-lock/set/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# set number of either days or years to lock new objects for

## Usage:
```bash
Usage:
./mgc object-storage objects object-lock set [dst] [flags]
```

## Product catalog:
- Examples:
- ./mgc object-storage objects object-lock set --retain-until-date="2025-10-03T00:00:00"

## Other commands:
- Flags:
- --dst uri Specifies the object whose lock is being requested (required)
- -h, --help help for set
- --retain-until-date string Timestamp in ISO 8601 format (required)

## Flags:
```bash
Global Flags:
--api-key string Use your API key to authenticate with the API
--chunk-size integer Chunk size to consider when doing multipart requests. Specified in Mb (range: 8 - 5120) (default 8)
-U, --cli.retry-until string Retry the action with the same parameters until the given condition is met. The flag parameters
use the format: 'retries,interval,condition', where 'retries' is a positive integer, 'interval' is
a duration (ex: 2s) and 'condition' is a 'engine=value' pair such as "jsonpath=expression"
-t, --cli.timeout duration If > 0, it's the timeout for the action execution. It's specified as numbers and unit suffix.
Valid unit suffixes: ns, us, ms, s, m and h. Examples: 300ms, 1m30s
--debug Display detailed log information at the debug level
--no-confirm Bypasses confirmation step for commands that ask a confirmation from the user
-o, --output string Change the output format. Use '--output=help' to know more details.
-r, --raw Output raw data, without any formatting or coloring
--region enum Region to reach the service (one of "br-mgl1", "br-ne1" or "br-se1") (default "br-se1")
--server-url uri Manually specify the server to use
--workers integer Number of routines that spawn to do parallel operations within object_storage (min: 1) (default 5)
```
20 changes: 11 additions & 9 deletions mgc/sdk/static/object_storage/buckets/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"magalu.cloud/core/utils"
"magalu.cloud/sdk/static/object_storage/buckets/acl"
"magalu.cloud/sdk/static/object_storage/buckets/label"
object_lock "magalu.cloud/sdk/static/object_storage/buckets/object-lock"
"magalu.cloud/sdk/static/object_storage/buckets/policy"
"magalu.cloud/sdk/static/object_storage/buckets/versioning"
)
Expand All @@ -17,15 +18,16 @@ var GetGroup = utils.NewLazyLoader[core.Grouper](func() core.Grouper {
},
func() []core.Descriptor {
return []core.Descriptor{
getCreate(), // object-storage buckets create
getDelete(), // object-storage buckets delete
getList(), // object-storage buckets list
getBucket(), // object-storage buckets get
getPublicUrl(), // object-storage objects public-url
acl.GetGroup(), // object-storage buckets acl
versioning.GetGroup(), // object-storage buckets versioning
policy.GetGroup(), // object-storage buckets policy
label.GetGroup(), // object-storage buckets label
getCreate(), // object-storage buckets create
getDelete(), // object-storage buckets delete
getList(), // object-storage buckets list
getBucket(), // object-storage buckets get
getPublicUrl(), // object-storage objects public-url
acl.GetGroup(), // object-storage buckets acl
versioning.GetGroup(), // object-storage buckets versioning
policy.GetGroup(), // object-storage buckets policy
label.GetGroup(), // object-storage buckets label
object_lock.GetGroup(), // object-storage buckets object-lock
}
},
)
Expand Down
61 changes: 61 additions & 0 deletions mgc/sdk/static/object_storage/buckets/object-lock/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package object_lock

import (
"context"
"net/http"

"magalu.cloud/core"
"magalu.cloud/core/utils"
"magalu.cloud/sdk/static/object_storage/common"
)

type GetBucketObjectLockParams struct {
Bucket common.BucketName `json:"dst" jsonschema:"description=Specifies the bucket whose ACL is being requested" mgc:"positional"`
}

type objectLockingResponse struct {
ObjectLockEnabled string
Rule common.ObjectLockRule
}

var getGet = utils.NewLazyLoader[core.Executor](func() core.Executor {
var exec core.Executor = core.NewStaticExecute(
core.DescriptorSpec{
Name: "get",
Description: "Get object locking configuration for the specified bucket",
},
getObjectLocking,
)
exec = core.NewExecuteResultOutputOptions(exec, func(exec core.Executor, result core.Result) string {
return "json"
})
return exec
})

func getObjectLocking(ctx context.Context, params GetBucketObjectLockParams, cfg common.Config) (result objectLockingResponse, err error) {
req, err := newGetObjectLockingRequest(ctx, cfg, params.Bucket)
if err != nil {
return
}

res, err := common.SendRequest(ctx, req)
if err != nil {
return
}

result, err = common.UnwrapResponse[objectLockingResponse](res, req)
return
}

func newGetObjectLockingRequest(ctx context.Context, cfg common.Config, bucketName common.BucketName) (*http.Request, error) {
url, err := common.BuildBucketHostURL(cfg, bucketName)
if err != nil {
return nil, core.UsageError{Err: err}
}

query := url.Query()
query.Add("object-lock", "")
url.RawQuery = query.Encode()

return http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
}
21 changes: 21 additions & 0 deletions mgc/sdk/static/object_storage/buckets/object-lock/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package object_lock

import (
"magalu.cloud/core"
"magalu.cloud/core/utils"
)

var GetGroup = utils.NewLazyLoader(func() core.Grouper {
return core.NewStaticGroup(
core.DescriptorSpec{
Name: "object-lock",
Description: "Object locking commands",
},
func() []core.Descriptor {
return []core.Descriptor{
getGet(), // object-storage buckets object-lock get
getSet(), // object-storage buckets object-lock set
}
},
)
})
Loading

0 comments on commit 50c54d8

Please sign in to comment.