gandi_cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb8f5388914fc3320694ff7ca9c27d4c850adf50
4
+ data.tar.gz: 219417c266880e17271cdcea7ef67b935e0ca5ef
5
+ SHA512:
6
+ metadata.gz: fac74e1bbf6fcc0a5857c4d35ba771230aa4362672e3285faa8e0c0aa1acdbbec3535ff0c24fac489a9a9d26f8a9107d1fe0917004768e8229b29b2bce4570b8
7
+ data.tar.gz: d3df8e92f067bb5d67030d590fce6d58b5eab57d8cd044959c325d1f0461262b673b1b10fb7b62f52112cca46b9d7e0cf04b4e6ba8bf4b41de0a6c914a79232a
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 gandi_cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jacob Atzen
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,45 @@
1
+ # GandiCli
2
+
3
+ Command line utility to manage DNS zones hosted by gandi.net
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gandi_cli'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gandi_cli
18
+
19
+ ## Usage
20
+
21
+ List zones:
22
+
23
+ $ gandi_cli list
24
+
25
+ name zone_id current_version
26
+ Default Gandi zone file 681838 1
27
+ mydomain.com 808080 20
28
+
29
+ Add a new record to the latest version of the zone (or copy if the latest is the active):
30
+
31
+ gandi_cli add_record mydomain.com A 86400 www 10.0.0.1
32
+
33
+ Activate the new version:
34
+
35
+ gandi_cli activate mydomain.com 21
36
+
37
+ See `gandi_cli help` for further information.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/gandi_cli ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require "gandi_cli"
6
+
7
+ # Start the CLI
8
+ GandiCli::Cli.start(ARGV)
data/gandi_cli.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gandi_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gandi_cli"
8
+ spec.version = GandiCli::VERSION
9
+ spec.authors = ["Jacob Atzen"]
10
+ spec.email = ["jacob@incremental.dk"]
11
+ spec.description = %q{Command line client for interacting with the gandi.net API}
12
+ spec.summary = %q{Command line client for the gandi.net API}
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_dependency 'gandi'
22
+ spec.add_dependency 'thor'
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+
26
+ spec.executables << 'gandi_cli'
27
+ end
@@ -0,0 +1,88 @@
1
+ module GandiCli
2
+ class Cli < Thor
3
+ desc "list", "List zone files"
4
+ def list
5
+ puts "%-30s %10s %s" % %w[name zone_id current_version]
6
+ GandiCli::Zone.list(client).each do |zone|
7
+ puts "%-30s %10s %15s" % [zone.name, zone.id, zone.version.id]
8
+ end
9
+ end
10
+
11
+ desc "add_record ZONE_NAME TYPE TTL NAME VALUE", "Add record to zone"
12
+ def add_record(zone_name, type, ttl, name, value)
13
+ zone = GandiCli::Zone.find(client, zone_name)
14
+ version = editable_version(zone)
15
+ version.add_record(type, ttl.to_i, name, value)
16
+ end
17
+
18
+ desc "records ZONE_NAME VERSION", "List records for a given version of a zone"
19
+ def records(zone_name, version)
20
+ zone = GandiCli::Zone.find(client, zone_name)
21
+ zone.find_version(version).records.each do |record|
22
+ puts "%s %s %s %s %s" % [record.id, record.type, record.ttl, record.name, record.value]
23
+ end
24
+ end
25
+
26
+ desc "activate ZONE_NAME VERSION", "Activate version for zone"
27
+ def activate(zone_name, version)
28
+ zone = GandiCli::Zone.find(client, zone_name)
29
+ zone.find_version(version).activate!
30
+ end
31
+
32
+ desc "delete_record ZONE_NAME VERSION RECORD_ID", "Delete a record"
33
+ def delete_record(zone_name, version, record_id)
34
+ zone = GandiCli::Zone.find(client, zone_name)
35
+ zone_record = zone.find_version(version).records.find{ |record|
36
+ record.id == record_id.to_i
37
+ }
38
+ if zone_record
39
+ puts "Deleting #{format_record(zone_record)}"
40
+ zone_record.delete
41
+ else
42
+ puts "Record not found"
43
+ end
44
+ end
45
+
46
+ desc "versions ZONE_NAME", "List versions for zone"
47
+ def versions(zone_name)
48
+ zone = GandiCli::Zone.find(client, zone_name)
49
+ zone.versions.each do |version|
50
+ puts "#{zone_name} v#{version.id}"
51
+ end
52
+ end
53
+
54
+ desc "copy_version ZONE_NAME [VERSION]", "Copy zone version (defaults to active version)"
55
+ def copy_version(zone_name, version = 0)
56
+ zone = GandiCli::Zone.find(client, zone_name)
57
+ new_version = zone.find_version(version.to_i).copy
58
+ puts "New version is #{new_version.id}"
59
+ end
60
+
61
+ private
62
+
63
+ def editable_version(zone)
64
+ if zone.version.id == zone.versions.last.id
65
+ puts "Creating new version of zone file based on v#{zone.version.id}"
66
+ zone.version.copy
67
+ else
68
+ zone.versions.last
69
+ end
70
+ end
71
+
72
+ def format_record(record)
73
+ "%s %s %s %s %s" % [record.id, record.type, record.ttl, record.name, record.value]
74
+ end
75
+
76
+ def client
77
+ GandiCli::Client.new(key).session
78
+ end
79
+
80
+ def zone_by_name(zone_name)
81
+ GandiCli::Zone.find(client, zone_name)
82
+ end
83
+
84
+ def key
85
+ File.read(ENV['HOME']+"/.gandi_cli").strip
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,11 @@
1
+ module GandiCli
2
+ class Client
3
+ def initialize(key)
4
+ @key = key
5
+ end
6
+
7
+ def session
8
+ @session ||= Gandi::Session.new(@key)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'forwardable'
2
+
3
+ module GandiCli
4
+ class Record
5
+ extend Forwardable
6
+ def_delegators :@record_info, :id, :type, :ttl, :name, :value
7
+ attr_reader :client, :zone_id, :version_id
8
+ def initialize(client, zone_id, version_id, record_info)
9
+ @client = client
10
+ @zone_id = zone_id
11
+ @version_id = version_id
12
+ @record_info = record_info
13
+ end
14
+
15
+ def delete
16
+ client.domain.zone.record.delete(zone_id, version_id, :id => id)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module GandiCli
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ module GandiCli
2
+ class Zone
3
+ extend Forwardable
4
+ class << self
5
+ def list(client)
6
+ client.domain.zone.list.map{|zone_info|
7
+ new(client, zone_info)
8
+ }
9
+ end
10
+
11
+ def find(client, name)
12
+ zone = client.domain.zone.list.find{|zone_info|
13
+ zone_info.name == name
14
+ }
15
+ new(client, zone)
16
+ end
17
+ end
18
+
19
+ def_delegators :@zone_info, :id, :name
20
+
21
+ attr_reader :client, :zone_info
22
+
23
+ def initialize(client, zone_info)
24
+ @client = client
25
+ @zone_info = zone_info
26
+ end
27
+
28
+ def versions
29
+ client.domain.zone.version.list(id).map{|version_info|
30
+ ZoneVersion.new(client, id, version_info.id)
31
+ }
32
+ end
33
+
34
+ def version
35
+ ZoneVersion.new(client, id, zone_info.version)
36
+ end
37
+
38
+ def find_version(version)
39
+ ZoneVersion.new(client, id, version)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ module GandiCli
2
+ class ZoneVersion
3
+ attr_reader :client, :zone_id, :id
4
+ def initialize(client, zone_id, id)
5
+ @client = client
6
+ @zone_id = zone_id
7
+ @id = id.to_i
8
+ end
9
+
10
+ def to_s
11
+ "#{zone_id}:#{id}"
12
+ end
13
+
14
+ def copy
15
+ new_zone_id = client.domain.zone.version.new(zone_id, id)
16
+ ZoneVersion.new(client, zone_id, new_zone_id)
17
+ end
18
+
19
+ def records
20
+ client.domain.zone.record.list(zone_id, id).map do |record_info|
21
+ Record.new(client, zone_id, id, record_info)
22
+ end
23
+ end
24
+
25
+ def add_record(type, ttl, name, value)
26
+ client.domain.zone.record.add(zone_id, id,
27
+ :type => type,
28
+ :ttl => ttl,
29
+ :name => name,
30
+ :value => value)
31
+ end
32
+
33
+ def activate!
34
+ client.domain.zone.version.set(zone_id, id)
35
+ end
36
+ end
37
+ end
data/lib/gandi_cli.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "gandi"
2
+ require "thor"
3
+ require "gandi_cli/version"
4
+ require "gandi_cli/zone_version"
5
+ require "gandi_cli/record"
6
+ require "gandi_cli/zone"
7
+ require "gandi_cli/client"
8
+ require "gandi_cli/cli"
9
+
10
+ module GandiCli
11
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gandi_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Atzen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gandi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Command line client for interacting with the gandi.net API
70
+ email:
71
+ - jacob@incremental.dk
72
+ executables:
73
+ - gandi_cli
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/gandi_cli
83
+ - gandi_cli.gemspec
84
+ - lib/gandi_cli.rb
85
+ - lib/gandi_cli/cli.rb
86
+ - lib/gandi_cli/client.rb
87
+ - lib/gandi_cli/record.rb
88
+ - lib/gandi_cli/version.rb
89
+ - lib/gandi_cli/zone.rb
90
+ - lib/gandi_cli/zone_version.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.14
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Command line client for the gandi.net API
115
+ test_files: []