dozenscli 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/bin/dozens +5 -0
- data/dozenscli.gemspec +25 -0
- data/lib/dozenscli.rb +3 -0
- data/lib/dozenscli/api.rb +107 -0
- data/lib/dozenscli/command.rb +87 -0
- data/lib/dozenscli/version.rb +3 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 h-tane
|
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,51 @@
|
|
1
|
+
# dozens-cli
|
2
|
+
|
3
|
+
Command Line Interface for Dozens.
|
4
|
+
|
5
|
+
This package provides a command line interface to Dozens REST API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'dozenscli'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dozenscli
|
20
|
+
|
21
|
+
## Getting Started
|
22
|
+
|
23
|
+
Before using dozens-cli, you need to tell it about your credentials.
|
24
|
+
|
25
|
+
Create a configuration file like this:
|
26
|
+
|
27
|
+
[profile]
|
28
|
+
dozens_id = <dozens_id>
|
29
|
+
api_key = <api_key>
|
30
|
+
|
31
|
+
and place it in ~/.dozenscli.conf
|
32
|
+
|
33
|
+
## Synopsis
|
34
|
+
|
35
|
+
$ dozens <command> <subcommand> [parameters]
|
36
|
+
|
37
|
+
Use command help for information on a specific command.
|
38
|
+
|
39
|
+
$ dozens help
|
40
|
+
|
41
|
+
Commands:
|
42
|
+
dozens create TYPE # Create resource. Type can be zone, record
|
43
|
+
dozens delete TYPE # Delete resource. Type can be zone, record
|
44
|
+
dozens help [COMMAND] # Describe available commands or one specific command
|
45
|
+
dozens list TYPE # List resource. Type can be zone, record
|
46
|
+
dozens update TYPE # Update resource. Type can be record
|
47
|
+
|
48
|
+
Operation of a record requires JSON data structures as input parameters on the command line.
|
49
|
+
|
50
|
+
// Example
|
51
|
+
$ dozens create record --params '{"domain":"dozens.jp","name":"www","type":"A","prio":10,"content":"192.168.0.1","ttl":"7200"}'
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/dozens
ADDED
data/dozenscli.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dozenscli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dozenscli"
|
8
|
+
spec.version = Dozenscli::VERSION
|
9
|
+
spec.authors = ["h-tane"]
|
10
|
+
spec.email = ["h-tane@nekojarashi.com"]
|
11
|
+
spec.summary = %q{Command Line Interface for Dozens.}
|
12
|
+
spec.description = %q{This package provides a command line interface to Dozens REST API.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "thor", "~> 0.18"
|
24
|
+
spec.add_dependency "inifile", "~> 2.0.2"
|
25
|
+
end
|
data/lib/dozenscli.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'inifile'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Dozenscli
|
6
|
+
class API
|
7
|
+
def initialize
|
8
|
+
@base_url = 'http://dozens.jp'
|
9
|
+
home = File.expand_path('~')
|
10
|
+
conf = IniFile.load("#{home}/.dozenscli.conf")
|
11
|
+
|
12
|
+
dozens_id = conf['profile']['dozens_id']
|
13
|
+
api_key = conf['profile']['api_key']
|
14
|
+
|
15
|
+
if dozens_id.nil? || api_key.nil?
|
16
|
+
abort("\x1b[31;01m[ERROR]\x1b[39;49;00m Configuration file is missing some required information")
|
17
|
+
end
|
18
|
+
|
19
|
+
@headers = {
|
20
|
+
'X-Auth-User' => dozens_id,
|
21
|
+
'X-Auth-Key' => api_key,
|
22
|
+
'Host' => 'dozens.jp',
|
23
|
+
'Content-Type' => 'application/json'
|
24
|
+
}
|
25
|
+
|
26
|
+
uri = URI.parse("#{@base_url}/api/authorize.json")
|
27
|
+
res = Net::HTTP.start(uri.host, uri.port) do |http|
|
28
|
+
http.get(uri.path, @headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
@auth_token = JSON.parse(res.body)['auth_token']
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_data(uri)
|
35
|
+
@headers['X-Auth-Token'] = @auth_token
|
36
|
+
|
37
|
+
res = Net::HTTP.start(uri.host, uri.port) do |http|
|
38
|
+
http.get(uri.path, @headers)
|
39
|
+
end
|
40
|
+
JSON.parse res.body
|
41
|
+
end
|
42
|
+
|
43
|
+
def post_data(uri, data)
|
44
|
+
@headers['X-Auth-Token'] = @auth_token
|
45
|
+
|
46
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
47
|
+
res = http.post(uri.request_uri, data, @headers)
|
48
|
+
JSON.parse res.body
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete_data(uri)
|
52
|
+
@headers['X-Auth-Token'] = @auth_token
|
53
|
+
|
54
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
55
|
+
res = http.delete(uri.request_uri, @headers)
|
56
|
+
JSON.parse res.body
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_zone
|
60
|
+
uri = URI.parse("#{@base_url}/api/zone.json")
|
61
|
+
get_data(uri)
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_zone(zone_name)
|
65
|
+
uri = URI.parse("#{@base_url}/api/zone/create.json")
|
66
|
+
data = JSON.generate({"name" => zone_name})
|
67
|
+
post_data(uri, data)
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete_zone(zone_id)
|
71
|
+
uri = URI.parse("#{@base_url}/api/zone/delete/#{zone_id}.json")
|
72
|
+
delete_data(uri)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_record(zone_name)
|
76
|
+
uri = URI.parse("#{@base_url}/api/record/#{zone_name}.json")
|
77
|
+
get_data(uri)
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_record(params)
|
81
|
+
uri = URI.parse("#{@base_url}/api/record/create.json")
|
82
|
+
begin
|
83
|
+
JSON.parse(params)
|
84
|
+
rescue JSON::ParserError => e
|
85
|
+
abort("\x1b[31;01m[ERROR]\x1b[39;49;00m #{e.message}")
|
86
|
+
else
|
87
|
+
post_data(uri, params)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete_record(record_id)
|
92
|
+
uri = URI.parse("#{@base_url}/api/record/delete/#{record_id}.json")
|
93
|
+
delete_data(uri)
|
94
|
+
end
|
95
|
+
|
96
|
+
def update_record(record_id, params)
|
97
|
+
uri = URI.parse("#{@base_url}/api/record/update/#{record_id}.json")
|
98
|
+
begin
|
99
|
+
JSON.parse(params)
|
100
|
+
rescue JSON::ParserError => e
|
101
|
+
abort("\x1b[31;01m[ERROR]\x1b[39;49;00m #{e.message}")
|
102
|
+
else
|
103
|
+
post_data(uri, params)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Dozenscli
|
4
|
+
class List < Thor
|
5
|
+
def initialize(*args)
|
6
|
+
super
|
7
|
+
@api = API.new
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'zone', 'Return a list of zones'
|
11
|
+
def zone
|
12
|
+
puts JSON.pretty_generate(@api.get_zone)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'record', 'Return a list of records for the provided zone'
|
16
|
+
option :zone, :required => true, :type => :string
|
17
|
+
def record
|
18
|
+
puts JSON.pretty_generate(@api.get_record(options[:zone]))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Create < Thor
|
23
|
+
def initialize(*args)
|
24
|
+
super
|
25
|
+
@api = API.new
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'zone', 'Create a new zone'
|
29
|
+
option :name, :required => true, :type => :string
|
30
|
+
def zone
|
31
|
+
puts JSON.pretty_generate(@api.create_zone(options[:name]))
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'record', 'Create a new record'
|
35
|
+
option :params, :required => true, :type => :string
|
36
|
+
def record
|
37
|
+
puts JSON.pretty_generate(@api.create_record(options[:params]))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Delete < Thor
|
42
|
+
def initialize(*args)
|
43
|
+
super
|
44
|
+
@api = API.new
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'zone', 'Delete a zone'
|
48
|
+
option :id, :required => true, :type => :string
|
49
|
+
def zone
|
50
|
+
puts JSON.pretty_generate(@api.delete_zone(options[:id]))
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'record', 'Delete a record'
|
54
|
+
option :id, :required => true, :type => :string
|
55
|
+
def record
|
56
|
+
puts JSON.pretty_generate(@api.delete_record(options[:id]))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Update < Thor
|
61
|
+
def initialize(*args)
|
62
|
+
super
|
63
|
+
@api = API.new
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'record', 'Update an existing record'
|
67
|
+
option :id, :required => true, :type => :string
|
68
|
+
option :params, :required => true, :type => :string
|
69
|
+
def record
|
70
|
+
puts JSON.pretty_generate(@api.update_record(options[:id], options[:params]))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Command < Thor
|
75
|
+
desc 'list TYPE', 'List resource. Type can be zone, record'
|
76
|
+
subcommand 'list', List
|
77
|
+
|
78
|
+
desc 'create TYPE', 'Create resource. Type can be zone, record'
|
79
|
+
subcommand 'create', Create
|
80
|
+
|
81
|
+
desc 'delete TYPE', 'Delete resource. Type can be zone, record'
|
82
|
+
subcommand 'delete', Delete
|
83
|
+
|
84
|
+
desc 'update TYPE', 'Update resource. Type can be record'
|
85
|
+
subcommand 'update', Update
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dozenscli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- h-tane
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: thor
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.18'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.18'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: inifile
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.0.2
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.0.2
|
78
|
+
description: This package provides a command line interface to Dozens REST API.
|
79
|
+
email:
|
80
|
+
- h-tane@nekojarashi.com
|
81
|
+
executables:
|
82
|
+
- dozens
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/dozens
|
92
|
+
- dozenscli.gemspec
|
93
|
+
- lib/dozenscli.rb
|
94
|
+
- lib/dozenscli/api.rb
|
95
|
+
- lib/dozenscli/command.rb
|
96
|
+
- lib/dozenscli/version.rb
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Command Line Interface for Dozens.
|
122
|
+
test_files: []
|