super_source 0.10.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: 3b880333fe00fd0d5ac0ae9abb6b2027312125df
4
+ data.tar.gz: ed977cc0238201b69356f46657df6067e367f3d4
5
+ SHA512:
6
+ metadata.gz: 97d87f486bf375fca1d39ccae2dcd2e1fdc93046be874f8f0939766499006ffe9eef90047bc26593d4982ea6f02d63d41d18e30d7da0ff24b5da7d6f8654e86e
7
+ data.tar.gz: 54e59882ee0656a00374121cb6b09b3fc8fa7d44aeedf371e01c867f3fc94e4b01e04684e05ae8ebfd181ae3d225895e8edba80855b4a1060668cf8478fe1ae4
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ log
11
+ .DS_Store
12
+ *.lock
13
+ .idea
14
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/DEV_README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Helpful things to remember when developing
2
+
3
+ ## Publishing to Rubygems
4
+
5
+ Ensure the version number is updated (lib/super_source/version.rb.
6
+
7
+ rspec
8
+
9
+ gem build super_source.gemspec
10
+
11
+ Make sure your ~/.gem credentials are the correct one
12
+
13
+ gem push super_source-VERSION.gem
14
+
15
+ ## Requiring the local version of the Gem
16
+
17
+ Use something like this:
18
+
19
+ gem 'super_source', '0.9.6', path: 'local/path/to/gem'
20
+
21
+
22
+ ## Philosophy
23
+
24
+ Super Source is split into two types of packages: the supso command line interface,
25
+ and packages included with the projects that use Super Source.
26
+
27
+ This gem, the Super Source Ruby gem, is an example of the latter.
28
+
29
+ These packages should:
30
+
31
+ 1. Do the bare minimum necessary to validate a project. They should throw a human-friendly error
32
+ in case the project is not valid.
33
+
34
+ 2. Include the least possible amount of third party libraries, ideally 0.
35
+
36
+ 3. As much as possible, they should be read-only.
37
+
38
+ Everything else should be done by the supso command line interface. For example, updating the client tokens should be
39
+ done in the supso library.
40
+
41
+ The supso command line interface should never be directly added as a requirement from the projects.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Jeff Pickhardt
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Super Source
2
+
3
+ ## Installation
4
+
5
+ ##### Instructions for using Super Source
6
+
7
+ Create a new, empty directory. Inside this directory, create a file named Gemfile, and add the following to it:
8
+
9
+ ```ruby
10
+ source 'https://rubygems.org'
11
+
12
+ gem 'super_source'
13
+ ```
14
+
15
+ Then execute:
16
+
17
+ $ bundle install
18
+
19
+ ## Documentation
20
+
21
+ Visit the [docs page](http://supersource.org/docs/overview/welcome) to read the documentation.
22
+
23
+ ## Contributing
24
+
25
+ To contribute, get in touch at http://supersource.org/ so that we can share the [Contributor License Agreement (CLA)](https://en.wikipedia.org/wiki/Contributor_License_Agreement) with you, then create a pull request.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "super_source"
5
+
6
+ require "irb"
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ module ModuleVars
2
+ def define_class_method(name, &block)
3
+ (class << self; self; end).instance_eval do
4
+ define_method(name, &block)
5
+ end
6
+ end
7
+
8
+ def create_module_var(name, val = nil)
9
+ class_variable_set("@@#{ name }", val)
10
+
11
+ define_class_method(name) do
12
+ class_variable_get("@@#{ name }")
13
+ end
14
+
15
+ define_class_method("#{name}=") do |set_to|
16
+ class_variable_set("@@#{ name }", set_to)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxa97nwFuinf275M/uCFL
3
+ MXDhR46lm3oCvEFMAPdqLJ4570DeJZK5MrsSeVaOtiMeW8eNAaLxNocL88QXojGm
4
+ Bm5jMWJeMwcs1iZTz+w+UwL4njhfE6fF81LeKJf0iq6gFsJE328RuFqj2fayn8sv
5
+ H5YTsPQhsm/dF2XkjWfQ2dSIHhjwBi0JUNgvZQDLmH6MbdQDenzMD2Z/MG+CMxyc
6
+ VqKOy+qaqx+eHdfgFk9zoU22cb2XifOSZzph/mGJim7g5N4LQb0zoeykGVvlZuKj
7
+ YiVCyjvHErM+iWqi7k2ZhlKacprI5Zm9tbZs+lFfmn8c1Ks11zUxeDPhkdUL/v38
8
+ YwIDAQAB
9
+ -----END PUBLIC KEY-----
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each do |file|
6
+ require file
7
+ end
8
+
9
+ Dir[File.dirname(__FILE__) + '/super_source/*.rb'].each do |file|
10
+ require file
11
+ end
12
+
13
+ module SuperSource
14
+ extend ModuleVars
15
+
16
+ env = ENV['ENV'] || "development"
17
+ create_module_var("environment", env)
18
+
19
+ spec = Gem::Specification.find_by_name("super_source")
20
+
21
+ create_module_var("gem_root", spec.gem_dir)
22
+ create_module_var("project_root", Util.detect_project_root)
23
+ create_module_var("project_supso_config_root", SuperSource.project_root ? SuperSource.project_root + '/.supso' : nil)
24
+ create_module_var("user_supso_config_root", "#{ Dir.home }/.supso")
25
+ FileUtils.mkdir_p(SuperSource.user_supso_config_root)
26
+
27
+ create_module_var("config", {})
28
+
29
+ SuperSource::Config.load_config!
30
+ end
@@ -0,0 +1,16 @@
1
+ module SuperSource
2
+ class Config
3
+ def self.load_config!
4
+ if !SuperSource.project_supso_config_root
5
+ return
6
+ end
7
+
8
+ configs_to_load = ["/config.json"]
9
+ configs_to_load.each do |relative_path|
10
+ config_path = SuperSource.project_supso_config_root + relative_path
11
+ loaded_config = File.exist?(config_path) ? JSON.parse(File.read(config_path)) : {}
12
+ SuperSource.config = Util.deep_merge(SuperSource.config, loaded_config)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module SuperSource
2
+ class InvalidProjectToken < StandardError; end
3
+ class MissingProjectToken < StandardError; end
4
+ class MissingProjectRoot < StandardError; end
5
+
6
+ module Exceptions
7
+ def Exceptions.help_message
8
+ "\n\n * " + ["To get client tokens, run `supso update`.",
9
+ "If you do not have the supso command line interface yet, first run `gem install supso`.",
10
+ "Visit http://supso.org/help for further help.",
11
+ ].join("\n\n * ") + "\n\n"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module SuperSource
4
+ class Organization
5
+ attr_accessor :name, :id
6
+
7
+ @@current_organization = nil
8
+
9
+ def initialize(name, id)
10
+ @name = name
11
+ @id = id
12
+ end
13
+
14
+ def self.current_organization_filename
15
+ "#{ SuperSource.project_supso_config_root }/current_organization.json"
16
+ end
17
+
18
+ def self.current_organization_from_file
19
+ organization_data = {}
20
+ begin
21
+ organization_data = JSON.parse(File.read(Organization.current_organization_filename))
22
+ organization_data = {} if !organization_data.is_a?(Object)
23
+ rescue
24
+ organization_data = {}
25
+ end
26
+
27
+ if organization_data['id']
28
+ Organization.new(organization_data['name'], organization_data['id'])
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ def self.current_organization
35
+ @@current_organization ||= Organization.current_organization_from_file
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,113 @@
1
+ require 'json'
2
+ require 'openssl'
3
+ require 'base64'
4
+
5
+ module SuperSource
6
+ class Project
7
+ attr_accessor :name, :api_token, :client_data, :client_token
8
+
9
+ def initialize(name, api_token, options = {})
10
+ @name = name
11
+ @api_token = api_token
12
+ @options = options
13
+ @options[:level] ||= :warn
14
+ @client_data = self.load_client_data
15
+ @client_token = self.load_client_token
16
+ end
17
+
18
+ def ensure_required!
19
+ if SuperSource.project_root.nil?
20
+ self.report_problem!("Could not detect a Supported Source project root in working directory or any parent " +
21
+ "directories. Are you sure you're running this from the right place?",
22
+ MissingProjectRoot)
23
+ return
24
+ end
25
+
26
+ if !self.token_file_exists?
27
+ self.report_problem!("Missing Supported Source token for " +
28
+ "project: #{ name }.#{ Exceptions.help_message }", MissingProjectToken)
29
+ return
30
+ end
31
+
32
+ if !self.valid?
33
+ self.report_problem!("Invalid Supported Source token for project: #{ name }.#{ Exceptions.help_message }",
34
+ InvalidProjectToken)
35
+ return
36
+ end
37
+ end
38
+
39
+ def report_problem!(message, error_class)
40
+ if @options[:level] == :warn
41
+ warn("WARNING: " + message)
42
+ elsif @options[:level] == :error
43
+ raise error_class.new(message)
44
+ end
45
+ end
46
+
47
+ def filename(filetype)
48
+ "#{ SuperSource.project_supso_config_root }/projects/#{ self.name }.#{ filetype }"
49
+ end
50
+
51
+ def data_filename
52
+ self.filename('json')
53
+ end
54
+
55
+ def load_client_data
56
+ if File.exist?(self.data_filename)
57
+ JSON.parse(File.read(self.data_filename))
58
+ else
59
+ {}
60
+ end
61
+ end
62
+
63
+ def load_client_token
64
+ if self.token_file_exists?
65
+ File.read(self.token_filename)
66
+ else
67
+ nil
68
+ end
69
+ end
70
+
71
+ def token_filename
72
+ self.filename('token')
73
+ end
74
+
75
+ def token_file_exists?
76
+ File.exist?(self.token_filename)
77
+ end
78
+
79
+ def valid?
80
+ if !self.client_token || !self.client_data
81
+ return false
82
+ end
83
+
84
+ if self.client_data['project_api_token'] != self.api_token
85
+ return false
86
+ end
87
+
88
+ if !Organization.current_organization ||
89
+ self.client_data['organization_id'] != Organization.current_organization.id
90
+ return false
91
+ end
92
+
93
+ public_key = OpenSSL::PKey::RSA.new File.read("#{ SuperSource.gem_root }/lib/other/supso2.pub")
94
+ digest = OpenSSL::Digest::SHA256.new
95
+
96
+ public_key.verify(digest, Base64.decode64(self.client_token), self.client_data.to_json)
97
+ end
98
+
99
+ class << self
100
+ attr_accessor :projects
101
+ end
102
+
103
+ def self.projects
104
+ @projects ||= []
105
+ end
106
+
107
+ def self.add(name, api_token, options = {})
108
+ project = Project.new(name, api_token, options)
109
+ self.projects << project
110
+ project.ensure_required!
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+
3
+ module SuperSource
4
+ class User
5
+ attr_accessor :email, :name, :id, :auth_token
6
+
7
+ @@current_user = nil
8
+
9
+ def initialize(email, name, id, auth_token = nil)
10
+ @email = email
11
+ @name = name
12
+ @id = id
13
+ @auth_token = auth_token
14
+ end
15
+
16
+ def self.current_user_filename
17
+ "#{ SuperSource.user_supso_config_root }/current_user.json"
18
+ end
19
+
20
+ def self.current_user_from_file
21
+ if !File.exist?(User.current_user_filename)
22
+ return nil
23
+ end
24
+
25
+ user_data = {}
26
+ begin
27
+ user_data = JSON.parse(File.read(User.current_user_filename))
28
+ user_data = {} if !user_data.is_a?(Object)
29
+ rescue JSON::ParserError => err
30
+ user_data = {}
31
+ end
32
+
33
+ if user_data['email'] || user_data['auth_token']
34
+ User.new(user_data['email'], user_data['name'], user_data['id'], user_data['auth_token'])
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ def self.current_user
41
+ @@current_user ||= User.current_user_from_file
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,61 @@
1
+ require 'bundler'
2
+ require 'json'
3
+
4
+ module SuperSource
5
+ module Util
6
+ def Util.deep_merge(first, second)
7
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
8
+ first.merge(second, &merger)
9
+ end
10
+
11
+ def Util.detect_project_root
12
+ project_root = Dir.getwd
13
+ while true
14
+ if project_root == ""
15
+ project_root = nil
16
+ break
17
+ end
18
+
19
+ if File.exist?(project_root + '/Gemfile') ||
20
+ File.exist?(project_root + '/package.json') ||
21
+ File.exist?(project_root + '.supso')
22
+ break
23
+ end
24
+
25
+ detect_project_root_splits = project_root.split("/")
26
+ detect_project_root_splits = detect_project_root_splits[0..detect_project_root_splits.length - 2]
27
+ project_root = detect_project_root_splits.join("/")
28
+ end
29
+
30
+ project_root
31
+ end
32
+
33
+ def Util.pluralize(count, word)
34
+ if count == 1
35
+ word
36
+ else
37
+ "#{ word }s"
38
+ end
39
+ end
40
+
41
+ def Util.require_all_gems!
42
+ begin
43
+ Bundler.require(:default, :development, :test, :production)
44
+ rescue Gem::LoadError, Bundler::GemfileNotFound
45
+ # Keep going
46
+ end
47
+ end
48
+
49
+ def Util.underscore_to_camelcase(str)
50
+ str.split('_').map{ |chunk| chunk.capitalize }.join
51
+ end
52
+
53
+ def Util.camelcase_to_underscore(str)
54
+ str.gsub(/::/, '/')
55
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
56
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
57
+ .tr("-", "_")
58
+ .downcase
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ module SuperSource
2
+ if !defined?(SuperSource::VERSION)
3
+ VERSION_MAJOR = 0
4
+ VERSION_MINOR = 10
5
+ VERSION_PATCH = 0
6
+ VERSION = [VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH].join('.')
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'super_source/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.authors = ["Super Source"]
8
+ spec.description = "Learn who's using your project with Super Source."
9
+ spec.email = ["admin@supso.org"]
10
+ spec.homepage = "http://supso.org/"
11
+ spec.name = "super_source"
12
+ spec.summary = "See who's using your project with Super Source."
13
+ spec.version = SuperSource::VERSION
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.match(%r{supported_source}) }
16
+ spec.bindir = "bin"
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec", "~> 3.3"
22
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: super_source
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ platform: ruby
6
+ authors:
7
+ - Super Source
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-27 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ description: Learn who's using your project with Super Source.
56
+ email:
57
+ - admin@supso.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - DEV_README.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/helpers/module_vars.rb
72
+ - lib/other/supso2.pub
73
+ - lib/super_source.rb
74
+ - lib/super_source/config.rb
75
+ - lib/super_source/exceptions.rb
76
+ - lib/super_source/organization.rb
77
+ - lib/super_source/project.rb
78
+ - lib/super_source/user.rb
79
+ - lib/super_source/util.rb
80
+ - lib/super_source/version.rb
81
+ - super_source.gemspec
82
+ homepage: http://supso.org/
83
+ licenses: []
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.8
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: See who's using your project with Super Source.
105
+ test_files: []