コード例 #1
0
    def setup_class(cls):
        print("running setup preparation...")
        # read env vars
        envvars = read_credentials()
        api_key = envvars['API_KEY']
        TestNotification.account_id = envvars['ACCOUNT_ID']
        notificationApiEndpoint = envvars['NOTIFICATION_API_ENDPOINT']
        iam_endpoint = envvars['IAM_ENDPOINT']

        authenticator = IAMAuthenticator(
            url=iam_endpoint,
            apikey=api_key)
        TestNotification.ibm_security_advisor_notifications_api_sdk = NotificationsApiV1(
            authenticator=authenticator)
        TestNotification.ibm_security_advisor_notifications_api_sdk.set_service_url(
            notificationApiEndpoint+"/notifications")

        # read notification json
        with open(jsonDir + "notification.json") as f:
            TestNotification.notification_data = json.load(f)
        
        TestNotification.notification_data[0]['name'] = generate_unique_name()
        TestNotification.create_notification_channel_resp = TestNotification.ibm_security_advisor_notifications_api_sdk.create_notification_channel(
            account_id=TestNotification.account_id,
            **TestNotification.notification_data[0]
        )
from ibm_cloud_security_advisor import NotificationsApiV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator(apikey='abc')
notifications_service = NotificationsApiV1(authenticator=authenticator)
notifications_service.set_service_url(
    "https://us-south.secadvisor.cloud.ibm.com/notifications")

data = {
    "name":
    "sdk_test_notification1",
    "description":
    "test1 description",
    "type":
    "Webhook",
    "endpoint":
    "http://test.com",
    "enabled":
    True,
    "severity": ["high", "medium", "low", "critical"],
    "alert_source": [{
        "provider_name": "VA",
        "finding_types": ["ALL"]
    }, {
        "provider_name": "CERT",
        "finding_types": ["ALL"]
    }]
}
response = notifications_service.create_notification_channel(account_id="abc",
                                                             **data)
コード例 #3
0
 def call_service(self, body):
     service = NotificationsApiV1(authenticator=NoAuthAuthenticator(), )
     service.set_service_url(base_url)
     output = service.get_public_key(**body)
     return output
コード例 #4
0
 def call_service(self, body):
     service = NotificationsApiV1(authenticator=NoAuthAuthenticator(), )
     service.set_service_url(base_url)
     output = service.test_notification_channel(**body)
     return output
コード例 #5
0
 def test_new_instance(self, mock1):
     assert BaseService.__init__ is mock1
     with mock.patch(
             'ibm_cloud_security_advisor.notifications_api_v1.get_authenticator_from_environment'
     ) as mocked_os:
         NotificationsApiV1.new_instance()
コード例 #6
0
 def test_init(self):
     with mock.patch(
             'ibm_cloud_security_advisor.notifications_api_v1.BaseService'
     ) as mocked_os:
         app = NotificationsApiV1({}, )
コード例 #7
0
 def setup_class(cls):
     print("\nrunning setup preparation...")
     with mock.patch(
             'ibm_cloud_security_advisor.notifications_api_v1.BaseService'
     ) as mocked_os:
         TestNotificationsApiV1.app = NotificationsApiV1({}, )