Skip to content

Commit 6bd0b31

Browse files
committed
new spec: mgc cli bucket policy basic usage
This patch adds specs covering the basic usage of the bucket policy feature using the mgc cli. The examples in here should include the same examples on the other specs: - https://docs.magalu.cloud/docs/storage/object-storage/how-to/permissions/policies - https://github.com/MagaluCloud/s3-tester/blob/main/spec/091_bucket-policy_spec.sh
1 parent 39b17d0 commit 6bd0b31

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

docs/conftest.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def mgc_path(default_profile):
7878
else:
7979
spec_dir = os.path.dirname(get_spec_path())
8080
path = os.path.join(spec_dir, default_profile.get(mgc_path_field_name))
81-
if not os.path.isfile(path):
82-
pytest.fail(f"The specified mgc_path '{path}' (absolute: {os.path.abspath(path)}) does not exist or is not a file.")
81+
abspath = os.path.abspath(path) if path and os.path.isfile(path) else path
82+
if not abspath:
83+
pytest.fail(f"The specified mgc_path '{path}' (absolute: {abspath}) does not exist or is not a file.")
8384
return path
8485

8586
@pytest.fixture

docs/policy_cli_test.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# ---
2+
# jupyter:
3+
# kernelspec:
4+
# name: s3-specs
5+
# display_name: S3 Specs
6+
# language_info:
7+
# name: python
8+
# ---
9+
10+
# # Bucket Policy via MGC CLI
11+
#
12+
# Restringir determinadas ações passíveis de serem executadas em um bucket, ou
13+
# compartilhar acessos de leitura e escrita com outros usuários (Principals),
14+
# são exemplos de possibilidades que a funcionalidade de Bucket Policy (políticas
15+
# do conteiner) permitem.
16+
#
17+
# A configuração, remoção e atualização de políticas em um bucket, por documentos
18+
# de policy (arquivos JSON) pode ser feita via MGC CLI. Este é o assunto desta
19+
# especificação.
20+
#
21+
22+
# + tags=["parameters"]
23+
config = "../params.example.yaml"
24+
# -
25+
26+
# + {"jupyter": {"source_hidden": true}}
27+
import pytest
28+
import logging
29+
import subprocess
30+
from shlex import split
31+
from s3_helpers import (
32+
run_example,
33+
)
34+
pytestmark = [pytest.mark.basic, pytest.mark.cli]
35+
# -
36+
37+
# ## Documentos relacionados
38+
#
39+
# Uma breve lista de outras referências sobre Bucket Policy
40+
#
41+
# - Docs Magalu Cloud: [Docs > Armazenamento > Object Storage > Como Fazer > Permissões > Bucket Policy](https://docs.magalu.cloud/docs/storage/object-storage/how-to/permissions/policies)
42+
# - s3-specs: [python/boto3 policies spec 1](https://magalucloud.github.io/s3-specs/runs/profiles_policies_test_br-ne1.html)
43+
# - s3-specs: [python/boto3 policies spec 2](https://magalucloud.github.io/s3-specs/runs/policies_test_test_br-ne1.html)
44+
# - s3-tester (specs legadas): [legacy s3-tester spec id:091](https://github.com/MagaluCloud/s3-tester/blob/main/spec/091_bucket-policy_spec.sh)
45+
# - AWS S3: [Bucket Policies for Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html)
46+
# - AWS S3: [Bucket policies](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-bucket-policies.html)
47+
48+
# ## Como fazer
49+
50+
# ### Lista dos comandos disponíveis
51+
#
52+
# O manual de uso com os comandos disponíveis na CLI relacionados a Bucket Policy
53+
# pode ser consultado via terminal usando o comando abaixo:
54+
55+
commands = [
56+
"{mgc_path} object-storage buckets policy --help",
57+
]
58+
59+
# + {"jupyter": {"source_hidden": true}}
60+
@pytest.mark.parametrize("cmd_template", commands)
61+
def test_cli_help_policy(cmd_template, mgc_path):
62+
cmd = split(cmd_template.format(mgc_path=mgc_path))
63+
result = subprocess.run(cmd, capture_output=True, text=True)
64+
65+
assert result.returncode == 0, f"Command failed with error: {result.stderr}"
66+
logging.debug(f"Output from {cmd_template}: {result.stdout}")
67+
assert all(snippet in result.stdout for snippet in ["delete", "get", "set"])
68+
69+
run_example(__name__, "test_cli_help_policy", config=config)
70+
# -

0 commit comments

Comments
 (0)