Example #1
0
    def create_project_robot(self,
                             project_name,
                             expires_at,
                             robot_name=None,
                             robot_desc=None,
                             has_pull_right=True,
                             has_push_right=True,
                             has_chart_read_right=True,
                             has_chart_create_right=True,
                             expect_status_code=201,
                             **kwargs):
        if robot_name is None:
            robot_name = base._random_name("robot")
        if robot_desc is None:
            robot_desc = base._random_name("robot_desc")
        if has_pull_right is False and has_push_right is False:
            has_pull_right = True
        access_list = []
        action_pull = "pull"
        action_push = "push"
        action_read = "read"
        action_create = "create"
        if has_pull_right is True:
            robotAccountAccess = v2_swagger_client.Access(
                resource="repository", action=action_pull)
            access_list.append(robotAccountAccess)
        if has_push_right is True:
            robotAccountAccess = v2_swagger_client.Access(
                resource="repository", action=action_push)
            access_list.append(robotAccountAccess)
        if has_chart_read_right is True:
            robotAccountAccess = v2_swagger_client.Access(
                resource="helm-chart", action=action_read)
            access_list.append(robotAccountAccess)
        if has_chart_create_right is True:
            robotAccountAccess = v2_swagger_client.Access(
                resource="helm-chart-version", action=action_create)
            access_list.append(robotAccountAccess)

        robotaccountPermissions = v2_swagger_client.Permission(
            kind="project", namespace=project_name, access=access_list)
        permission_list = []
        permission_list.append(robotaccountPermissions)
        robotAccountCreate = v2_swagger_client.RobotCreate(
            name=robot_name,
            description=robot_desc,
            expires_at=expires_at,
            level="project",
            permissions=permission_list)

        client = self._get_client(**kwargs)
        data = []
        data, status_code, header = client.create_robot_with_http_info(
            robotAccountCreate)
        base._assert_status_code(expect_status_code, status_code)
        base._assert_status_code(201, status_code)
        return base._get_id_from_header(header), data
Example #2
0
    def create_access_list(self, right_map = [True] * 10):
        _assert_status_code(10, len(right_map), r"Please input full access list for system robot account. Expected {}, while actual input count is {}.")
        action_pull = "pull"
        action_push = "push"
        action_read = "read"
        action_create = "create"
        action_del = "delete"

        access_def_list = [
            ("repository", action_pull),
            ("repository", action_push),
            ("artifact", action_del),
            ("helm-chart", action_read),
            ("helm-chart-version", action_create),
            ("helm-chart-version", action_del),
            ("tag", action_create),
            ("tag", action_del),
            ("artifact-label", action_create),
            ("scan", action_create)
        ]

        access_list = []
        for i in range(len(access_def_list)):
            if right_map[i] is True:
                robotAccountAccess = v2_swagger_client.Access(resource = access_def_list[i][0], action = access_def_list[i][1])
                access_list.append(robotAccountAccess)
        return access_list