opensips-pi 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/lib/opensips-pi.rb +52 -0
- data/lib/opensips-pi/version.rb +5 -0
- data/opensips-pi.gemspec +22 -0
- data/spec/opensips_pi_spec.rb +158 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/shared_examples.rb +17 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGNkZWNmOTRlMzgxMmVmOTgwMGM4ZTM4MjMxNTI5ZmQ1MTFhY2JkMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MmI0M2U3M2FhNjhkNmM0YjBhYTQwMmJkOGJkNTU5MDJmOWE5MzVjOQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTc4YTJiOWZiMDJlNTA0YjY5ZjIwMzU0OGJhZDYxNjU3YTA2NmI3YTk4YzYz
|
10
|
+
ZTljYmE2NjMyZTkyZGYwOGVmYmRhZjAzNzg2ZGVlMzU3NTJjYjFkOWRmNDMx
|
11
|
+
MGUwNzEwZjI0OGU0MDljNjQ1YzVmZmMyYjUyZjYxOTUxYzI5Njg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTg4NmQ3MzZiYjMwMTc4YzI5M2FjNGYyMmIyMDNhYWNmNmEyNzQ3MmQzYTBh
|
14
|
+
MzE4Yjg2MzQxOWMzMjg1ZDI3OGNmZmQwNzNmYTk4OTE2N2FiZWYwM2U1NTU1
|
15
|
+
Y2RhZDIyNmU0NzlhMDUwNmU2Y2Q0MDc4ZmExMDljNjBmY2E0NWM=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Locaweb <development@locaweb.com.br>
|
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,55 @@
|
|
1
|
+
## Opensips::Pi
|
2
|
+
|
3
|
+
Opensips::Pi is an OpenSIPS Provisioning Interface for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'opensips-pi'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or manually install it:
|
16
|
+
|
17
|
+
$ gem install opensips-pi
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
By default, `opensipsctl` is used to run all commands. You can change this as the following:
|
22
|
+
|
23
|
+
Opensips::Pi.bin = "/usr/sbin/opensipsctl"
|
24
|
+
|
25
|
+
To log information, an instance of [Logger](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html) is used by default. You can also change this:
|
26
|
+
|
27
|
+
Opensips::Pi.logger = Rails.logger
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
To add a new user:
|
32
|
+
|
33
|
+
Opensips::Pi.add("username", "password")
|
34
|
+
|
35
|
+
To remove an user:
|
36
|
+
|
37
|
+
Opensips::Pi.remove("username")
|
38
|
+
|
39
|
+
To change user's password:
|
40
|
+
|
41
|
+
Opensips::Pi.password("username", "new_password")
|
42
|
+
|
43
|
+
More methods will be available soon. Feel free to fork this project and contribute with pull requests.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
This project is released under the MIT License. See LICENSE.txt for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/opensips-pi.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "opensips-pi/version"
|
2
|
+
require "open3"
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module Opensips
|
6
|
+
module Pi
|
7
|
+
@@logger = nil
|
8
|
+
@@bin = nil
|
9
|
+
|
10
|
+
def self.bin
|
11
|
+
@@bin || "opensipsctl"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.bin=(cmd)
|
15
|
+
@@bin = cmd
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.logger
|
19
|
+
@@logger ||= Logger.new(STDOUT)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.logger=(klass)
|
23
|
+
@@logger = klass
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.add(user, pass, domain=nil)
|
27
|
+
call("#{bin} add #{identifier(user,domain).shellescape} #{pass.shellescape}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.remove(user, domain=nil)
|
31
|
+
call("#{bin} rm #{identifier(user,domain).shellescape}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.password(user, pass, domain=nil)
|
35
|
+
call("#{bin} passwd #{identifier(user,domain).shellescape} #{pass.shellescape}")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def self.identifier(user, domain)
|
40
|
+
domain ? "#{user}@#{domain}" : user
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.call(cmd)
|
44
|
+
out, err, code = Open3.capture3(cmd)
|
45
|
+
|
46
|
+
logger.info("Opensips::Pi") { out }
|
47
|
+
logger.error("Opensips::Pi") { err }
|
48
|
+
|
49
|
+
[code.success?,out,err]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/opensips-pi.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opensips-pi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "opensips-pi"
|
8
|
+
gem.version = Opensips::Pi::VERSION
|
9
|
+
gem.authors = ["Lenon Marcel", "Alexandre Cardoso"]
|
10
|
+
gem.email = ["lenon.marcel@gmail.com", "accbel@gmail.com"]
|
11
|
+
gem.description = %q{OpenSIPS provisioning interface for Ruby.}
|
12
|
+
gem.summary = %q{Opensips::Pi is an OpenSIPS Provisioning Interface for Ruby.}
|
13
|
+
gem.homepage = "https://github.com/locaweb/opensips-pi"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.add_development_dependency "rspec", "~> 2.13.0"
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Opensips::Pi do
|
4
|
+
subject { Opensips::Pi }
|
5
|
+
|
6
|
+
let(:user) { "fulano" }
|
7
|
+
let(:domain) { "domain" }
|
8
|
+
let(:pass) { "senha" }
|
9
|
+
let(:bin) { "opensipsctl-bin" }
|
10
|
+
|
11
|
+
before do
|
12
|
+
subject.bin = nil
|
13
|
+
subject.logger = nil
|
14
|
+
Logger.any_instance.stub(:info => double, :error => double)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".bin" do
|
18
|
+
it "returns opensipsctl by default" do
|
19
|
+
subject.bin = nil
|
20
|
+
subject.bin.should be == "opensipsctl"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a custom command" do
|
24
|
+
subject.bin = "/usr/sbin/opensipsctl"
|
25
|
+
subject.bin.should be == "/usr/sbin/opensipsctl"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".logger" do
|
30
|
+
it "returns a new instance of Logger by default" do
|
31
|
+
subject.logger = nil
|
32
|
+
subject.logger.should be_kind_of Logger
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns a custom logger" do
|
36
|
+
dummy = Class.new
|
37
|
+
subject.logger = dummy
|
38
|
+
subject.logger.should be == dummy
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".add" do
|
43
|
+
before { subject.stub(:bin => bin) }
|
44
|
+
|
45
|
+
it "calls opensipsctl command with given username, domain and password" do
|
46
|
+
Open3.should_receive(:capture3).with("#{bin} add #{user}@#{domain} #{pass}").and_return(["foo", "bar", double(:"success?" => true)])
|
47
|
+
|
48
|
+
expect {
|
49
|
+
subject.add(user, pass, domain)
|
50
|
+
}.to_not raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
it "calls opensipsctl command with given username and password" do
|
54
|
+
Open3.should_receive(:capture3).with("#{bin} add #{user} #{pass}").and_return(["foo", "bar", double(:"success?" => true)])
|
55
|
+
|
56
|
+
expect {
|
57
|
+
subject.add(user, pass)
|
58
|
+
}.to_not raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns false when opensipsctl exit with 1" do
|
62
|
+
Open3.stub(:capture3 => ["foo", "bar", double(:"success?" => false)])
|
63
|
+
subject.add(user, pass).should == [false,"foo","bar"]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns true when opensipsctl exit with 0" do
|
67
|
+
Open3.stub(:capture3 => ["foo", "bar", double(:"success?" => true)])
|
68
|
+
subject.add(user, pass).should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "escape arguments when calling opensipsctl" do
|
72
|
+
user = "user with spaces"
|
73
|
+
Open3.should_receive(:capture3).with("#{bin} add user\\ with\\ spaces #{pass}").and_return(["","",double(:"success?" => true)])
|
74
|
+
|
75
|
+
subject.add(user, pass)
|
76
|
+
end
|
77
|
+
|
78
|
+
it_behaves_like "a method that log stdout and stderr messages", :add, "fulano", "senha"
|
79
|
+
end
|
80
|
+
|
81
|
+
describe ".remove" do
|
82
|
+
before { subject.stub(:bin => bin) }
|
83
|
+
|
84
|
+
it "calls opensipsctl command with given username and domain" do
|
85
|
+
Open3.should_receive(:capture3).with("#{bin} rm #{user}@#{domain}").and_return(["foo", "bar", double(:"success?" => true)])
|
86
|
+
|
87
|
+
expect {
|
88
|
+
subject.remove(user, domain)
|
89
|
+
}.to_not raise_error
|
90
|
+
end
|
91
|
+
|
92
|
+
it "calls opensipsctl command with given username" do
|
93
|
+
Open3.should_receive(:capture3).with("#{bin} rm #{user}").and_return(["foo", "bar", double(:"success?" => true)])
|
94
|
+
|
95
|
+
expect {
|
96
|
+
subject.remove(user)
|
97
|
+
}.to_not raise_error
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns false when opensipsctl exit with 1" do
|
101
|
+
Open3.stub(:capture3 => ["foo", "bar", double(:"success?" => false)])
|
102
|
+
subject.remove(user).should == [false,"foo","bar"]
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns true when opensipsctl exit with 0" do
|
106
|
+
Open3.stub(:capture3 => ["foo", "bar", double(:"success?" => true)])
|
107
|
+
subject.remove(user).should be_true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "escape arguments when calling opensipsctl" do
|
111
|
+
user = "user with spaces"
|
112
|
+
Open3.should_receive(:capture3).with("#{bin} rm user\\ with\\ spaces").and_return(["","",double(:"success?" => true)])
|
113
|
+
|
114
|
+
subject.remove(user)
|
115
|
+
end
|
116
|
+
|
117
|
+
it_behaves_like "a method that log stdout and stderr messages", :remove, "fulano"
|
118
|
+
end
|
119
|
+
|
120
|
+
describe ".password" do
|
121
|
+
before { subject.stub(:bin => bin) }
|
122
|
+
|
123
|
+
it "calls opensipsctl command with given username, password and domain" do
|
124
|
+
Open3.should_receive(:capture3).with("#{bin} passwd #{user}@#{domain} #{pass}").and_return(["foo", "bar", double(:"success?" => true)])
|
125
|
+
|
126
|
+
expect {
|
127
|
+
subject.password(user, pass, domain)
|
128
|
+
}.to_not raise_error
|
129
|
+
end
|
130
|
+
|
131
|
+
it "calls opensipsctl command with username and password" do
|
132
|
+
Open3.should_receive(:capture3).with("#{bin} passwd #{user} #{pass}").and_return(["foo", "bar", double(:"success?" => true)])
|
133
|
+
|
134
|
+
expect {
|
135
|
+
subject.password(user, pass)
|
136
|
+
}.to_not raise_error
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns false when opensipsctl exit with 1" do
|
140
|
+
Open3.stub(:capture3 => ["foo", "bar", double(:"success?" => false)])
|
141
|
+
subject.password(user, pass).should == [false,"foo","bar"]
|
142
|
+
end
|
143
|
+
|
144
|
+
it "returns true when opensipsctl exit with 0" do
|
145
|
+
Open3.stub(:capture3 => ["foo", "bar", double(:"success?" => true)])
|
146
|
+
subject.password(user, pass).should be_true
|
147
|
+
end
|
148
|
+
|
149
|
+
it "escape arguments when calling opensipsctl" do
|
150
|
+
user = "user with spaces"
|
151
|
+
Open3.should_receive(:capture3).with("#{bin} passwd user\\ with\\ spaces #{pass}").and_return(["","",double(:"success?" => true)])
|
152
|
+
|
153
|
+
subject.password(user, pass)
|
154
|
+
end
|
155
|
+
|
156
|
+
it_behaves_like "a method that log stdout and stderr messages", :password, "fulano", "senha"
|
157
|
+
end
|
158
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'opensips-pi'
|
4
|
+
|
5
|
+
Dir["spec/support/**/*.rb"].each { |f| load(f) }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
config.order = 'random'
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
shared_examples "a method that log stdout and stderr messages" do |method, *args|
|
2
|
+
it "log stdout and stderr messages" do
|
3
|
+
Open3.stub(:capture3 => ["standard output", "standard error", double(:"success?" => false)])
|
4
|
+
|
5
|
+
subject.logger.should_receive(:info) { |prog, &block|
|
6
|
+
prog.should be == "Opensips::Pi"
|
7
|
+
block.call.should be == "standard output"
|
8
|
+
}
|
9
|
+
|
10
|
+
subject.logger.should_receive(:error) { |prog, &block|
|
11
|
+
prog.should be == "Opensips::Pi"
|
12
|
+
block.call.should be == "standard error"
|
13
|
+
}
|
14
|
+
|
15
|
+
subject.send(method, *args)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opensips-pi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lenon Marcel
|
8
|
+
- Alexandre Cardoso
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.13.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.13.0
|
28
|
+
description: OpenSIPS provisioning interface for Ruby.
|
29
|
+
email:
|
30
|
+
- lenon.marcel@gmail.com
|
31
|
+
- accbel@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- .rspec
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/opensips-pi.rb
|
43
|
+
- lib/opensips-pi/version.rb
|
44
|
+
- opensips-pi.gemspec
|
45
|
+
- spec/opensips_pi_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
- spec/support/shared_examples.rb
|
48
|
+
homepage: https://github.com/locaweb/opensips-pi
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.0.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Opensips::Pi is an OpenSIPS Provisioning Interface for Ruby.
|
72
|
+
test_files:
|
73
|
+
- spec/opensips_pi_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/support/shared_examples.rb
|