Class: Dyndnsd::Helper
- Inherits:
-
Object
- Object
- Dyndnsd::Helper
- Defined in:
- lib/dyndnsd/helper.rb
Class Method Summary collapse
- .changed?(hostname, myips, hosts) ⇒ Boolean
- .fqdn_valid?(hostname, domain) ⇒ Boolean
- .ip_valid?(ip) ⇒ Boolean
- .span(operation, &block) ⇒ void
- .user_allowed?(username, password, users) ⇒ Boolean
Class Method Details
.changed?(hostname, myips, hosts) ⇒ Boolean
39 40 41 42 |
# File 'lib/dyndnsd/helper.rb', line 39 def self.changed?(hostname, myips, hosts) # myips order is always deterministic ((!hosts.include? hostname) || (hosts[hostname] != myips)) && !myips.empty? end |
.fqdn_valid?(hostname, domain) ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/dyndnsd/helper.rb', line 10 def self.fqdn_valid?(hostname, domain) return false if hostname.length < domain.length + 2 return false if !hostname.end_with?(domain) name = hostname.chomp(domain) return false if !name.match(/^[a-zA-Z0-9_-]+\.$/) true end |
.ip_valid?(ip) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/dyndnsd/helper.rb', line 20 def self.ip_valid?(ip) IPAddr.new(ip) true rescue ArgumentError false end |
.span(operation, &block) ⇒ void
This method returns an undefined value.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dyndnsd/helper.rb', line 47 def self.span(operation, &block) tracer = OpenTelemetry.tracer_provider.tracer(Dyndnsd.name, Dyndnsd::VERSION) tracer.in_span( operation, attributes: {'component' => 'dyndnsd'}, kind: :server ) do |span| Dyndnsd.logger.debug "Creating span ID #{span.context.hex_span_id} for trace ID #{span.context.hex_trace_id}" block.call(span) rescue StandardError => e span.record_exception(e) raise e end end |
.user_allowed?(username, password, users) ⇒ Boolean
31 32 33 |
# File 'lib/dyndnsd/helper.rb', line 31 def self.user_allowed?(username, password, users) (users.key? username) && (users[username]['password'] == password) end |