Class: Multiwoven::Integrations::Source::AmazonS3::Client
- Inherits:
-
SourceConnector
- Object
- SourceConnector
- Multiwoven::Integrations::Source::AmazonS3::Client
- Defined in:
- lib/multiwoven/integrations/source/amazon_s3/client.rb
Constant Summary collapse
- DISCOVER_QUERY =
"SELECT * FROM S3Object LIMIT 1;"
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(connection_config) ⇒ Object
- #read(sync_config) ⇒ Object
Instance Method Details
#check_connection(connection_config) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/multiwoven/integrations/source/amazon_s3/client.rb', line 9 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access client = config_aws(connection_config) client.get_bucket_policy_status({ bucket: connection_config[:bucket] }) ConnectionStatus.new(status: ConnectionStatusType["succeeded"]). rescue StandardError => e ConnectionStatus.new(status: ConnectionStatusType["failed"], message: e.). end |
#discover(connection_config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/multiwoven/integrations/source/amazon_s3/client.rb', line 18 def discover(connection_config) connection_config = connection_config.with_indifferent_access conn = create_connection(connection_config) # If pulling from multiple files, all files must have the same schema path = build_path(connection_config[:path]) full_path = "s3://#{connection_config[:bucket]}/#{path}*.#{connection_config[:file_type]}" records = get_results(conn, "DESCRIBE SELECT * FROM '#{full_path}';") columns = build_discover_columns(records) streams = [Multiwoven::Integrations::Protocol::Stream.new(name: full_path, action: StreamAction["fetch"], json_schema: convert_to_json_schema(columns))] catalog = Catalog.new(streams: streams) catalog. rescue StandardError => e handle_exception(e, { context: "AMAZONS3:DISCOVER:EXCEPTION", type: "error" }) end |
#read(sync_config) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/multiwoven/integrations/source/amazon_s3/client.rb', line 33 def read(sync_config) connection_config = sync_config.source.connection_specification.with_indifferent_access conn = create_connection(connection_config) query = sync_config.model.query query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil? query(conn, query) rescue StandardError => e handle_exception(e, { context: "AMAZONS3:READ:EXCEPTION", type: "error", sync_id: sync_config.sync_id, sync_run_id: sync_config.sync_run_id }) end |