forked from TrueCloudLab/frostfs-testlib
[#247] Use TestFiles which automatically deletes itself
Signed-off-by: a.berezin <a.berezin@yadro.com>
This commit is contained in:
parent
7a482152a8
commit
cb31d41f15
6 changed files with 209 additions and 346 deletions
|
@ -14,6 +14,7 @@ from frostfs_testlib.shell.local_shell import LocalShell
|
|||
|
||||
# TODO: Refactor this code to use shell instead of _cmd_run
|
||||
from frostfs_testlib.utils.cli_utils import _configure_aws_cli
|
||||
from frostfs_testlib.utils.file_utils import TestFile
|
||||
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
command_options = CommandOptions(timeout=480)
|
||||
|
@ -153,8 +154,7 @@ class AwsCliClient(S3ClientWrapper):
|
|||
@reporter.step("Get bucket acl")
|
||||
def get_bucket_acl(self, bucket: str) -> list:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} s3api get-bucket-acl --bucket {bucket} "
|
||||
f"--endpoint {self.s3gate_endpoint} --profile {self.profile}"
|
||||
f"aws {self.common_flags} s3api get-bucket-acl --bucket {bucket} " f"--endpoint {self.s3gate_endpoint} --profile {self.profile}"
|
||||
)
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
response = self._to_json(output)
|
||||
|
@ -172,10 +172,7 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
@reporter.step("List objects S3")
|
||||
def list_objects(self, bucket: str, full_output: bool = False) -> Union[dict, list[str]]:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} s3api list-objects --bucket {bucket} "
|
||||
f"--endpoint {self.s3gate_endpoint} --profile {self.profile}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} s3api list-objects --bucket {bucket} " f"--endpoint {self.s3gate_endpoint} --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
response = self._to_json(output)
|
||||
|
||||
|
@ -319,18 +316,18 @@ class AwsCliClient(S3ClientWrapper):
|
|||
version_id: Optional[str] = None,
|
||||
object_range: Optional[tuple[int, int]] = None,
|
||||
full_output: bool = False,
|
||||
) -> Union[dict, str]:
|
||||
file_path = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
|
||||
) -> dict | TestFile:
|
||||
test_file = TestFile(os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4())))
|
||||
version = f" --version-id {version_id}" if version_id else ""
|
||||
cmd = (
|
||||
f"aws {self.common_flags} s3api get-object --bucket {bucket} --key {key} "
|
||||
f"{version} {file_path} --endpoint {self.s3gate_endpoint} --profile {self.profile}"
|
||||
f"{version} {test_file} --endpoint {self.s3gate_endpoint} --profile {self.profile}"
|
||||
)
|
||||
if object_range:
|
||||
cmd += f" --range bytes={object_range[0]}-{object_range[1]}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
response = self._to_json(output)
|
||||
return response if full_output else file_path
|
||||
return response if full_output else test_file
|
||||
|
||||
@reporter.step("Get object ACL")
|
||||
def get_object_acl(self, bucket: str, key: str, version_id: Optional[str] = None) -> list:
|
||||
|
@ -583,7 +580,7 @@ class AwsCliClient(S3ClientWrapper):
|
|||
self.local_shell.exec(cmd)
|
||||
|
||||
@reporter.step("Put object tagging")
|
||||
def put_object_tagging(self, bucket: str, key: str, tags: list, version_id: Optional[str] = '') -> None:
|
||||
def put_object_tagging(self, bucket: str, key: str, tags: list, version_id: Optional[str] = "") -> None:
|
||||
tags = [{"Key": tag_key, "Value": tag_value} for tag_key, tag_value in tags]
|
||||
tagging = {"TagSet": tags}
|
||||
version = f" --version-id {version_id}" if version_id else ""
|
||||
|
@ -622,8 +619,7 @@ class AwsCliClient(S3ClientWrapper):
|
|||
metadata: Optional[dict] = None,
|
||||
) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} s3 sync {dir_path} s3://{bucket} "
|
||||
f"--endpoint-url {self.s3gate_endpoint} --profile {self.profile}"
|
||||
f"aws {self.common_flags} s3 sync {dir_path} s3://{bucket} " f"--endpoint-url {self.s3gate_endpoint} --profile {self.profile}"
|
||||
)
|
||||
if metadata:
|
||||
cmd += " --metadata"
|
||||
|
@ -779,9 +775,7 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
@reporter.step("Adds the specified user to the specified group")
|
||||
def iam_add_user_to_group(self, user_name: str, group_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam add-user-to-group --user-name {user_name} --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam add-user-to-group --user-name {user_name} --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -789,12 +783,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Attaches the specified managed policy to the specified IAM group")
|
||||
def iam_attach_group_policy(self, group_name: str, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam attach-group-policy --group-name {group_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam attach-group-policy --group-name {group_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -803,12 +794,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Attaches the specified managed policy to the specified user")
|
||||
def iam_attach_user_policy(self, user_name: str, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam attach-user-policy --user-name {user_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam attach-user-policy --user-name {user_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -817,12 +805,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Creates a new AWS secret access key and access key ID for the specified user")
|
||||
def iam_create_access_key(self, user_name: Optional[str] = None) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam create-access-key --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam create-access-key --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
if user_name:
|
||||
|
@ -837,12 +822,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return access_key_id, secret_access_key
|
||||
|
||||
|
||||
@reporter.step("Creates a new group")
|
||||
def iam_create_group(self, group_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam create-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam create-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -853,7 +835,6 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Creates a new managed policy for your AWS account")
|
||||
def iam_create_policy(self, policy_name: str, policy_document: dict) -> dict:
|
||||
cmd = (
|
||||
|
@ -871,12 +852,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Creates a new IAM user for your AWS account")
|
||||
def iam_create_user(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam create-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam create-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -887,12 +865,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Deletes the access key pair associated with the specified IAM user")
|
||||
def iam_delete_access_key(self, access_key_id: str, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam delete-access-key --access-key-id {access_key_id} --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam delete-access-key --access-key-id {access_key_id} --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
|
||||
|
@ -901,12 +876,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Deletes the specified IAM group")
|
||||
def iam_delete_group(self, group_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam delete-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam delete-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -914,12 +886,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Deletes the specified inline policy that is embedded in the specified IAM group")
|
||||
def iam_delete_group_policy(self, group_name: str, policy_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam delete-group-policy --group-name {group_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam delete-group-policy --group-name {group_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -927,12 +896,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Deletes the specified managed policy")
|
||||
def iam_delete_policy(self, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam delete-policy --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam delete-policy --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -940,26 +906,19 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Deletes the specified IAM user")
|
||||
def iam_delete_user(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam delete-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam delete-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
response = self._to_json(output)
|
||||
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Deletes the specified inline policy that is embedded in the specified IAM user")
|
||||
def iam_delete_user_policy(self, user_name: str, policy_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam delete-user-policy --user-name {user_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam delete-user-policy --user-name {user_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -967,12 +926,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Removes the specified managed policy from the specified IAM group")
|
||||
def iam_detach_group_policy(self, group_name: str, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam detach-group-policy --group-name {group_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam detach-group-policy --group-name {group_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -981,12 +937,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Removes the specified managed policy from the specified user")
|
||||
def iam_detach_user_policy(self, user_name: str, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam detach-user-policy --user-name {user_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam detach-user-policy --user-name {user_name} --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -995,12 +948,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Returns a list of IAM users that are in the specified IAM group")
|
||||
def iam_get_group(self, group_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam get-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam get-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1011,12 +961,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Retrieves the specified inline policy document that is embedded in the specified IAM group")
|
||||
def iam_get_group_policy(self, group_name: str, policy_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam get-group-policy --group-name {group_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam get-group-policy --group-name {group_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1024,12 +971,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Retrieves information about the specified managed policy")
|
||||
def iam_get_policy(self, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam get-policy --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam get-policy --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1040,12 +984,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Retrieves information about the specified version of the specified managed policy")
|
||||
def iam_get_policy_version(self, policy_arn: str, version_id: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam get-policy-version --policy-arn {policy_arn} --version-id {version_id} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam get-policy-version --policy-arn {policy_arn} --version-id {version_id} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1056,12 +997,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Retrieves information about the specified IAM user")
|
||||
def iam_get_user(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam get-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam get-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1072,12 +1010,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Retrieves the specified inline policy document that is embedded in the specified IAM user")
|
||||
def iam_get_user_policy(self, user_name: str, policy_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam get-user-policy --user-name {user_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam get-user-policy --user-name {user_name} --policy-name {policy_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1087,12 +1022,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Returns information about the access key IDs associated with the specified IAM user")
|
||||
def iam_list_access_keys(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-access-keys --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-access-keys --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1100,12 +1032,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists all managed policies that are attached to the specified IAM group")
|
||||
def iam_list_attached_group_policies(self, group_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-attached-group-policies --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-attached-group-policies --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1115,12 +1044,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists all managed policies that are attached to the specified IAM user")
|
||||
def iam_list_attached_user_policies(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-attached-user-policies --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-attached-user-policies --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1130,12 +1056,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists all IAM users, groups, and roles that the specified managed policy is attached to")
|
||||
def iam_list_entities_for_policy(self, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-entities-for-policy --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-entities-for-policy --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1146,12 +1069,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists the names of the inline policies that are embedded in the specified IAM group")
|
||||
def iam_list_group_policies(self, group_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-group-policies --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-group-policies --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1161,12 +1081,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists the IAM groups")
|
||||
def iam_list_groups(self) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-groups --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-groups --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1176,12 +1093,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists the IAM groups that the specified IAM user belongs to")
|
||||
def iam_list_groups_for_user(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-groups-for-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-groups-for-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1191,27 +1105,21 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists all the managed policies that are available in your AWS account")
|
||||
def iam_list_policies(self) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-policies --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-policies --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
response = self._to_json(output)
|
||||
|
||||
assert 'Policies' in response.keys(), f"Expected Policies in response:\n{response}"
|
||||
assert "Policies" in response.keys(), f"Expected Policies in response:\n{response}"
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists information about the versions of the specified managed policy")
|
||||
def iam_list_policy_versions(self, policy_arn: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-policy-versions --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-policy-versions --policy-arn {policy_arn} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1221,12 +1129,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists the names of the inline policies embedded in the specified IAM user")
|
||||
def iam_list_user_policies(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-user-policies --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-user-policies --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1236,12 +1141,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Lists the IAM users")
|
||||
def iam_list_users(self) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-users --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-users --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
output = self.local_shell.exec(cmd).stdout
|
||||
|
@ -1251,12 +1153,11 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Adds or updates an inline policy document that is embedded in the specified IAM group")
|
||||
def iam_put_group_policy(self, group_name: str, policy_name: str, policy_document: dict) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam put-group-policy --endpoint {self.iam_endpoint}"
|
||||
f" --group-name {group_name} --policy-name {policy_name} --policy-document \'{json.dumps(policy_document)}\'"
|
||||
f" --group-name {group_name} --policy-name {policy_name} --policy-document '{json.dumps(policy_document)}'"
|
||||
)
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
|
@ -1266,12 +1167,11 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Adds or updates an inline policy document that is embedded in the specified IAM user")
|
||||
def iam_put_user_policy(self, user_name: str, policy_name: str, policy_document: dict) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam put-user-policy --endpoint {self.iam_endpoint}"
|
||||
f" --user-name {user_name} --policy-name {policy_name} --policy-document \'{json.dumps(policy_document)}\'"
|
||||
f" --user-name {user_name} --policy-name {policy_name} --policy-document '{json.dumps(policy_document)}'"
|
||||
)
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
|
@ -1282,7 +1182,6 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Removes the specified user from the specified group")
|
||||
def iam_remove_user_from_group(self, group_name: str, user_name: str) -> dict:
|
||||
cmd = (
|
||||
|
@ -1296,12 +1195,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Updates the name and/or the path of the specified IAM group")
|
||||
def iam_update_group(self, group_name: str, new_name: Optional[str] = None, new_path: Optional[str] = None) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam update-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam update-group --group-name {group_name} --endpoint {self.iam_endpoint}"
|
||||
if new_name:
|
||||
cmd += f" --new-group-name {new_name}"
|
||||
if new_path:
|
||||
|
@ -1314,12 +1210,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Updates the name and/or the path of the specified IAM user")
|
||||
def iam_update_user(self, user_name: str, new_name: Optional[str] = None, new_path: Optional[str] = None) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam update-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam update-user --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if new_name:
|
||||
cmd += f" --new-user-name {new_name}"
|
||||
if new_path:
|
||||
|
@ -1346,12 +1239,9 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("List tags of IAM user")
|
||||
def iam_list_user_tags(self, user_name: str) -> dict:
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam list-user-tags --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
cmd = f"aws {self.common_flags} iam list-user-tags --user-name {user_name} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
|
||||
|
@ -1360,13 +1250,10 @@ class AwsCliClient(S3ClientWrapper):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@reporter.step("Removes the specified tags from the user")
|
||||
def iam_untag_user(self, user_name: str, tag_keys: list) -> dict:
|
||||
tag_keys_joined = ' '.join(tag_keys)
|
||||
cmd = (
|
||||
f"aws {self.common_flags} iam untag-user --user-name {user_name} --tag-keys {tag_keys_joined} --endpoint {self.iam_endpoint}"
|
||||
)
|
||||
tag_keys_joined = " ".join(tag_keys)
|
||||
cmd = f"aws {self.common_flags} iam untag-user --user-name {user_name} --tag-keys {tag_keys_joined} --endpoint {self.iam_endpoint}"
|
||||
if self.profile:
|
||||
cmd += f" --profile {self.profile}"
|
||||
|
||||
|
@ -1374,5 +1261,3 @@ class AwsCliClient(S3ClientWrapper):
|
|||
response = self._to_json(output)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue