|
1
|
|
|
# coding=utf-8 |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
See http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html \ |
|
5
|
|
|
#config-Type-Evaluation-ComplianceResourceType |
|
6
|
|
|
""" |
|
7
|
|
|
import datetime |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class AWSConfigEvaluation(object): |
|
11
|
|
|
""" |
|
12
|
|
|
Represents a response payload to an evaluation event |
|
13
|
|
|
""" |
|
14
|
|
|
#: Define an evaluation of a resource as compliant to a rule. See `Evaluation.ComplianceType <http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html#config-Type-Evaluation-ComplianceType>`_. # noqa |
|
15
|
|
|
TYPE_COMPLIANT = 'COMPLIANT' |
|
16
|
|
|
#: Define an evaluation of a resource as not being compliant to a rule. See `Evaluation.ComplianceType <http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html#config-Type-Evaluation-ComplianceType>`_. # noqa |
|
17
|
|
|
TYPE_NON_COMPLIANT = 'NON_COMPLIANT' |
|
18
|
|
|
#: Define a rule as not being applicable to a specific resource. See `Evaluation.ComplianceType <http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html#config-Type-Evaluation-ComplianceType>`_. # noqa |
|
19
|
|
|
TYPE_NOT_APPLICABLE = 'NOT_APPLICABLE' |
|
20
|
|
|
#: Define a rule as not having enough insufficient data for evaluate a resource. See `Evaluation.ComplianceType <http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html#config-Type-Evaluation-ComplianceType>`_. # noqa |
|
21
|
|
|
TYPE_INSUFFICIENT_DATA = 'INSUFFICIENT_DATA' |
|
22
|
|
|
|
|
23
|
|
|
def __init__(self, Type, Annotation, ResourceType=None, ResourceId=None, |
|
24
|
|
|
OrderingTimestamp=None): |
|
25
|
|
|
""" |
|
26
|
|
|
|
|
27
|
|
|
:param Type: One of :py:attr:`~awslambdahelper.evaluation.AWSConfigEvaluation.TYPE_COMPLIANT`, |
|
28
|
|
|
:py:attr:`~awslambdahelper.evaluation.AWSConfigEvaluation.TYPE_NON_COMPLIANT`, |
|
29
|
|
|
:py:attr:`~awslambdahelper.evaluation.AWSConfigEvaluation.TYPE_NOT_APPLICABLE`, or |
|
30
|
|
|
:py:attr:`~awslambdahelper.evaluation.AWSConfigEvaluation.TYPE_INSUFFICIENT_DATA`. |
|
31
|
|
|
:param Annotation: An explanation to attach to the evaluation result. Shown in the AWS Config Console. |
|
32
|
|
|
:type Annotation: str |
|
33
|
|
|
:param ResourceType: |
|
34
|
|
|
:type ResourceType: str |
|
35
|
|
|
:param ResourceId: The id (eg, id-000000) or the ARN (eg, arn:aws:iam:01234567890:eu-west-1:..) for the resource |
|
36
|
|
|
:type ResourceId: str |
|
37
|
|
|
:param OrderingTimestamp: The time of the event in AWS Config that triggered the evaluation. |
|
38
|
|
|
""" |
|
39
|
|
|
self.OrderingTimestamp = OrderingTimestamp |
|
40
|
|
|
self.ComplianceResourceType = ResourceType |
|
41
|
|
|
self.ComplianceResourceId = ResourceId |
|
42
|
|
|
self.ComplianceType = Type |
|
43
|
|
|
self.Annotation = Annotation |
|
44
|
|
|
|
|
45
|
|
|
def set(self, ResourceType=None, ResourceId=None, |
|
46
|
|
|
OrderingTimestamp=None): |
|
47
|
|
|
""" |
|
48
|
|
|
Sets variables for the evaluation, after creation. |
|
49
|
|
|
See the |
|
50
|
|
|
`Evaluation <http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html>`_ resource for details. |
|
51
|
|
|
|
|
52
|
|
|
:param ResourceType: |
|
53
|
|
|
:param ResourceId: The id (eg, id-000000) or the ARN (eg, arn:aws:iam:01234567890:eu-west-1:..) for the resource |
|
54
|
|
|
:param OrderingTimestamp: The time of the event in AWS Config that triggered the evaluation. |
|
55
|
|
|
:return: This evaluation object |
|
56
|
|
|
:rtype: :py:class:`~awslambdahelper.evaluation.AWSConfigEvaluation` |
|
57
|
|
|
""" |
|
58
|
|
|
|
|
59
|
|
|
if ResourceType is not None: |
|
60
|
|
|
self.ComplianceResourceType = ResourceType |
|
61
|
|
|
|
|
62
|
|
|
if ResourceId is not None: |
|
63
|
|
|
self.ComplianceResourceId = ResourceId |
|
64
|
|
|
|
|
65
|
|
|
if OrderingTimestamp is not None: |
|
66
|
|
|
self.OrderingTimestamp = OrderingTimestamp |
|
67
|
|
|
|
|
68
|
|
|
return self |
|
69
|
|
|
|
|
70
|
|
|
def to_dict(self): |
|
71
|
|
|
""" |
|
72
|
|
|
Convert the AWSConfigEvaluation object to |
|
73
|
|
|
an `Evaluation <http://docs.aws.amazon.com/config/latest/APIReference/API_Evaluation.html>`_ payload. If the |
|
74
|
|
|
timestamp is not set, we create one. |
|
75
|
|
|
|
|
76
|
|
|
:return: an AWS Config Evaluation resource |
|
77
|
|
|
:rtype: dict |
|
78
|
|
|
""" |
|
79
|
|
|
|
|
80
|
|
|
response = { |
|
81
|
|
|
'ComplianceType': self.ComplianceType, |
|
82
|
|
|
'Annotation': self.Annotation, |
|
83
|
|
|
'ComplianceResourceType': self.ComplianceResourceType, |
|
84
|
|
|
'ComplianceResourceId': self.ComplianceResourceId |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if self.OrderingTimestamp is None: |
|
88
|
|
|
response['OrderingTimestamp'] = datetime.datetime.utcnow().isoformat() + "Z" |
|
89
|
|
|
else: |
|
90
|
|
|
response['OrderingTimestamp'] = self.OrderingTimestamp |
|
91
|
|
|
|
|
92
|
|
|
return response |
|
93
|
|
|
|