dnsmadeeasy 0.3.5 → 0.4.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.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # vim: ft=ruby
4
+
3
5
  lib = File.expand_path('lib', __dir__)
4
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
7
  require 'dnsmadeeasy/version'
@@ -34,7 +36,6 @@ Gem::Specification.new do |spec|
34
36
  spec.email = %w(kigster@gmail.com letuboy@gmail.com hjhart@gmail.com)
35
37
  spec.summary = DnsMadeEasy::DESCRIPTION
36
38
  spec.description = DnsMadeEasy::DESCRIPTION
37
- # rubocop:todo Naming/HeredocDelimiterNaming
38
39
  spec.post_install_message = <<~EOF
39
40
  Thank you for using the DnsMadeEasy ruby gem, the Ruby client
40
41
  API for DnsMadeEasy.com's SDK v2. Please note that this gem
data/lib/dme.rb CHANGED
@@ -7,15 +7,10 @@ module DME
7
7
  def [](key, secret)
8
8
  ::DnsMadeEasy::Api::Client.new(key, secret)
9
9
  end
10
-
11
- # rubocop:todo Style/MissingRespondToMissing
12
- # rubocop:todo Style/MethodMissingSuper
13
10
  def method_missing(method, *args, &block)
14
11
  DnsMadeEasy.send(method, *args, &block)
15
12
  rescue NameError => e
16
13
  puts "Error: #{e.message}"
17
14
  end
18
- # rubocop:enable Style/MethodMissingSuper
19
- # rubocop:enable Style/MissingRespondToMissing
20
15
  end
21
16
  end
@@ -92,8 +92,6 @@ module DnsMadeEasy
92
92
  # Basically delegate it all to the Client instance
93
93
  # if the method call is supported.
94
94
  #
95
- # rubocop:todo Style/MissingRespondToMissing
96
- # rubocop:todo Style/MethodMissingSuper
97
95
  def method_missing(method, *args, &block)
98
96
  if client.respond_to?(method)
99
97
  client.send(method, *args, &block)
@@ -101,7 +99,5 @@ module DnsMadeEasy
101
99
  super(method, *args, &block)
102
100
  end
103
101
  end
104
- # rubocop:enable Style/MethodMissingSuper
105
- # rubocop:enable Style/MissingRespondToMissing
106
102
  end
107
103
  end
@@ -169,17 +169,10 @@ module DnsMadeEasy
169
169
  options.merge!('priority' => priority, 'weight' => weight, 'port' => port)
170
170
  create_record domain_name, name, 'SRV', value, options
171
171
  end
172
-
173
- # rubocop:todo Naming/MethodParameterName
174
- # rubocop:todo Naming/VariableName
175
172
  def create_httpred_record(domain_name, name, value, redirectType = 'STANDARD - 302', description = '', keywords = '', title = '', options = {})
176
- # rubocop:enable Naming/VariableName
177
- # rubocop:todo Naming/VariableName
178
173
  options.merge!('redirectType' => redirectType, 'description' => description, 'keywords' => keywords, 'title' => title)
179
- # rubocop:enable Naming/VariableName
180
174
  create_record domain_name, name, 'HTTPRED', value, options
181
175
  end
182
- # rubocop:enable Naming/MethodParameterName
183
176
 
184
177
  def update_record(domain, record_id, name, type, value, options = {})
185
178
  body = { 'name' => name, 'type' => type, 'value' => value, 'ttl' => 3600, 'gtdLocation' => 'DEFAULT', 'id' => record_id }
@@ -89,9 +89,9 @@ module DnsMadeEasy
89
89
 
90
90
  # @return String path to the default credentials file.
91
91
  def default_credentials_path(user: nil)
92
- user ? # rubocop:todo Style/MultilineTernaryOperator
93
- File.expand_path(Dir.home(user) + '/.dnsmadeeasy/credentials.yml').freeze :
94
- File.expand_path('~/.dnsmadeeasy/credentials.yml').freeze
92
+ File.expand_path(
93
+ user ? Dir.home(user) + '/.dnsmadeeasy/credentials.yml' : '~/.dnsmadeeasy/credentials.yml'
94
+ )
95
95
  end
96
96
  end
97
97
  end
@@ -21,28 +21,7 @@ module DnsMadeEasy
21
21
  return nil if mash.nil?
22
22
 
23
23
  creds = if mash.accounts.is_a?(Array)
24
- account = if account
25
- mash.accounts.find { |a| a.name == account.to_s }
26
- elsif
27
- # rubocop:todo Layout/ConditionPosition
28
- mash.accounts.size == 1
29
- # rubocop:enable Layout/ConditionPosition
30
- mash.accounts.first
31
- else
32
- mash.accounts.find(&:default_account)
33
- end
34
-
35
- unless account
36
- raise DnsMadeEasy::APIKeyAndSecretMissingError,
37
- (account ? "account #{account} was not found" : 'default account does not exist')
38
- end
39
-
40
- unless account.credentials
41
- raise DnsMadeEasy::InvalidCredentialsFormatError,
42
- 'Expected account entry to have "credentials" key'
43
- end
44
-
45
- account.credentials
24
+ credentials_from_array(mash.accounts, account&.to_s)
46
25
 
47
26
  elsif mash.credentials
48
27
  mash.credentials
@@ -52,11 +31,11 @@ module DnsMadeEasy
52
31
  'expected either "accounts" or "credentials" as the top-level key'
53
32
  end
54
33
 
55
- # rubocop:todo Style/MultilineTernaryOperator
56
- creds ? ApiKeys.new(creds.api_key,
57
- creds.api_secret,
58
- encryption_key || creds.encryption_key) : nil
59
- # rubocop:enable Style/MultilineTernaryOperator
34
+ return nil unless creds
35
+
36
+ ApiKeys.new creds.api_key,
37
+ creds.api_secret,
38
+ encryption_key || creds.encryption_key
60
39
  end
61
40
 
62
41
  def to_s
@@ -65,6 +44,28 @@ module DnsMadeEasy
65
44
 
66
45
  private
67
46
 
47
+ def credentials_from_array(accounts, account_name = nil)
48
+ account = if account_name
49
+ accounts.find { |a| a.name == account_name }
50
+ elsif accounts.size == 1
51
+ accounts.first
52
+ else
53
+ accounts.find(&:default_account)
54
+ end
55
+
56
+ unless account
57
+ raise DnsMadeEasy::APIKeyAndSecretMissingError,
58
+ (account ? "account #{account} was not found" : 'Default account does not exist')
59
+ end
60
+
61
+ unless account.credentials
62
+ raise DnsMadeEasy::InvalidCredentialsFormatError,
63
+ 'Expected an account entry to have the "credentials" key'
64
+ end
65
+
66
+ account.credentials
67
+ end
68
+
68
69
  def parse!
69
70
  self.mash = Hashie::Extensions::SymbolizeKeys.symbolize_keys(load_hash)
70
71
  end
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ # vim: ft=ruby
5
+
4
6
  require 'colored2'
5
7
  require 'awesome_print'
6
8
  require 'dnsmadeeasy'
@@ -10,11 +12,12 @@ require 'etc'
10
12
  module DnsMadeEasy
11
13
  class Runner
12
14
  SUPPORTED_FORMATS = %w(json json_pretty yaml pp).freeze
15
+ SUPPORTED_FORMAT_FLAGS = SUPPORTED_FORMATS.map { |f| "--#{f}" }.freeze
13
16
 
14
17
  attr_accessor :format, :argv, :operation
15
18
 
16
19
  def initialize(argv = nil)
17
- self.argv = argv || ARGV.dup
20
+ self.argv = argv || ARGV.dup
18
21
  self.format = process_flags_format
19
22
  end
20
23
 
@@ -44,12 +47,10 @@ module DnsMadeEasy
44
47
  end
45
48
  0
46
49
  rescue ArgumentError => e
50
+ STDERR.puts(e.backtrace.join("\n").yellow)
47
51
  sig = method_signature(e, method)
48
- # rubocop:todo Style/MultilineTernaryOperator
49
- sig.shift == method.to_s ?
50
- print_signature(method, sig) :
51
- print_error('Action', method.to_s.bold.yellow.to_s, 'has generated an error'.red, exception: e)
52
- # rubocop:enable Style/MultilineTernaryOperator
52
+ print_signature(method, sig) if sig.shift == method.to_s
53
+ print_error('Action', method.to_s.bold.yellow.to_s, 'has generated an error'.red, exception: e)
53
54
  1
54
55
  rescue NoMethodError => e
55
56
  print_error('Action', method.to_s.bold.yellow.to_s, 'is not valid.'.red)
@@ -62,58 +63,57 @@ module DnsMadeEasy
62
63
 
63
64
  def print_error(*args, exception: nil)
64
65
  unless args.empty?
65
- # rubocop:todo Naming/HeredocDelimiterNaming
66
66
  puts <<~EOF
67
- # rubocop:enable Naming/HeredocDelimiterNaming
68
- #{'Error:'.bold.red} #{args.join(' ').red}
67
+ #{'Error:'.bold.red} #{args.join(' ').red}
69
68
  EOF
70
69
  end
71
70
 
72
71
  if exception
73
- # rubocop:todo Naming/HeredocDelimiterNaming
74
72
  puts <<~EOF
75
- # rubocop:enable Naming/HeredocDelimiterNaming
76
- #{'Exception: '.bold.red}#{exception.inspect.red}
73
+ #{'Exception: '.bold.red}#{exception.inspect.red}
77
74
  EOF
78
75
  end
79
76
  end
80
77
 
81
78
  def print_signature(method, sig)
82
- # rubocop:todo Naming/HeredocDelimiterNaming
83
- puts <<~EOF # rubocop:todo Naming/HeredocDelimiterNaming
84
- # rubocop:enable Naming/HeredocDelimiterNaming
85
- #{'Error: '.bold.yellow}
86
- #{'You are missing some arguments for this operation:'.red}
79
+ puts <<~EOF
80
+ #{'Error: '.bold.yellow}
81
+ #{'You are missing some arguments for this operation:'.red}
87
82
 
88
- #{'Correct Usage: '.bold.yellow}
89
- #{method.to_s.bold.green} #{sig.join(' ').blue}
83
+ #{'Correct Usage: '.bold.yellow}
84
+ #{method.to_s.bold.green} #{sig.join(' ').blue}
90
85
 
91
86
  EOF
92
87
  end
93
88
 
94
89
  def process_flags_format
95
- if argv.first&.start_with?('--')
96
- format = argv.shift.gsub(/^--/, '')
97
- if format =~ /^h(elp)?$/i
98
- print_help_message
99
- end
90
+ if argv.first =~ /^op(erations)?$/i
91
+ print_supported_operations
92
+
93
+ elsif argv.include?('--help') || argv.include?('-h')
94
+ print_help_message
95
+
96
+ elsif !(argv & SUPPORTED_FORMAT_FLAGS).empty?
97
+ format_flag = (argv & SUPPORTED_FORMAT_FLAGS).first
98
+ format = format_flag.delete '--'
99
+ argv.delete(format_flag)
100
100
  unless SUPPORTED_FORMATS.include?(format)
101
- puts "Error: format #{format.bold.red} is not supported."
102
- puts "Supported values are: #{SUPPORTED_FORMATS.join(', ')}"
101
+ warn "Error: format #{format.bold.red} is not supported."
102
+ warn "Supported values are: #{SUPPORTED_FORMATS.join(', ')}"
103
103
  exit 1
104
104
  end
105
- elsif argv.first =~ /^op(erations)?$/i
106
- print_supported_operations
107
- exit 0
105
+ format
108
106
  end
109
- format
110
107
  end
111
108
 
112
109
  def configure_authentication
113
- credentials_file = ENV['DNSMADEEASY_CREDENTIALS_FILE'] || DnsMadeEasy::Credentials.default_credentials_path(user: Etc.getlogin)
110
+ credentials_file = ENV['DNSMADEEASY_CREDENTIALS_FILE'] ||
111
+ DnsMadeEasy::Credentials.default_credentials_path(user: Etc.getlogin)
112
+
114
113
  if ENV['DNSMADEEASY_API_KEY'] && ENV['DNSMADEEASY_API_SECRET']
115
114
  DnsMadeEasy.api_key = ENV['DNSMADEEASY_API_KEY']
116
115
  DnsMadeEasy.api_secret = ENV['DNSMADEEASY_API_SECRET']
116
+
117
117
  elsif credentials_file && ::File.exist?(credentials_file)
118
118
  keys = DnsMadeEasy::Credentials.keys_from_file(file: credentials_file)
119
119
  if keys
@@ -125,61 +125,70 @@ module DnsMadeEasy
125
125
  if DnsMadeEasy.api_key.nil?
126
126
  print_error('API Key/Secret was not detected or read from file')
127
127
  puts('You can also set two environment variables: ')
128
- puts(' DNSMADEEASY_API_KEY and DNSMADEEASY_API_SECRET')
128
+ puts('DNSMADEEASY_API_KEY and ')
129
+ puts(' • DNSMADEEASY_API_SECRET')
129
130
  exit 123
130
131
  end
131
132
  end
132
133
 
133
134
  def print_usage_message
134
- # rubocop:todo Naming/HeredocDelimiterNaming
135
135
  puts <<~EOF
136
- # rubocop:enable Naming/HeredocDelimiterNaming
137
- #{'Usage:'.bold.yellow}
138
- #{'# Execute an API call:'.dark}
139
- #{"dme [ #{SUPPORTED_FORMATS.map { |f| "--#{f}" }.join(' | ')} ] operation [ arg1 arg2 ... ] ".bold.green}
140
-
141
- #{'# Print suported operations:'.dark}
142
- #{'dme op[erations]'.bold.green}
136
+ #{'Usage:'.bold.yellow}
137
+ #{'# Execute an API call:'.dark}
138
+ #{"dme [ #{SUPPORTED_FORMATS.map { |f| "--#{f}" }.join(' | ')} ] operation [ arg1 arg2 ... ] ".bold.green}
143
139
 
140
+ #{'# Print suported operations:'.dark}
141
+ #{'dme op[erations]'.bold.green}
144
142
  EOF
145
143
  end
146
144
 
147
145
  def print_help_message
148
146
  print_usage_message
149
-
150
- # rubocop:todo Naming/HeredocDelimiterNaming
151
147
  puts <<~EOF
152
- # rubocop:enable Naming/HeredocDelimiterNaming
153
- #{header 'Credentials'}
154
- Store your credentials in a YAML file
155
- #{DnsMadeEasy::Credentials.default_credentials_path(user: ENV['USER'])} as follows:
156
148
 
149
+ #{header 'Credentials'}
150
+ Store your credentials in a YAML file #{DnsMadeEasy::Credentials.default_credentials_path(user: ENV['USER']).blue}
151
+ as follows:
152
+
153
+ #{'# ~/.dnsmadeeasy/credentials.yml'.bold.black}
157
154
  #{'credentials:
158
- api_key: XXXX
159
- api_secret: YYYY'.bold.magenta}
160
-
161
- Or a multi-account version:
162
-
163
- #{'accounts:
164
- - name: production
165
- credentials:
166
- api_key: XXXX
167
- api_secret: YYYY
168
- encryption_key: my_key
169
- - name: development
170
- default_account: true
171
- credentials:
172
- api_key: ZZZZ
173
- api_secret: WWWW'.bold.magenta}
174
-
175
- #{header 'Examples:'}
176
- #{'dme domain moo.com
177
- dme --json domain moo.com
178
- dme find_all moo.com A www
179
- dme find_first moo.com CNAME vpn-west
180
- dme --yaml find_first moo.com CNAME vpn-west'.green}
155
+ api_key: XXXX
156
+ api_secret: YYYY'.cyan}
157
+
158
+ Or, you can use a multi-account version, but in that case it helps if you
159
+ specify which of the accounts is the default:
181
160
 
182
161
  EOF
162
+
163
+ puts <<-YAML
164
+ #{'# ~/.dnsmadeeasy/credentials.yml'.bold.black}
165
+ #{'accounts:
166
+ - name: production
167
+ credentials:
168
+ api_key: XXXX
169
+ api_secret: YYYY
170
+ encryption_key: my_key
171
+ - name: development
172
+ default_account: true
173
+ credentials:
174
+ api_key: ZZZZ
175
+ api_secret: WWWW'.cyan}
176
+ YAML
177
+
178
+ puts header 'Examples:'
179
+
180
+ puts '
181
+ $ dme domain moo.com
182
+ $ dme domain moo.com --yaml > moo.yml
183
+
184
+ $ dme all moo.com
185
+ $ dme find_all moo.com A www
186
+ $ dme find_first moo.com CNAME vpn-west
187
+
188
+ $ dme update_record moo.com www A 11.3.43.56
189
+ $ dme create_record moo.com ftp CNAME www.moo.com.
190
+
191
+ $ dme --yaml find_first moo.com CNAME vpn-west'.green
183
192
  exit 1
184
193
  end
185
194
 
@@ -188,17 +197,14 @@ module DnsMadeEasy
188
197
  end
189
198
 
190
199
  def print_supported_operations
191
- # rubocop:todo Naming/HeredocDelimiterNaming
192
200
  puts <<~EOF
193
- # rubocop:enable Naming/HeredocDelimiterNaming
194
- #{header 'Actions:'}
195
- Checkout the README and RubyDoc for the arguments to each operation,
196
- which is basically a method on a DnsMadeEasy::Api::Client instance.
197
- #{'http://www.rubydoc.info/gems/dnsmadeeasy/DnsMadeEasy/Api/Client'.blue.bold.underlined}
198
-
199
- #{header 'Valid Operations Are:'}
200
- #{DnsMadeEasy::Api::Client.public_operations.join("\n ").green.bold}
201
+ #{header 'Actions:'}
202
+ Checkout the README and RubyDoc for the arguments to each operation,
203
+ which is basically a method on a DnsMadeEasy::Api::Client instance.
204
+ #{'http://www.rubydoc.info/gems/dnsmadeeasy/DnsMadeEasy/Api/Client'.blue.bold.underlined}
201
205
 
206
+ #{header 'Valid Operations Are:'}
207
+ #{DnsMadeEasy::Api::Client.public_operations.join("\n ").green.bold}
202
208
  EOF
203
209
  end
204
210
 
@@ -220,10 +226,9 @@ module DnsMadeEasy
220
226
 
221
227
  # e.backtrack.first looks like this:
222
228
  # ..../dnsmadeeasy/lib/dnsmadeeasy/api/client.rb:143:in `create_a_record'
223
- # rubocop:todo Naming/MethodParameterName
224
229
  def method_signature(e, method)
225
230
  file, line, call_method = e.backtrace.first.split(':')
226
- call_method = call_method.gsub(/[']/, '').split('`').last
231
+ call_method = call_method.gsub(/[']/, '').split('`').last
227
232
  if call_method && call_method.to_sym == method.to_sym
228
233
  source_line = File.open(file).to_a[line.to_i - 1].chomp!
229
234
  if source_line =~ /def #{method}/
@@ -236,7 +241,6 @@ module DnsMadeEasy
236
241
  rescue StandardError
237
242
  []
238
243
  end
239
- # rubocop:enable Naming/MethodParameterName
240
244
 
241
245
  def puts(*args)
242
246
  super(*args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DnsMadeEasy
4
- VERSION = '0.3.5'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsmadeeasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2019-12-04 00:00:00.000000000 Z
16
+ date: 2020-04-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: awesome_print
@@ -227,6 +227,8 @@ extensions: []
227
227
  extra_rdoc_files: []
228
228
  files:
229
229
  - ".codeclimate.yml"
230
+ - ".dme-help.png"
231
+ - ".github/workflows/ruby.yml"
230
232
  - ".gitignore"
231
233
  - ".rspec"
232
234
  - ".rubocop.yml"
@@ -234,7 +236,7 @@ files:
234
236
  - ".travis.yml"
235
237
  - Gemfile
236
238
  - LICENSE.txt
237
- - README.md
239
+ - README.adoc
238
240
  - Rakefile
239
241
  - bin/console
240
242
  - bin/setup
@@ -277,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
279
  - !ruby/object:Gem::Version
278
280
  version: '0'
279
281
  requirements: []
280
- rubygems_version: 3.0.6
282
+ rubygems_version: 3.1.2
281
283
  signing_key:
282
284
  specification_version: 4
283
285
  summary: 'This is an authoratative and fully-featured API client for the DNS Provider