ssd 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3612cdb1ce4050fcce37d43f7bed735b2ab3a8e3
4
+ data.tar.gz: 034c08db0254a426d7236d79374ff042e1ea5c5e
5
+ SHA512:
6
+ metadata.gz: 1e7700b75c47565ac400f184fee70134bf52e94f69dca1a923a25dea8a0d8db008b408775461e27dd0b791fa7909c64c726436a7b4184f14a4bf3fa7ee524fb8
7
+ data.tar.gz: 2e4b4138b8031616a268ccf5fabb1cbff44635467e7fe14231a3b56a59dcee7bc974c990780846e19abfaeb07d5cb8de1b4217dac80c6c754733cde9b61d15ff
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.swp
2
+ SSD
3
+ *.lock
4
+ *.gem
5
+ .ssd
6
+ pkg
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at zotherstupidguy@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ssd.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 zotherstupidguy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ What is SSD?
2
+ ==================
3
+ SSD (Simply-Smart-Data) is an append-only, file-based, immutable key-value store for Microservices written in Ruby.
4
+
5
+ Key Features
6
+ =================
7
+ - Scalable file-based design (each key gets its own file).
8
+ - Immutable (timestamped inserts).
9
+ - Fault tolerance (transactional operations).
10
+ - Measurably low technical debt (consciously clean small-sized library that wouldn't complect your codebase).
11
+ - Zero external dependencies.
12
+ - Schemaless (easily meets your Application evolution needs).
13
+ - Append-only (easily keeps track of Applications Data timeline).
14
+ - Key-based rolling-forward\rolling-back.
15
+ - Strict Security-first policy SHA256 Encryption (implment your own logging for intercepting keys required for decrypting data).
16
+ - JSON objects (based on ruby's native pstore).
17
+ - RESTful HTTP/JSON API Endpoint.
18
+ - Super easy to learn (up & running in mins).
19
+
20
+ Use Cases
21
+ ==========
22
+ SSD is carefully crafted to scale specially-well with the Microservies Architeturual Pattern to allow providing storage for independently deployable services with ease.
23
+
24
+ Usage
25
+ ======
26
+ ```ruby
27
+ class User
28
+ include SSD
29
+ attr_accessor :id # ssd key
30
+ end
31
+ ```
32
+
33
+ Concerns FAQs
34
+ ===============
35
+ Asynchronous I/O [https://en.wikipedia.org/wiki/Asynchronous_I/O]
36
+
37
+ Other Alternatives
38
+ ======================
39
+ - ArangoDB [https://www.arangodb.com/].
40
+ - Persistent [https://github.com/ismasan/persistent].
41
+ - CouchDB [http://couchdb.apache.org/].
42
+ - DataMapper [http://github.com/datamapper/dm-core/tree/master].
43
+ - Persistable [http://github.com/andykent/persistable/tree/master].
44
+ - Stone [http://github.com/ndemonner/stone/tree/master].
45
+
46
+ References
47
+ ===========
48
+ - The rise of append-only, immutable data stores. [http://www.pwc.com/us/en/technology-forecast/2015/remapping-database-landscape/features/assets/pwc-append-only-immutable-data-stores-rise.pdf]
49
+ - NoSQL DB. [http://nosql-database.org/]
50
+ - Anti-RDBMs. [https://www.metabrew.com/article/anti-rdbms-a-list-of-distributed-key-value-stores]
51
+ - Architecture of immutable data stores. [http://www.toadworld.com/platforms/oracle/w/wiki/11548.architecture-of-immutable-data-stores]
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ssd"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/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
data/lib/encrypt.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'openssl'
2
+ require 'digest/sha1'
3
+
4
+ # Get SHA256 Hash of a file
5
+ # puts Digest::SHA256.hexdigest File.read "data.dat"
6
+ # # Get MD5 Hash of a file
7
+ # puts Digest::MD5.hexdigest File.read "data.dat"
8
+ # # Get MD5 Hash of a string
9
+ # puts Digest::SHA256.hexdigest "Hello World"
10
+ #
11
+ # # Get SHA256 Hash of a string using update
12
+ # sha256 = Digest::SHA256.new
13
+ # sha256.update "Hello"
14
+ # sha256.update " World"
15
+ # puts sha256.hexdigest
16
+
17
+ c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
18
+ c.encrypt
19
+ # your pass is what is used to encrypt/decrypt
20
+ # puts Digest::SHA256.hexdigest "Hello World"
21
+ c.key = key = Digest::SHA256.hexdigest "user_id_1232131313123131313135341"
22
+ #Digest::SHA1.hexdigest("yourpass")
23
+ c.iv = iv = c.random_iv
24
+ e = c.update("this is verylongwithmany special characters jsonfile")
25
+ e << c.final
26
+ puts "encrypted: #{e}\n"
27
+ c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
28
+ c.decrypt
29
+ c.key = key
30
+ c.iv = iv
31
+ d = c.update(e)
32
+ d << c.final
33
+ puts "decrypted: #{d}\n"
data/lib/ssd.rb ADDED
@@ -0,0 +1,144 @@
1
+ require 'fileutils'
2
+ require 'logger'
3
+ require 'securerandom'
4
+ require 'pstore'
5
+ require 'digest'
6
+
7
+ require_relative "./ssd/version"
8
+
9
+ $log = Logger.new(STDOUT)
10
+
11
+ module SSD
12
+ attr_reader :db
13
+ attr_reader :path
14
+
15
+ def self.included(base)
16
+ base.send :include, InstanceMethods
17
+ base.extend ClassMethods
18
+ end
19
+
20
+ module InstanceMethods
21
+
22
+ def self.included(base)
23
+ @@ssd_name = base.new.class.to_s.downcase
24
+ end
25
+
26
+ attr_accessor :id
27
+
28
+ def id= value
29
+ @id = value
30
+ FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
31
+ @@ssd_path = ".ssd/#{@@ssd_name}/#{@id}.ssd"
32
+ @@ssd_db = PStore.new @@ssd_path, true
33
+ @@ssd_db.ultra_safe = true
34
+ @@ssd_db.transaction(true) {}
35
+ return @@ssd_db
36
+ end
37
+
38
+ def transaction
39
+ @@ssd_db.transaction do
40
+ yield @@ssd_db
41
+ @@ssd_db.commit
42
+ end
43
+ end
44
+
45
+ def []=
46
+ begin
47
+ if !@id.nil? then
48
+ @@ssd_db.transaction do
49
+ #todo should be somthing like??? timestamp instead of id as a key?? and use .last while reading
50
+ #@@ssd_db[id.to_sym] = self
51
+ @@ssd_db[Time.now.utc.to_s + "_" + Random.new_seed.to_s ] = self
52
+ end
53
+ else
54
+ raise 'ssd id can not be nil. see more (documentation url)'
55
+ end
56
+ end
57
+ end
58
+
59
+ alias append []=
60
+ alias save []=
61
+ alias store []=
62
+ end
63
+
64
+ module ClassMethods
65
+ def self.extended(base)
66
+ @@ssd_name = base.new.class.to_s.downcase
67
+ #FileUtils::mkdir_p 'DS'
68
+ #@@ssd_path = "DS/#{name}.pstore"
69
+ #@@ssd_db = PStore.new @@ssd_path, true
70
+ #@@ssd_db.ultra_safe = true
71
+ #@@ssd_db.transaction(true) {}
72
+ #@@ssd_db
73
+ end
74
+
75
+ def setup id
76
+ @@id = id
77
+ FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
78
+ @@ssd_path = ".ssd/#{@@ssd_name}/#{@@id}.ssd"
79
+ @@ssd_db = PStore.new @@ssd_path, true
80
+ @@ssd_db.ultra_safe = true
81
+ @@ssd_db.transaction(true) {}
82
+ return @@ssd_db
83
+ end
84
+
85
+ def last_key id
86
+ setup id
87
+ last_key = @@ssd_db.transaction true do
88
+ @@ssd_db.roots
89
+ end
90
+ last_key.last
91
+ end
92
+
93
+ def keys id
94
+ setup id
95
+ @@ssd_db.transaction true do
96
+ @@ssd_db.roots
97
+ end
98
+ end
99
+
100
+ def key? id
101
+ setup id
102
+ @@ssd_db.transaction true do
103
+ @@ssd_db.root? id.to_sym
104
+ end
105
+ end
106
+
107
+ alias exists? key?
108
+
109
+ def [] id
110
+ setup id
111
+ @@ssd_db.transaction true do
112
+ @@ssd_db[id.to_sym]
113
+ end
114
+ end
115
+
116
+ def fetch id
117
+ #TODO add raise if id.nil?
118
+ last_key = (last_key id)
119
+ @@ssd_db.transaction true do
120
+ @@ssd_db.fetch last_key
121
+ end
122
+ end
123
+
124
+ alias get fetch
125
+ alias find fetch
126
+
127
+ def delete *ids
128
+ @@ssd_db.transaction do
129
+ ids.each do |id|
130
+ @@ssd_db.delete id.to_sym
131
+ end
132
+ @@ssd_db.commit
133
+ end
134
+ end
135
+ alias remove delete
136
+
137
+ def count id
138
+ setup id
139
+ $log.info("count")
140
+ return keys(id).count
141
+ end
142
+ end
143
+
144
+ end
@@ -0,0 +1,3 @@
1
+ module SSD
2
+ VERSION = "0.1.0"
3
+ end
data/logo.png ADDED
Binary file
@@ -0,0 +1,4 @@
1
+ require "minitest/autorun"
2
+ require "minitest/pride"
3
+
4
+ require_relative "./../lib/ssd"
data/specs/ssd_spec.rb ADDED
@@ -0,0 +1,55 @@
1
+ require_relative "./spec_helper"
2
+
3
+ describe SSD do
4
+
5
+ before do
6
+ class User
7
+ include SSD
8
+ attr_accessor :first_name, :last_name, :location
9
+ end
10
+
11
+ @generated_id = Random.new.seed
12
+ end
13
+
14
+ describe "#append" do
15
+ it "saves an object to the database" do
16
+ #skip
17
+ @user = User.new
18
+ @user.id = @generated_id
19
+ @user.append
20
+ @user.id.must_equal @generated_id
21
+ end
22
+ end
23
+
24
+ describe "#read" do
25
+ it "fetches an object from the database" do
26
+ # skip
27
+ @user = User.new
28
+ @user.id = @generated_id
29
+ @user.append
30
+ user = User.get(@generated_id)
31
+ user.id.must_equal @generated_id
32
+ end
33
+ end
34
+
35
+ describe "an append-only operations" do
36
+ it "it keeps adding new objects" do
37
+ @user = User.new
38
+
39
+ @user.id = @generated_id
40
+ @user.location = "Egypt"
41
+ @user.append
42
+
43
+ @user = User.get(@generated_id)
44
+ @user.location = "Brazil"
45
+ @user.append
46
+
47
+ @user = User.get(@generated_id)
48
+ @user.location = "France"
49
+ @user.append
50
+
51
+ User.count(@generated_id).must_equal 3
52
+ end
53
+ end
54
+
55
+ end
data/ssd.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ssd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ssd"
8
+ spec.version = SSD::VERSION
9
+ spec.authors = ["zotherstupidguy"]
10
+ spec.email = ["zotherstupidguy@gmail.com"]
11
+
12
+ spec.summary = %q{SSD is an append-only, file-based, immutable key-value store for Microservices written in Ruby.}
13
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/ssd-rb"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zotherstupidguy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - zotherstupidguy@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/encrypt.rb
72
+ - lib/ssd.rb
73
+ - lib/ssd/version.rb
74
+ - logo.png
75
+ - specs/spec_helper.rb
76
+ - specs/ssd_spec.rb
77
+ - ssd.gemspec
78
+ homepage: https://github.com/ssd-rb
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: SSD is an append-only, file-based, immutable key-value store for Microservices
102
+ written in Ruby.
103
+ test_files: []