| 45 | self.name = "amazon_aws" |
| 46 | |
| 47 | def connect(self): |
| 48 | log = regular_log.default() |
| 49 | try: |
| 50 | if 'client_id' not in self.auth_data: |
| 51 | log['error']['client_id'] = 'auth_data must provide a client_id.' |
| 52 | return {'log': log} |
| 53 | if 'client_secret' not in self.auth_data: |
| 54 | log['error']['client_secret'] = 'auth_data must provide aws_access_key_id and aws_secret_access_key .' |
| 55 | return {'log': log} |
| 56 | |
| 57 | config = None |
| 58 | if self.auth_data.get('aws_v4_signature'): |
| 59 | config = Config(signature_version = 's3v4') |
| 60 | |
| 61 | self.connection_client = DataToolsS3.get_client( |
| 62 | aws_access_key_id = self.auth_data['client_id'], |
| 63 | aws_secret_access_key = self.auth_data['client_secret'], |
| 64 | config = config, |
| 65 | region_name = self.auth_data.get('aws_region') |
| 66 | ) |
| 67 | self.url_signer_service = None |
| 68 | if self.auth_data.get('url_signer_service') is not None and self.auth_data.get('url_signer_service') != '': |
| 69 | self.url_signer_service = self.auth_data.get('url_signer_service') |
| 70 | if self.url_signer_service.endswith('/'): |
| 71 | # Remove trailing slash |
| 72 | self.url_signer_service = self.url_signer_service.rstrip(self.url_signer_service[-1]) |
| 73 | |
| 74 | return {'result': True} |
| 75 | except Exception as e: |
| 76 | log['error'][ |
| 77 | 'auth_credentials'] = 'Error connecting to AWS S3. Please check you private key, email and id are correct.' |
| 78 | return {'log': log} |
| 79 | |
| 80 | @with_connection |
| 81 | def __get_string_data(self, opts): |