daphne_util 0.0.1

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDc4OGFiNGE1OWQ3YjllMTgxMjU1NTFmMzY3YzBkZTdkYTJmYjFmNA==
5
+ data.tar.gz: !binary |-
6
+ MTU2N2NlNTcwOTQ3YjU4OTJjYmViYTIwNWMzY2JkYzkzZjkzNGJlOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTBkOTc4NGExZTJjOTIyODhlMDFkMjM1ZTBlZDhkNzZlODEzMzcyMDFmY2E1
10
+ YTNjMDg1Yjk1NjI2NWM2NjUzNjE0OGQ0ZjE5NTdjODEzZTMxMzg0YWRmNzQy
11
+ NGEwMmNjMTUyZTc4MWE2ZDVhYmEwNDU2OGYxYmI5N2Q1MzU4N2Y=
12
+ data.tar.gz: !binary |-
13
+ YWZlYjk3ZGYyY2QyODhiMGVhNjZjM2Y3OTVjNGE2MjZiMzliNWRjMjFjMzll
14
+ YmIxNzIzNTI0YTA5MWNkZjc1YjA0M2EzNmZmMmViZDU2YmNiOWIyYmVhZmRk
15
+ YzEzMDc1NWIzY2E5ZWViYjgxMWU5OGVjYjE2YzgyZTlkY2FkODQ=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in daphne_util.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 MTN Satellite Communications
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Grady Griffin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # DaphneUtil
2
+
3
+ A pseudorandom credential generator to create/distribute application credentials
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'daphne_util'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install daphne_util
18
+
19
+ ## CLI Usage
20
+
21
+ daphne_client_id arg1[,arg2[,argN]]
22
+
23
+ daphne_client_secret arg1[,arg2[,argN]]
24
+
25
+ ## Ruby App Usage
26
+
27
+
28
+ DaphneUtil::IdGenerator.generate(arg1[,arg2[,argN]])
29
+
30
+ DaphneUtil::SecretGenerator.generate(arg1[,arg2[,argN]])
31
+
32
+
33
+
34
+
35
+ ### CLI Example
36
+
37
+ $ daphne_client_id aname aplace athing
38
+ application-636b685a-70ef-032f-857c-9f422af7a6b2
39
+
40
+ $ daphne_client_secret aname aplace athing
41
+ 60934d2dd5069fd4f39550f90cde5b39e0337c91211eb9d8a01174563698fd32
42
+
43
+ ### Ruby Code Example
44
+
45
+ ```
46
+ #calling module methods
47
+
48
+ DaphneUtil.generate_id("aname","aplace","athing")
49
+ #application-636b685a-70ef-032f-857c-9f422af7a6b2
50
+
51
+ DaphneUtil.generate_secret("aname","aplace","athing")
52
+ #60934d2dd5069fd4f39550f90cde5b39e0337c91211eb9d8a01174563698fd32
53
+
54
+
55
+ #extending a class
56
+
57
+ class Foo
58
+ extend DaphneUtil
59
+ end
60
+
61
+ Foo.generate_id("aname","aplace","athing")
62
+ #application-636b685a-70ef-032f-857c-9f422af7a6b2
63
+
64
+ Foo.generate_secret("aname","aplace","athing")
65
+ #60934d2dd5069fd4f39550f90cde5b39e0337c91211eb9d8a01174563698fd32
66
+ ```
67
+
68
+
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
8
+
9
+
10
+ desc "Open an irb session preloaded with this library"
11
+ task :console do
12
+ sh "irb -rubygems -I lib -r daphne_util.rb"
13
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'daphne_util'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'daphne_util'
7
+ end
8
+
9
+ if ARGV.length == 0
10
+ puts "Please include at least one argument"
11
+ else
12
+ puts DaphneUtil::IdGenerator.generate(*ARGV)
13
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'daphne_util'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'daphne_util'
7
+ end
8
+
9
+ if ARGV.length == 0
10
+ puts "Please include at least one argument"
11
+ else
12
+ puts DaphneUtil::SecretGenerator.generate(*ARGV)
13
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'daphne_util/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "daphne_util"
8
+ spec.version = DaphneUtil::VERSION::STRING
9
+ spec.authors = ["Grady Griffin"]
10
+ spec.email = ["gradygriffin@gmail.com"]
11
+ spec.description = %q{Daphne pseudorandom credential generator}
12
+ spec.summary = %q{A pseudorandom credential generator to create and generate application credentials}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1 @@
1
+ class SaltUndefined < StandardError; end
@@ -0,0 +1,25 @@
1
+ module DaphneUtil
2
+ module IdGenerator
3
+
4
+ def self.generate(*seed)
5
+ seed_string = seed.compact.join("-")
6
+ hashes = (0..4).to_a.map {|x| Digest::MD5.hexdigest("client_id=#{seed_string}#{DaphneUtil.salt}#{x}")}
7
+
8
+ prefix = DaphneUtil.apps.include?(seed[0]) ? seed[0] : "application"
9
+
10
+ [
11
+ prefix,
12
+ hashes[0][4..11],
13
+ hashes[1][8..11],
14
+ hashes[2][12..15],
15
+ hashes[3][16..19],
16
+ hashes[4][20..31],
17
+ ].join("-")
18
+ end
19
+
20
+ def generate(seed)
21
+ DaphneUtil::IdGenerator.generate(seed)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module DaphneUtil
2
+ module SecretGenerator
3
+
4
+ def self.generate(*seed)
5
+ seed_string = seed.compact.join("-")
6
+ hashes = (0..1).to_a.map {|x| Digest::MD5.hexdigest("client_secret=#{seed_string}#{DaphneUtil.salt}#{x}")}
7
+ hashes.join
8
+ end
9
+
10
+ def generate(seed)
11
+ DaphneUtil::SecretGenerator.generate(seed)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module DaphneUtil
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+
2
+ require "digest"
3
+ require "daphne_util/version"
4
+ require "daphne_util/id_generator"
5
+ require "daphne_util/secret_generator"
6
+ require "daphne_util/errors"
7
+
8
+
9
+ module DaphneUtil
10
+
11
+ def self.salt
12
+ @salt ||= "Fuego! Fuego! Fuego!"
13
+ raise DaphneUtil::SaltUndefined unless @salt
14
+ Digest::SHA512.hexdigest(@salt.to_s)
15
+ end
16
+
17
+ def self.apps
18
+ ['seanet', 'poseidon', 'apollo']
19
+ end
20
+
21
+ def self.salt=(val)
22
+ @salt = val
23
+ end
24
+
25
+ def self.generate_id(*seed)
26
+ DaphneUtil::IdGenerator.generate(*seed)
27
+ end
28
+
29
+ def self.generate_secret(*seed)
30
+ DaphneUtil::SecretGenerator.generate(*seed)
31
+ end
32
+
33
+ def generate_id(*seed)
34
+ DaphneUtil::IdGenerator.generate(*seed)
35
+ end
36
+
37
+ def generate_secret(*seed)
38
+ DaphneUtil::SecretGenerator.generate(*seed)
39
+ end
40
+
41
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'DaphneUtil#generate_id' do
4
+
5
+ before(:each) do
6
+ DaphneUtil.salt = 'hello'
7
+ @seed = Digest::MD5.hexdigest(rand(9999).to_s)
8
+ end
9
+
10
+ it "should generate a id string" do
11
+ DaphneUtil.generate_id(@seed).should be_a(String)
12
+ end
13
+
14
+ it "should be consistent" do
15
+ DaphneUtil.generate_id(@seed).should eq(DaphneUtil.generate_id(@seed))
16
+ end
17
+
18
+ it "should have the correct structure" do
19
+ DaphneUtil.generate_id(@seed).should match /^application-[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/
20
+ end
21
+
22
+ it "should generate a secret string" do
23
+ DaphneUtil.generate_secret(@seed).should be_a(String)
24
+ end
25
+
26
+ it "should be consistent" do
27
+ DaphneUtil.generate_secret(@seed).should eq(DaphneUtil.generate_secret(@seed))
28
+ end
29
+
30
+ it "should have the correct structure" do
31
+ DaphneUtil.generate_secret(@seed).should match /^[\da-f]{64}$/
32
+ end
33
+
34
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'IdGenerator#generate' do
4
+
5
+ before(:each) do
6
+ DaphneUtil.salt = 'hello'
7
+ @seed = Digest::MD5.hexdigest(rand(9999).to_s)
8
+ end
9
+
10
+ it "should generate a id string" do
11
+ DaphneUtil::IdGenerator.generate(@seed).should be_a(String)
12
+ end
13
+
14
+ it "should be consistent" do
15
+ DaphneUtil::IdGenerator.generate(@seed).should eq(DaphneUtil::IdGenerator.generate(@seed))
16
+ end
17
+
18
+ it "should have the correct structure" do
19
+ DaphneUtil::IdGenerator.generate(@seed).should match /^application-[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'SecretGenerator#generate' do
4
+
5
+ before(:each) do
6
+ DaphneUtil.salt = 'hello'
7
+ @seed = Digest::MD5.hexdigest(rand(9999).to_s)
8
+ end
9
+
10
+ it "should generate a secret string" do
11
+ DaphneUtil::SecretGenerator.generate(@seed).should be_a(String)
12
+ end
13
+
14
+ it "should be consistent" do
15
+ DaphneUtil::SecretGenerator.generate(@seed).should eq(DaphneUtil::SecretGenerator.generate(@seed))
16
+ end
17
+
18
+ it "should have the correct structure" do
19
+ DaphneUtil::SecretGenerator.generate(@seed).should match /^[\da-f]{64}$/
20
+ end
21
+
22
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'daphne_util'
5
+
6
+ class Gimp; end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daphne_util
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Grady Griffin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-17 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Daphne pseudorandom credential generator
56
+ email:
57
+ - gradygriffin@gmail.com
58
+ executables:
59
+ - daphne_client_id
60
+ - daphne_client_secret
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/daphne_client_id
71
+ - bin/daphne_client_secret
72
+ - daphne_util.gemspec
73
+ - lib/daphne_util.rb
74
+ - lib/daphne_util/errors.rb
75
+ - lib/daphne_util/id_generator.rb
76
+ - lib/daphne_util/secret_generator.rb
77
+ - lib/daphne_util/version.rb
78
+ - spec/daphne_util_spec.rb
79
+ - spec/id_generator_spec.rb
80
+ - spec/secret_generator_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.6
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A pseudorandom credential generator to create and generate application credentials
106
+ test_files:
107
+ - spec/daphne_util_spec.rb
108
+ - spec/id_generator_spec.rb
109
+ - spec/secret_generator_spec.rb
110
+ - spec/spec_helper.rb