|
10 | 10 | import restful
|
11 | 11 | import api.handlers.ws_domains as ws_domains
|
12 | 12 | import api
|
| 13 | +from pprint import pprint |
13 | 14 |
|
14 | 15 | def iter_lines(fil_or_str):
|
15 | 16 | if isinstance(fil_or_str, (basestring)):
|
@@ -94,39 +95,79 @@ def do_get(cls, refpol_id, response):
|
94 | 95 |
|
95 | 96 | refpol = RefPolicy.Read(refpol_id)
|
96 | 97 |
|
97 |
| - if refpol.documents is None or 'dsl' not in refpol.documents: |
98 |
| - logger.info("Missing DSL. Making service request") |
99 |
| - dsl = ws_domains.call( |
100 |
| - 'lobster', |
101 |
| - 'translate_selinux', |
102 |
| - { |
103 |
| - 'refpolicy': refpol.id, |
104 |
| - 'modules': [] |
105 |
| - } |
106 |
| - ) |
107 |
| - |
108 |
| - if len(dsl['errors']) > 0: |
109 |
| - raise Exception("Failed to translate DSL: {0}" |
110 |
| - .format("\n".join( |
111 |
| - ("{0}".format(x) for x in dsl['errors'])))) |
112 |
| - |
113 |
| - if 'documents' not in refpol: |
114 |
| - refpol['documents'] = {} |
115 |
| - |
116 |
| - refpol['documents']['dsl'] = { |
117 |
| - 'text': dsl['result'], |
118 |
| - 'mode': 'lobster', |
119 |
| - 'digest': hashlib.md5(dsl['result']).hexdigest() |
120 |
| - } |
| 98 | + # For each module in modules, send module.te_file to te2json.py |
| 99 | + # Just get the last module for now, though |
| 100 | + for modname in refpol['modules']: |
| 101 | + print refpol['modules'][modname]['te_file'] |
| 102 | + # Use ws_domains.call() to invoke raw.py and get the raw policy |
| 103 | + module = refpol['modules'][modname] |
| 104 | + raw = ws_domains.call( |
| 105 | + 'raw', |
| 106 | + 'translate_selinux', |
| 107 | + { |
| 108 | + 'refpolicy': refpol.id, |
| 109 | + 'module': module |
| 110 | + } |
| 111 | + ) |
| 112 | + |
| 113 | + result_pol = { |
| 114 | + 'modules': refpol['modules'], |
| 115 | + 'written': refpol['written'], |
| 116 | + 'disk_location': refpol['disk_location'], |
| 117 | + 'valid': refpol['valid'], |
| 118 | + 'total': refpol['total'], |
| 119 | + 'id': refpol['id'], |
| 120 | + '_id': refpol['_id'], |
| 121 | + 'documents': {} |
| 122 | + } |
121 | 123 |
|
122 |
| - refpol.Insert() |
| 124 | + result_pol['documents']['raw'] = { |
| 125 | + 'text': raw, |
| 126 | + 'mode': 'python', |
| 127 | + 'digest': hashlib.md5(raw).hexdigest() |
| 128 | + } |
123 | 129 |
|
124 |
| - elif 'digest' not in refpol.documents['dsl']: |
125 |
| - refpol.documents['dsl']['digest'] = hashlib.md5( |
126 |
| - refpol.documents['dsl']['text']).hexdigest() |
127 |
| - refpol.Insert() |
128 | 130 |
|
129 |
| - response['payload'] = refpol |
| 131 | + # Concatinate all the module files together |
| 132 | + # refpol['documents']['raw'] = { |
| 133 | + # 'text': dsl['result'], |
| 134 | + # 'mode': 'lobster', |
| 135 | + # 'digest': hashlib.md5(dsl['result']).hexdigest() |
| 136 | + # } |
| 137 | + |
| 138 | + # if refpol.documents is None or 'dsl' not in refpol.documents: |
| 139 | + # logger.info("Missing DSL. Making service request") |
| 140 | + # dsl = ws_domains.call( |
| 141 | + # 'lobster', |
| 142 | + # 'translate_selinux', |
| 143 | + # { |
| 144 | + # 'refpolicy': refpol.id, |
| 145 | + # 'modules': [] |
| 146 | + # } |
| 147 | + # ) |
| 148 | + |
| 149 | + # if len(dsl['errors']) > 0: |
| 150 | + # raise Exception("Failed to translate DSL: {0}" |
| 151 | + # .format("\n".join( |
| 152 | + # ("{0}".format(x) for x in dsl['errors'])))) |
| 153 | + |
| 154 | + # if 'documents' not in refpol: |
| 155 | + # refpol['documents'] = {} |
| 156 | + |
| 157 | + # refpol['documents']['dsl'] = { |
| 158 | + # 'text': dsl['result'], |
| 159 | + # 'mode': 'lobster', |
| 160 | + # 'digest': hashlib.md5(dsl['result']).hexdigest() |
| 161 | + # } |
| 162 | + |
| 163 | + # refpol.Insert() |
| 164 | + |
| 165 | + # elif 'digest' not in refpol.documents['dsl']: |
| 166 | + # refpol.documents['dsl']['digest'] = hashlib.md5( |
| 167 | + # refpol.documents['dsl']['text']).hexdigest() |
| 168 | + # refpol.Insert() |
| 169 | + |
| 170 | + response['payload'] = result_pol |
130 | 171 | response['payload'].get('parsed', {}).pop('full', None)
|
131 | 172 | return response
|
132 | 173 |
|
|
0 commit comments