Path: blob/develop/awscli/customizations/cloudtrail/utils.py
1567 views
# Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.121314def get_account_id_from_arn(trail_arn):15"""Gets the account ID portion of an ARN"""16return trail_arn.split(':')[4]171819def get_account_id(sts_client):20"""Retrieve the AWS account ID for the authenticated user or role"""21response = sts_client.get_caller_identity()22return response['Account']232425def get_trail_by_arn(cloudtrail_client, trail_arn):26"""Gets trail information based on the trail's ARN"""27trails = cloudtrail_client.describe_trails()['trailList']28for trail in trails:29if trail.get('TrailARN', None) == trail_arn:30return trail31raise ValueError('A trail could not be found for %s' % trail_arn)323334