예제 #1
0
    def run(self, params={}):
        group_name = params.get(Input.GROUP_NAME)
        user_id = params.get(Input.USER_ID)

        self.logger.info(f"Getting group info: {group_name}")
        group = get_group(self.connection, group_name)
        group_id = group.get("id")

        self.logger.info(f"Getting user info: {user_id}")
        user_response = get_user_info(self.connection, user_id, self.logger)
        user_object = user_response.json()
        user = {
            "@odata.id":
            f"https://graph.microsoft.com/v1.0/{self.connection.tenant}/users/{user_object.get('id')}"
        }

        headers = self.connection.get_headers(self.connection.get_auth_token())
        add_to_group_endpoint = (
            f"https://graph.microsoft.com/v1.0/{self.connection.tenant}/groups/{group_id}/members/$ref"
        )
        result = requests.post(add_to_group_endpoint,
                               json=user,
                               headers=headers)

        if not result.status_code == 204:
            raise PluginException(
                cause=
                f"Add User to Group call returned an unexpected response: {result.status_code}",
                assistance=
                f"Check that the group name {group_name} and user id {user_id} are correct.",
                data=result.text,
            )

        return {Output.SUCCESS: True}
예제 #2
0
    def run(self, params={}):
        group_name = params.get(Input.NAME)

        self.logger.info(f"Getting group named: {group_name}")

        group_output = get_group(self.connection, group_name)

        # Komand clean doesn't take care of null
        for key in group_output.keys():
            if group_output.get(key) == "null":
                group_output.pop(key)

        return {Output.GROUP: komand.helper.clean(group_output)}