codesake_commons 0.50.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.sw?
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@codesake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codesake_commons.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Paolo Perego
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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Paolo Perego
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,29 @@
1
+ # CodesakeCommons
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'codesake_commons'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install codesake_commons
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codesake_commons/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "codesake_commons"
8
+ gem.version = Codesake::Commons::VERSION
9
+ gem.authors = ["Paolo Perego"]
10
+ gem.email = ["thesp0nge@gmail.com"]
11
+ gem.description = %q{codesake.com is an application security startup providing code review and penetration test services for Ruby powered web applications. codesake_commons is the gem containing common ground routines useful across the project}
12
+ gem.summary = %q{codesake_commons is the gem containing common ground routines useful across the codesake.com project}
13
+ gem.homepage = "http://codesake.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'rainbow'
21
+ end
@@ -0,0 +1,22 @@
1
+ module Codesake
2
+ module Commons
3
+ class Io
4
+ def self.remove_pid_file(pid_file)
5
+ File.delete(pid_file) if File.exists?(pid_file)
6
+ end
7
+
8
+ def self.create_pid_file(pid_file)
9
+ f = File.new(pid_file, "w")
10
+ f.write("#{Process.pid}")
11
+ f.close
12
+ end
13
+
14
+ def self.read_pid_file(pid_file)
15
+ f = File.new(pid_file, "r")
16
+ pid=f.read
17
+ f.close
18
+ pid
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,84 @@
1
+ require 'rainbow'
2
+ require 'syslog'
3
+ require 'singleton'
4
+
5
+ module Codesake
6
+ module Commons
7
+ class Logging
8
+ include Singleton
9
+
10
+ attr_reader :silencer
11
+ attr_reader :verbose
12
+ attr_reader :syslog
13
+
14
+ def initialize
15
+ super
16
+ @silencer = false
17
+ @verbose = true
18
+ @syslog = true
19
+ end
20
+
21
+ def die(msg, pid_file=nil)
22
+ printf "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:red)
23
+ send_to_syslog(msg, :helo)
24
+ Codesake::Commons::Io.remove_pid_file(pid_file) unless pid_file.nil?
25
+ Kernel.exit(-1)
26
+ end
27
+
28
+ def err(msg)
29
+ printf "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:red)
30
+ send_to_syslog(msg, :err)
31
+ end
32
+
33
+ def warn(msg)
34
+ printf "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:yellow)
35
+ send_to_syslog(msg, :warn)
36
+ end
37
+
38
+ def ok(msg)
39
+ printf "#{Time.now.strftime("%H:%M:%S")} [*] #{msg}\n".color(:green)
40
+ send_to_syslog(msg, :log)
41
+ end
42
+
43
+ def log(msg)
44
+ return if @silencer
45
+ printf "#{Time.now.strftime("%H:%M:%S")}: #{msg}\n".color(:white)
46
+ send_to_syslog(msg, :debug)
47
+ end
48
+
49
+ def helo(msg, pid_file = nil)
50
+ printf "[*] #{msg} at #{Time.now.strftime("%H:%M:%S")}\n".color(:white)
51
+ send_to_syslog(msg, :helo)
52
+ create_pid_file(pid_file) unless pid_file.nil?
53
+ end
54
+
55
+ def toggle_silence
56
+ @silencer = ! @silencer
57
+ @verbose = ! @silencer
58
+ warn("silenced. Logs are disabled") if @silencer
59
+ end
60
+
61
+ def toggle_syslog
62
+ @syslog = ! @syslog
63
+ warn("codesake messages to syslog are now disabled") unless @syslog
64
+ ok("codesake messages to syslog are now enabled") if @syslog
65
+ end
66
+
67
+ private
68
+ def send_to_syslog(msg, level)
69
+ return false unless @syslog
70
+
71
+ log = Syslog.open("codesake")
72
+ log.debug(msg) if level == :debug
73
+ log.warn(msg) if level == :warn
74
+ log.info(msg) if level == :helo
75
+ log.notice(msg) if level == :log
76
+ log.err(msg) if level == :error
77
+
78
+ true
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,5 @@
1
+ module Codesake
2
+ module Commons
3
+ VERSION = "0.50.0"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "codesake_commons/version"
2
+ require "codesake_commons/logging"
3
+ require "codesake_commons/io"
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CodesakeCommons" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "The Codesake::Commons::Logging package will" do
4
+ it "handle a silencer flag turning on/off logs"
5
+ it "disable logs when silenced"
6
+
7
+
8
+ end
9
+
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'codesake_commons'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codesake_commons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.50.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paolo Perego
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rainbow
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: codesake.com is an application security startup providing code review
31
+ and penetration test services for Ruby powered web applications. codesake_commons
32
+ is the gem containing common ground routines useful across the project
33
+ email:
34
+ - thesp0nge@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .document
40
+ - .gitignore
41
+ - .rspec
42
+ - .rvmrc
43
+ - Gemfile
44
+ - LICENSE
45
+ - LICENSE.txt
46
+ - README.md
47
+ - Rakefile
48
+ - codesake_commons.gemspec
49
+ - lib/codesake_commons.rb
50
+ - lib/codesake_commons/io.rb
51
+ - lib/codesake_commons/logging.rb
52
+ - lib/codesake_commons/version.rb
53
+ - spec/codesake_commons_spec.rb
54
+ - spec/logging_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: http://codesake.com
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.24
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: codesake_commons is the gem containing common ground routines useful across
80
+ the codesake.com project
81
+ test_files:
82
+ - spec/codesake_commons_spec.rb
83
+ - spec/logging_spec.rb
84
+ - spec/spec_helper.rb