|
1 | 1 | """Index and retrive information from the resource JSON."""
|
2 | 2 | import jmespath
|
| 3 | +from collections import namedtuple |
| 4 | + |
| 5 | +# service - The name of the AWS service |
| 6 | +# operation - The name of the AWS operation |
| 7 | +# params - A dict of params to send in the request (not implemented yet) |
| 8 | +# path - A JMESPath expression to select the expected elements. |
| 9 | +ServerCompletion = namedtuple('ServerCompletion', |
| 10 | + ['service', 'operation', 'params', 'path']) |
3 | 11 |
|
4 | 12 |
|
5 | 13 | def extract_field_from_jmespath(expression):
|
@@ -57,6 +65,44 @@ def build_index(self, resource_data):
|
57 | 65 | return index
|
58 | 66 |
|
59 | 67 |
|
| 68 | +class CompleterQuery(object): |
| 69 | + """Describes how to autocomplete a resource.""" |
| 70 | + def __init__(self, resource_index): |
| 71 | + self._index = resource_index |
| 72 | + |
| 73 | + def describe_autocomplete(self, service, operation, param): |
| 74 | + """ |
| 75 | +
|
| 76 | + :type service: str |
| 77 | + :param service: The AWS service name. |
| 78 | +
|
| 79 | + :type operation: str |
| 80 | + :param operation: The AWS operation name. |
| 81 | +
|
| 82 | + :type param: str |
| 83 | + :param param: The name of the parameter being completed. This must |
| 84 | + match the casing in the service model (e.g. InstanceIds, not |
| 85 | + --instance-ids). |
| 86 | +
|
| 87 | + :rtype: ServerCompletion |
| 88 | + :return: A ServerCompletion object that describes what API call to make |
| 89 | + in order to complete the response. |
| 90 | +
|
| 91 | + """ |
| 92 | + service_index = self._index[service] |
| 93 | + if param not in service_index.get('operations', {}).get(operation, {}): |
| 94 | + return None |
| 95 | + p = service_index['operations'][operation][param] |
| 96 | + resource_name = p['resourceName'] |
| 97 | + resource_identifier = p['resourceIdentifier'] |
| 98 | + |
| 99 | + resource_index = service_index['resources'][resource_name] |
| 100 | + completion_operation = resource_index['operation'] |
| 101 | + path = resource_index['resourceIdentifier'][resource_identifier] |
| 102 | + return ServerCompletion(service=service, operation=completion_operation, |
| 103 | + params={}, path=path) |
| 104 | + |
| 105 | + |
60 | 106 | def main():
|
61 | 107 | import sys
|
62 | 108 | import json
|
|
0 commit comments