def setup_class(cls):
        print("running setup preparation...")
        # read env vars
        envvars = read_credentials()
        api_key = envvars['API_KEY']
        TestOccurrence.account_id = envvars['ACCOUNT_ID']
        findingsApiEndpoint = envvars['FINDING_API_ENDPOINT']
        iam_endpoint = envvars['IAM_ENDPOINT']

        # read note
        with open(jsonDir + "note.json") as f:
            TestOccurrence.note_data = json.load(f)

        authenticator = IAMAuthenticator(url=iam_endpoint, apikey=api_key)
        TestOccurrence.ibm_security_advisor_findings_api_sdk = FindingsApiV1(
            authenticator=authenticator)
        TestOccurrence.ibm_security_advisor_findings_api_sdk.set_service_url(
            findingsApiEndpoint + "/findings")

        print("setup:creating note...")
        create_note_resp = TestOccurrence.ibm_security_advisor_findings_api_sdk.create_note(
            account_id=TestOccurrence.account_id, **TestOccurrence.note_data)

        # read occurrence
        with open(jsonDir + "occurrence.json") as f:
            TestOccurrence.occ_data = json.load(f)

        print("setup:creating occurrence...")
        TestOccurrence.create_occ_resp = TestOccurrence.ibm_security_advisor_findings_api_sdk.create_occurrence(
            account_id=TestOccurrence.account_id,
            note_name=TestOccurrence.account_id + "/providers/" +
            TestOccurrence.occ_data['provider_id'] + "/notes/" +
            TestOccurrence.note_data['id'],
            **TestOccurrence.occ_data)
示例#2
0
    def setup_class(cls):
        print("running setup preparation...")
        # read env vars
        envvars = read_credentials()
        api_key = envvars['API_KEY']
        TestNote.account_id = envvars['ACCOUNT_ID']
        findingsApiEndpoint = envvars['FINDING_API_ENDPOINT']
        iam_endpoint = envvars['IAM_ENDPOINT']
        
		
        # read note
        with open(jsonDir + "note.json") as f:
            TestNote.note_data = json.load(f)
        TestNote.note_data['id'] = generate_unique_string('note')

        authenticator = IAMAuthenticator(
            url=iam_endpoint,
            apikey=api_key)
        TestNote.ibm_security_advisor_findings_api_sdk = FindingsApiV1(
            authenticator=authenticator)
        TestNote.ibm_security_advisor_findings_api_sdk.set_service_url(
            findingsApiEndpoint+"/findings")

        print("setup:creating note...")
        create_note_resp = TestNote.ibm_security_advisor_findings_api_sdk.create_note(
            account_id=TestNote.account_id,
            **TestNote.note_data
        )
        print(create_note_resp)
from ibm_cloud_security_advisor import FindingsApiV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator(apikey='abc')
findings_service = FindingsApiV1(authenticator=authenticator)
findings_service.set_service_url(
    "https://us-south.secadvisor.cloud.ibm.com/findings")

response = findings_service.create_occurrence(
    account_id="abc123",
    provider_id="sdktest",
    note_name="abc123/providers/sdktest/notes/sdk_note_id1",
    kind="FINDING",
    id="sdk_occ_id1",
    context={
        "region": "us-south",
        "resource_type": "Cluster",
        "service_name": "Kubernetes Cluster",
        "account_id": "abc123"
    },
    finding={
        "severity": "LOW",
        "next_steps": [{
            "title": "string",
            "url": "string"
        }]
    })

print(response)
示例#4
0
 def test_new_instance(self, mock1):
     assert BaseService.__init__ is mock1
     with mock.patch(
             'ibm_cloud_security_advisor.findings_api_v1.get_authenticator_from_environment'
     ) as mocked_os:
         FindingsApiV1.new_instance()
示例#5
0
 def test_init(self):
     with mock.patch(
             'ibm_cloud_security_advisor.findings_api_v1.BaseService'
     ) as mocked_os:
         app = FindingsApiV1({}, )
示例#6
0
 def setup_class(cls):
     print("\nrunning setup preparation...")
     with mock.patch(
             'ibm_cloud_security_advisor.findings_api_v1.BaseService'
     ) as mocked_os:
         TestFindingsApi.app = FindingsApiV1({}, )