| 568 | |
| 569 | """ Overridable function to read remote files. """ |
| 570 | def read(self, remote_path): |
| 571 | |
| 572 | action = self.actions.get('read', {}) |
| 573 | payload = action.get('read') |
| 574 | call_name = action.get('call', 'render') |
| 575 | |
| 576 | # Skip if something is missing or call function is not set |
| 577 | if not action or not payload or not call_name or not hasattr(self, call_name): |
| 578 | return |
| 579 | |
| 580 | # Get remote file md5 |
| 581 | md5_remote = self.md5(remote_path) |
| 582 | |
| 583 | if not md5_remote: |
| 584 | log.warn('Error getting remote file md5, check presence and permission') |
| 585 | return |
| 586 | |
| 587 | execution_code = payload % ({ 'path' : remote_path }) |
| 588 | |
| 589 | data_b64encoded = getattr(self, call_name)( |
| 590 | code = execution_code, |
| 591 | ) |
| 592 | data = base64.b64decode(data_b64encoded) |
| 593 | |
| 594 | if not md5(data) == md5_remote: |
| 595 | log.warn('Remote file md5 mismatch, check manually') |
| 596 | else: |
| 597 | log.info('File downloaded correctly') |
| 598 | |
| 599 | return data |
| 600 | |
| 601 | def write(self, data, remote_path): |
| 602 | |