rsa archer rest和grc api库
rsa-archer的Python项目详细描述
使用Archer Rest和内容API的库
我最初的目标是创建Office365邮件到Archer事件应用程序连接器。脚本捕获电子邮件,检查是否分配了事件ID,并将电子邮件添加到Archer记录中的评论部分(子表单)。 这个包支持阿切尔部分连接器,如果有人感兴趣,我可以分享整个事情。
发行说明:
v0.1.7 (30 Aug 2019)
- bug fixes v0.1.4 (05 Feb 2019)
- added user deactivation method and some user method error handling v0.1.3 (29 Jan 2019)
- added archer instance method get_value_id_by_field_name_and_value() to be able to set value in record create/update methods
archer rest api
一。创建Archer实例
在archer中创建具有适当权限的“api”用户 首先,创建archer实例对象并继续使用它
fromrsa_archer.archer_instanceimportArcherInstancearcher_instance=ArcherInstance("domain",INSTANCE,"api username","password")# e.g. archer_instance=ArcherInstance("archer.companyzxc.com","risk_management","api","secure password")
2.使用内容记录
2.1选择应用程序
要开始处理内容记录,您需要选择archer应用程序(每个archer实例对象一个应用程序),没有它将无法工作。
archer_instance.from_application("application name")# e.g.archer_instance.from_application("Incidents")#same name as in archer application list
2.2创建新记录
note-目前,本机处理记录字段的操作仅限于文本字段,对于值列表、attachets和其他类型的字段,您需要使用archer内部id进行操作。很好的例子是使用附件,可以在下面找到。 准备带有字段名及其值(文本或id)的json:
record_json={"field name1":"value1","field name2":"value2","values list field name":[id1,id2,id3..]...}# e.g.record_json={"Incident Summary":"desired text","Reporter email":"email","Incident Details":"HTML text","Severity":[34658]}
创建记录并获取其ID:
record_id=archer_instance.create_content_record(record_json)< H3>现有记录EH3> 2.2
2.2.1获取记录内容
按ID获取记录对象:
existing_record=archer_instance.get_record(record_id)
获取记录字段(包括id)的值:
existing_record.get_field_content("field_name")# it returns, value of the text field# array of user internal ids for user field# proper value for values list# internal ids for other types of fields# TODO other types of fields
2.2.2更新现有记录
准备更新程序json
updater_json={"field name1":"value1","field name2":"value2",...}#e.g.updater_json={"Incident Summary":"desired text","Reporter email":"email","Incident Details":"HTML text"}
更新记录值:
archer_instance.update_content_record(updater_json,record_id)
2.2.3向Archer实例发布附件
将附件上载到Archer并获取其ID:
attachment_id=archer_instance.post_attachment("file name",fileinbase64_string)
将附件ID添加到数组中,您可能希望先获得现有记录攻击ID,并将附加附件ID附加到它上,否则将丢失现有附件:
attachment_ids=[]attachment_ids.append(attachment_id)
然后将ID与现有记录关联起来,例如:
updater_json={"Attachments":attachment_ids}archer_instance.update_content_record(updater_json,record_id)
三。使用内容记录中的子表单
3.1创建子记录
创建子记录并获取其ID:
sub_form_json={"subform field name1":"value1","subform field name1":"value1",...}sub_record_id=archer_instance.create_sub_record(sub_form_json,"subform field name in target application")
然后将子记录与内容记录相关联,在这种情况下存在记录:
updater_json={"subform field name in target application":sub_record_id}archer_instance.update_content_record(updater_json,record_id)<>但是它将取代现有的子记录在应用程序中,所以你应该先得到现有的子记录:
current_sub_records_ids=record.get_field_content("subform field name in target application")#get the array of existing attachments idsifcurrent_sub_records:final_sub_records=current_sub_records_ids+sub_record_idelse:final_sub_records=sub_record_id
然后更新原始申请记录:
updater_json={"subform field name in target application":sub_record_id}archer_instance.update_content_record(updater_json,record_id)
3.2子记录附件
将附件上载到Archer并获取其ID:
attachment_id=archer_instance.post_attachment("file name",fileinbase64_string)
将附件ID放入数组:
attachment_ids=[]attachment_ids.append(attachment_id)
将其与新的子记录关联起来
sub_form_json={"sub form attachment field name":attachment_ids}archer_instance.create_sub_record(sub_form_json,"APPLICATION FIELD NAME")
四。与用户合作
4.1获取用户对象:
获取所有用户对象:
users=archer_instance.get_users()
获取单个用户对象:
user=archer_instance.get_user_by_id("user id")
让用户使用过滤器,请在Archer Rest API文档中找到过滤器的完整列表:
users=archer_instance.get_users("?$select=Id,DisplayName&$orderby=LastName")
获取未登录的活动用户:
users=archer_instance.get_active_users_with_no_login()
4.2获取用户信息
获取用户对象参数(为了方便添加),所有信息都可以在user.json:
email=user.get_user_email()id=user.get_user_id()display_name=user.get_gisplay_name()user_name=user.get_username()last_login=user.get_last_login_date()
4.3使用用户对象
将用户分配给角色:
user.assign_role_to_user("role id")
激活用户:
user.activate_user()
停用用户:
user.deactivate_user()
将用户添加到组:
archer_instance.get_all_groups()#loads all groups firstuser.put_user_to_group("group name")
Archer GRC API(6.4版发布)
要开始在grc api中工作,您需要设置一个端点,它类似于我们在rest中使用的应用程序。 要查找端点的确切名称,可以使用以下方法:
archer_instance.find_grc_endpoint_url("application name")
使用端点名称,您可以获取应用程序的内容记录:
- 一次只能提供1000条记录,使用“跳过”可获取更多信息
- 由于rest api中没有正常的搜索,所以我使用这个api只获取键字段到id的映射。
- 方法返回数组而不是记录对象,因为这些json与rest json不同,我不“不是真的使用它们
array_of_jsons=archer_instance.get_grc_endpoint_records("endpoint name",skip=None)
我正在生成密钥记录字段值以记录内部ID映射:
- 对于事件应用程序,“应用程序密钥字段”是Incident inc xxx,但由于某些原因,密钥记录字段仅存储整数
- 因此,我在我的示例中将前缀“inc-”添加到方法中
archer_instance.build_unique_value_to_id_mapping("endpoint name",tranp_key,"prefix"=None)
因此,根据关键记录字段值,我可以获取记录内部ID:
record_id=archer_instance.get_record_id_by_unique_value(tranp_key)