def test_generate_workload_role(self): # noinspection PyArgumentList r = Role(apiVersion=API_VERSION, kind=Role.KIND, type=Role.TYPE, metadata=Metadata(name="Gitlab", description="Gitlab", tags=Tags(RoleTemplate.USER)), spec=Spec(group=["Security"], known_device_only=True)) j: dict = Role.Schema().dump(r) self.assertEqual(API_VERSION, j["apiVersion"]) self.assertEqual(Role.KIND, j["kind"]) self.assertIn("metadata", j.keys()) self.assertEqual("Gitlab", j["metadata"]["name"]) self.assertIn("spec", j.keys()) self.assertEqual("Security", j["spec"]["group"][0])
def test_parse_group_role(self): r: Role = Role.Schema().loads( load_testdata("tests/data/role_group.json")) self.assertEqual(Role.KIND, r.kind) self.assertEqual("Gitlab", r.metadata.name) self.assertEqual(["Security"], r.spec.group) self.assertEqual([], r.spec.device_ownership)
def update(self): policy_spec = Base.get_json_input(self.app.pargs.role_spec) policy = Role.Schema().load(policy_spec) policy_info = self._client.update(policy) self.app.render(RoleInfo.Schema().dump(policy_info), handler='json', indent=2, sort_keys=True)
def test_parse_email_role(self): r: Role = Role.Schema().loads( load_testdata("tests/data/role_email.json")) self.assertEqual(Role.KIND, r.kind) self.assertEqual("Email", r.metadata.name) self.assertEqual([], r.spec.group) self.assertEqual([], r.spec.device_ownership, []) self.assertEqual(["*****@*****.**"], r.spec.email)
def test_parse_workload_role(self): r: Role = Role.Schema().loads( load_testdata("tests/data/role_workload.json")) self.assertEqual(Role.KIND, r.kind) self.assertEqual("vault-client", r.metadata.name) self.assertEqual(1, len(r.spec.label_selector)) self.assertEqual( "vault-client", r.spec.label_selector[0]["com.banyanops.hosttag.role"])
def create(self): spec = Base.get_json_input(self.app.pargs.role_spec) role = Role.Schema().load(spec) role_id = self._client.create(role) self.app.print(f'Role ID: {role_id}')
def get(self): info: RoleInfo = self._client[self.app.pargs.role_name] role_json = Role.Schema().dump(info.role) # colorized_json = highlight(policy_json, lexers.JsonLexer(), formatters.Terminal256Formatter(style="default")) self.app.render(role_json, handler='json', indent=2, sort_keys=True)