kozeki-aws 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ef60ead4c72f1520ea141b3be7dc5d844895613012806c52e0a2683a21c31d85
4
+ data.tar.gz: 52296210b6690184887ca538994651968c2e7309b2d4096f77031b25f8471110
5
+ SHA512:
6
+ metadata.gz: 04a1e7bae1964bf58db7b3788e4c9453d533a2cb4d12479c0bb1cc83071446ba01bc0162124fd105347e0c6bcebd290b5bda7a4b013f5aef218a6a4bd7a90c6d
7
+ data.tar.gz: 21b29735a9eed6e96fbaa7fb856d17392cbdf1cf7a199e2c2f509f8408fc82e865bd9be49b4dd1230be838e68e439424bcca35d747bb48cf724907f0f21a7585
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-11-15
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Kozeki::Aws
2
+
3
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+ require 'aws-sdk-s3'
3
+ require 'stringio'
4
+ require 'kozeki/filesystem'
5
+
6
+ module Kozeki
7
+ module Aws
8
+ class S3Filesystem
9
+ include Kozeki::Filesystem
10
+
11
+ def initialize(client: ::Aws::S3::Client.new, bucket:, prefix:, delimiter: '/', cache_control: nil)
12
+ @s3 = client
13
+ @bucket = bucket
14
+ @prefix = prefix
15
+ @delimiter = delimiter
16
+ @cache_control = cache_control || method(:default_cache_control)
17
+ end
18
+
19
+ attr_reader :s3, :bucket, :prefix, :delimiter
20
+
21
+ def read_with_mtime(path)
22
+ r = @s3.get_object(
23
+ bucket:,
24
+ key: make_key(path),
25
+ )
26
+ [
27
+ r.body,
28
+ r.last_modified,
29
+ ]
30
+ rescue Aws::S3::Errors::NotFound
31
+ raise Kozeki::Filesystem::NotFound
32
+ end
33
+
34
+ def write(path, string)
35
+ key = make_key(path)
36
+ @s3.put_object(
37
+ bucket:,
38
+ key:,
39
+ body: StringIO.new(string, 'r'), # avoid body to be logged
40
+ content_type: content_type_for(path),
41
+ cache_control: @cache_control[key],
42
+ )
43
+ nil
44
+ end
45
+
46
+ def delete(path)
47
+ @s3.delete_object(
48
+ bucket:,
49
+ key: make_key(path),
50
+ )
51
+ nil
52
+ rescue Aws::S3::Errors::NotFound
53
+ nil
54
+ end
55
+
56
+ def list_entries
57
+ @s3.list_objects_v2(
58
+ bucket:,
59
+ prefix:,
60
+ ).flat_map do |page|
61
+ page.contents.map do |content|
62
+ Kozeki::Filesystem::Entry.new(
63
+ path: key_to_path(content.key),
64
+ mtime: content.last_modified,
65
+ )
66
+ end
67
+ end
68
+ end
69
+
70
+ private def make_key(path)
71
+ "#{prefix}#{path.join(delimiter)}"
72
+ end
73
+
74
+ private def key_to_path(key)
75
+ raise "key didn't start with prefix" unless key.start_with?(prefix)
76
+ key[prefix.size..-1].split(delimiter)
77
+ end
78
+
79
+ private def content_type_for(path)
80
+ case path[-1]
81
+ when /\.json$/
82
+ 'application/json; charset=utf-8'
83
+ else
84
+ 'application/octet-stream'
85
+ end
86
+ end
87
+
88
+ private def default_cache_control(key)
89
+ nil
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kozeki
4
+ module Aws
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/kozeki/aws.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "aws/version"
4
+ require_relative "aws/s3_filesystem"
5
+
6
+ module Kozeki
7
+ module Aws
8
+ end
9
+ end
data/scripts/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "kozeki/aws"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/scripts/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kozeki-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sorah Fukumori
8
+ autorequire:
9
+ bindir: scripts
10
+ cert_chain: []
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kozeki
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-s3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - her@sorah.jp
44
+ executables:
45
+ - console
46
+ - setup
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - CHANGELOG.md
51
+ - README.md
52
+ - Rakefile
53
+ - lib/kozeki/aws.rb
54
+ - lib/kozeki/aws/s3_filesystem.rb
55
+ - lib/kozeki/aws/version.rb
56
+ - scripts/console
57
+ - scripts/setup
58
+ homepage: https://github.com/sorah/kozeki
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ homepage_uri: https://github.com/sorah/kozeki
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 3.1.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.4.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: AWS plugins for Kozeki
82
+ test_files: []