occson-rails 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
+ SHA256:
3
+ metadata.gz: 10d7cd7b65f63588fe7f4d733196330e9cfc9f0e99094c27e1c3f2b45022233e
4
+ data.tar.gz: d60d04467dafac510dda72dc051e233567825dd086ffff145a9e7f7fcc275956
5
+ SHA512:
6
+ metadata.gz: a36e6440bffda7e384b89c5d83b805ebe00774c978e04231791d56b52e98173f75f786e7cd36470fe9e882a66dfbeaa271488e89b0daaa4395ab92a33cc390f2
7
+ data.tar.gz: dd76f5e62e3bffaf890925490a597a6b7ca45a4436a8537725e7d114d72e712d2408eb08fbfdbe372441f15b0af388a0267c5449b74c28073cc78cb30ce30ad7
data/CHANGELOG.md ADDED
File without changes
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Tomasz Kowalewski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # OCCSON
2
+
3
+ Store, manage and deploy Rails configuration securely with Occson.
4
+
5
+ ## Installation
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'occson-rails'
10
+ ```
11
+
12
+ And then execute:
13
+ ```bash
14
+ $ bundle
15
+ ```
16
+
17
+ ## Usage
18
+ Use occson rails engine in two simple steps:
19
+
20
+ 1. Define application version in `config/application.rb`
21
+
22
+ ```ruby
23
+ module Dummy
24
+ VERSION = "0.1.0"
25
+
26
+ class Application < Rails::Application
27
+ end
28
+ end
29
+ ```
30
+
31
+ 2. Create `.env` file with occson related environment variables
32
+
33
+ ```
34
+ OCCSON_ACCESS_TOKEN=[ACCESS_TOKEN]
35
+ OCCSON_PASSPHRASE=[PASSPHRASE]
36
+ ```
37
+
38
+ You can create `.env` file by environment eg.:
39
+
40
+ ```
41
+ .env
42
+ .env.development
43
+ .env.development.local
44
+ ```
45
+
46
+ ## License
47
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
9
+
10
+ require "rake/testtask"
11
+
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = false
16
+ end
17
+
18
+ task default: :test
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/occson/rails .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,6 @@
1
+ module Occson
2
+ module Rails
3
+ class ApplicationController < ActionController::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Occson
2
+ module Rails
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Occson
2
+ module Rails
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Occson
2
+ module Rails
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Occson
2
+ module Rails
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Occson rails</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "occson/rails/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Occson::Rails::Engine.routes.draw do
2
+ end
@@ -0,0 +1,27 @@
1
+ module Occson
2
+ module Rails
3
+ class ApplicationVersion
4
+ UndefinedApplicationVersionError = Class.new(StandardError)
5
+
6
+ def initialize(application)
7
+ @application = application
8
+ end
9
+
10
+ def call
11
+ raise UndefinedApplicationVersionError, "Uninitialized constant #{const}" unless Object.const_defined?(const)
12
+
13
+ Object.const_get(const)
14
+ end
15
+
16
+ private
17
+
18
+ def const
19
+ @_const ||= class_name.sub('Application', 'VERSION')
20
+ end
21
+
22
+ def class_name
23
+ @application.class.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ require 'occson'
2
+
3
+ require_relative 'application_version'
4
+ require_relative 'environment_parser'
5
+ require_relative 'environment_storer'
6
+ require_relative 'environment_loader'
7
+
8
+ module Occson
9
+ module Rails
10
+ class Engine < ::Rails::Engine
11
+ isolate_namespace Occson::Rails
12
+
13
+ config.before_configuration do
14
+ EnvironmentLoader.new(::Rails.root, ::Rails.env).call
15
+
16
+ unless ENV.key?('OCCSON_ACCESS_TOKEN') && ENV.key?('OCCSON_PASSPHRASE')
17
+ puts "Please setup OCCSON_ACCESS_TOKEN and OCCSON_PASSPHRASE."
18
+
19
+ next
20
+ end
21
+
22
+ version = ApplicationVersion.new(::Rails.application).call
23
+ uri = "occson://#{version}/.env"
24
+ access_token = ENV.fetch('OCCSON_ACCESS_TOKEN')
25
+ passphrase = ENV.fetch('OCCSON_PASSPHRASE')
26
+
27
+ document = Occson::Document.new(uri, access_token, passphrase).download
28
+
29
+ if document.blank?
30
+ puts "Occson cannot download document."
31
+
32
+ next
33
+ end
34
+
35
+ EnvironmentStorer.new(EnvironmentParser.new(document).call).call
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ module Occson
2
+ module Rails
3
+ class EnvironmentLoader
4
+ def initialize(root, environment)
5
+ @root = root
6
+ @environment = environment
7
+ end
8
+
9
+ def call
10
+ files.each do |file|
11
+ next unless File.exist?(file)
12
+
13
+ EnvironmentStorer.new(EnvironmentParser.new(File.read(file)).call).call
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def files
20
+ [
21
+ @root.join(".env"),
22
+ @root.join(".env.#{@environment}"),
23
+ @root.join(".env.#{@environment}.local")
24
+ ]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module Occson
2
+ module Rails
3
+ class EnvironmentParser
4
+ def initialize(content)
5
+ @content = content
6
+ end
7
+
8
+ def call
9
+ Hash[parse]
10
+ end
11
+
12
+ private
13
+
14
+ def parse
15
+ @content.split("\n").map do |line|
16
+ next if line.start_with?('#')
17
+
18
+ line.split("=", 2) # @TODO handle wrapped values
19
+ end.compact
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Occson
2
+ module Rails
3
+ class EnvironmentStorer
4
+ def initialize(environment)
5
+ @environment = environment
6
+ end
7
+
8
+ def call
9
+ @environment.each do |key, value|
10
+ ENV.store(key, value)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Occson
2
+ module Rails
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "occson/rails/version"
2
+ require "occson/rails/engine"
3
+
4
+ module Occson
5
+ module Rails
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :occson_rails do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: occson-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Kowalewski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
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: occson
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ description: ''
42
+ email:
43
+ - me@tkowalewski.pl
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - app/assets/config/occson_rails_manifest.js
53
+ - app/assets/stylesheets/occson/rails/application.css
54
+ - app/controllers/occson/rails/application_controller.rb
55
+ - app/helpers/occson/rails/application_helper.rb
56
+ - app/jobs/occson/rails/application_job.rb
57
+ - app/mailers/occson/rails/application_mailer.rb
58
+ - app/models/occson/rails/application_record.rb
59
+ - app/views/layouts/occson/rails/application.html.erb
60
+ - config/routes.rb
61
+ - lib/occson/rails.rb
62
+ - lib/occson/rails/application_version.rb
63
+ - lib/occson/rails/engine.rb
64
+ - lib/occson/rails/environment_loader.rb
65
+ - lib/occson/rails/environment_parser.rb
66
+ - lib/occson/rails/environment_storer.rb
67
+ - lib/occson/rails/version.rb
68
+ - lib/tasks/occson/rails_tasks.rake
69
+ homepage: https://github.com/occson/occson-rails
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/occson/occson-rails
74
+ source_code_uri: https://github.com/occson/occson-rails
75
+ changelog_uri: https://github.com/occson/occson-rails/blob/master/CHANGELOG.md
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.1.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Store, manage and deploy configuration securely with Occson.
95
+ test_files: []