Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
""" Example script showing how to onboard an AWS environment.
"""
import logging

from dt_api_security_results.client import ApiSecurityResultsClient
from dt_api_security_results.messages import CloudAuthenticatorCreateRequest
from dt_api_security_results.models.cloud_authenticators import AwsAuthenticator, \
CloudAuthenticatorTypesEnum

# TODO: Replace these values
API_KEY = "MDAwMDAwMDAwMDAwMDAwMA=="
ROLE_ARN = "arn:aws:iam::12345678:role/DataTheoremAccess"
EXTERNAL_ID = "z96hmxdd96fm37sfeyavnbmu4pz510qx"

logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")

if __name__ == "__main__":
    client = ApiSecurityResultsClient(
        api_key=API_KEY, base_url="https://dev-horizon.appspot.com/customer/beta"
    )

    request = CloudAuthenticatorCreateRequest(
        cloud_authenticator_type=CloudAuthenticatorTypesEnum.AMAZON_WEB_SERVICES,
        aws_credential=AwsAuthenticator(role_arn=ROLE_ARN, external_id=EXTERNAL_ID),
    )
    try:
        response = client.cloud_authenticator_create(authenticator_request=request)
    except Exception:
        logging.exception("An error occurred.")
    else:
        logging.info(f"Successfully added cloud authenticator: {response.json()}")
    logging.info("All done.")