Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Remove unneeded .freeze method on literal string.
Browse files Browse the repository at this point in the history
  • Loading branch information
christiankakesa committed Dec 28, 2016
1 parent a1ede6d commit fa23155
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

source 'https://rubygems.org'.freeze
source 'https://rubygems.org'

# Specify your gem's dependencies in netsoul.gemspec
gemspec
12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'yard'

RSpec::Core::RakeTask.new('spec'.freeze)
RSpec::Core::RakeTask.new('spec')

task default: :spec

require 'rake/extensiontask'
Rake::ExtensionTask.new 'netsoul_kerberos'.freeze do |ext|
ext.lib_dir = 'lib'.freeze
Rake::ExtensionTask.new 'netsoul_kerberos' do |ext|
ext.lib_dir = 'lib'
end

desc 'Generate documentation'.freeze
desc 'Generate documentation'
YARD::Rake::YardocTask.new do |t|
t.files = %w(lib/**/*.rb - LICENSE.txt).map(&:freeze).freeze
t.options = %w(--main README.md --no-private --protected).map(&:freeze).freeze
t.files = %w(lib/**/*.rb - LICENSE.txt).map(&:freeze)
t.options = %w(--main README.md --no-private --protected).map(&:freeze)
end
22 changes: 11 additions & 11 deletions bin/netsoul-ruby
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

lib = File.join(File.dirname(File.realpath(__FILE__)), '..'.freeze, 'lib'.freeze)
lib = File.join(File.dirname(File.realpath(__FILE__)), '..', 'lib')
$LOAD_PATH.unshift File.expand_path(lib)

require 'netsoul/client'

require 'optparse'
require 'yaml'

process_name_string = "#{__FILE__} #{ARGV.join(' '.freeze)}".freeze
process_name_string = "#{__FILE__} #{ARGV.join(' ')}"
Process.respond_to?(:setproctitle) ? Process.setproctitle(process_name_string) : $PROGRAM_NAME = process_name_string

options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: netsoul-ruby [options]'.freeze
opts.separator ''.freeze
opts.separator 'Netsoul-Ruby options:'.freeze
opts.banner = 'Usage: netsoul-ruby [options]'
opts.separator ''
opts.separator 'Netsoul-Ruby options:'

opts.on('-c'.freeze, '--config FILE'.freeze, 'Configuration file in YAML'.freeze) do |file|
opts.on('-c', '--config FILE', 'Configuration file in YAML') do |file|
options[:user_opts] = YAML.load_file(file) if File.file?(file)
end

opts.on('-h'.freeze, '--help'.freeze, 'Display this screen'.freeze) do
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit 42
end
end.parse!

if options.empty? || options[:user_opts].size == 0
unless ENV.to_a.count { |k, _v| %w(NETSOUL_LOGIN NETSOUL_SOCKS_PASSWORD NETSOUL_LOGIN NETSOUL_UNIX_PASSWORD NETSOUL_AUTH_METHOD).include?(k) } >= 2
puts '[ERROR] You have to specify a configuration file or environment variables'.freeze
puts '[ERROR] You have to specify a configuration file or environment variables'
exit 42
end
end

def trap_interrupt(client)
Signal.trap('INT'.freeze) do
Signal.trap('INT') do
exit 42 unless client.started
begin client.disconnect; end
puts '!!! [SIGINT] !!!'.freeze
puts '!!! [SIGINT] !!!'
exit 42
end
end
Expand All @@ -59,7 +59,7 @@ begin
retry_wait_time = 1.0
loop do
res = c.get
res != 'nothing'.freeze ? log(:info, "[get ] #{res}") : log(:warn, '[get ] (<was empty!!!>)'.freeze)
res != 'nothing' ? log(:info, "[get ] #{res}") : log(:warn, '[get ] (<was empty!!!>)')
if res.to_s.match(/^ping.*/)
c.send res
log :info, "[send] #{res}"
Expand Down
14 changes: 7 additions & 7 deletions ext/netsoul_kerberos/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

require 'mkmf'

have_library('krb5'.freeze, 'krb5_init_context'.freeze)
have_library('gssapi_krb5'.freeze, 'gss_init_sec_context'.freeze)
have_header('string.h'.freeze)
have_header('krb5.h'.freeze)
have_header('gssapi/gssapi.h'.freeze)
have_header('gssapi/gssapi_krb5.h'.freeze)
have_library('krb5', 'krb5_init_context')
have_library('gssapi_krb5', 'gss_init_sec_context')
have_header('string.h')
have_header('krb5.h')
have_header('gssapi/gssapi.h')
have_header('gssapi/gssapi_krb5.h')

create_makefile('netsoul_kerberos'.freeze)
create_makefile('netsoul_kerberos')
14 changes: 7 additions & 7 deletions lib/netsoul/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(*args)

def auth_ag
send(Message.auth_ag)
raise Netsoul::IdentificationError, 'Identification failed.'.freeze unless get.split(' '.freeze)[1] == '002'.freeze
raise Netsoul::IdentificationError, 'Identification failed.' unless get.split(' ')[1] == '002'
end
private :auth_ag

Expand All @@ -27,8 +27,8 @@ def auth_method
else
send(Message.standard_auth(@config))
end
raise Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze \
unless get.split(' '.freeze)[1] == '002'.freeze
raise Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables' \
unless get.split(' ')[1] == '002'
end
private :auth_method

Expand All @@ -40,7 +40,7 @@ def auth_status

def connect
@socket = TCPSocket.new(@config.server_host, @config.server_port)
raise Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @socket
raise Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.' unless @socket
_cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = get.split

@config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
Expand All @@ -62,20 +62,20 @@ def disconnect
def send(str)
_, sock = IO.select(nil, [@socket], nil, SOCKET_WRITE_TIMEOUT)
s = sock.first
raise Netsoul::SocketError, 'Timeout or raise on write socket'.freeze unless s
raise Netsoul::SocketError, 'Timeout or raise on write socket' unless s
s.puts str
s.flush
end

def get
sock, = IO.select([@socket], nil, nil, SOCKET_READ_TIMEOUT)
s = sock.first
raise Netsoul::SocketError, 'Timeout or raise on read socket'.freeze unless s
raise Netsoul::SocketError, 'Timeout or raise on read socket' unless s
res = s.gets.chomp
if !res.empty?
res
else
'nothing'.freeze # Send some string and permit IO.select to thrown exception if something goes wrong.
'nothing' # Send some string and permit IO.select to thrown exception if something goes wrong.
end
end

Expand Down
14 changes: 7 additions & 7 deletions lib/netsoul/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class Config
#
# rubocop:disable all
def initialize(opts = {})
@server_host = ENV['NETSOUL_SERVER_HOST'] || opts.fetch(:server_host, 'ns-server.epita.fr'.freeze)
@server_host = ENV['NETSOUL_SERVER_HOST'] || opts.fetch(:server_host, 'ns-server.epita.fr')
@server_port = Integer(ENV['NETSOUL_SERVER_PORT'] || opts.fetch(:server_port, 4242))
@login = ENV['NETSOUL_LOGIN'] || opts.fetch(:login, 'ionis'.freeze)
@socks_password = ENV['NETSOUL_SOCKS_PASSWORD'] || opts.fetch(:socks_password, 'socks_password'.freeze)
@unix_password = ENV['NETSOUL_UNIX_PASSWORD'] || opts.fetch(:unix_password, 'unix_password'.freeze)
@login = ENV['NETSOUL_LOGIN'] || opts.fetch(:login, 'ionis')
@socks_password = ENV['NETSOUL_SOCKS_PASSWORD'] || opts.fetch(:socks_password, 'socks_password')
@unix_password = ENV['NETSOUL_UNIX_PASSWORD'] || opts.fetch(:unix_password, 'unix_password')
@auth_method = (ENV['NETSOUL_AUTH_METHOD'] || (AUTH_METHODS.include?(opts[:auth_method]) ? opts[:auth_method] : :std)).to_sym
@state = (ENV['NETSOUL_STATE'] || (USER_STATES.include?(opts[:state]) ? opts[:state] : :none)).to_sym
@location = ENV['NETSOUL_LOCATION'] || opts.fetch(:location, 'Home'.freeze)
@user_group = ENV['NETSOUL_USER_GROUP'] || opts.fetch(:user_group, 'ETNA_2008'.freeze)
@location = ENV['NETSOUL_LOCATION'] || opts.fetch(:location, 'Home')
@user_group = ENV['NETSOUL_USER_GROUP'] || opts.fetch(:user_group, 'ETNA_2008')
@user_connection_info = {}

@client_name = ENV['NETSOUL_CLIENT_NAME'] || opts.fetch(:client_name, "(Netsoul-Ruby v#{Netsoul::VERSION}) -> { Christian Kakesa, since 2009}".freeze)
@client_name = ENV['NETSOUL_CLIENT_NAME'] || opts.fetch(:client_name, "(Netsoul-Ruby v#{Netsoul::VERSION}) -> { Christian Kakesa, since 2009}")
end
# rubocop:enable all

Expand Down
2 changes: 1 addition & 1 deletion lib/netsoul/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.logger
$stdout.sync = true
logger.level = Logger::INFO
logger.formatter = proc do |severity, datetime, _progname, msg|
"#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L'.freeze)}] #{msg}\n"
"#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{msg}\n"
end
end
end
Expand Down
84 changes: 42 additions & 42 deletions lib/netsoul/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _standard_auth_string(config)

def standard_auth(config)
client_ip = config.user_connection_info[:client_ip]
location = Message._escape(Location.get(client_ip) == 'ext'.freeze ? config.location : Location.get(client_ip))
location = Message._escape(Location.get(client_ip) == 'ext' ? config.location : Location.get(client_ip))
client_name = Message._escape(config.client_name)
"ext_user_log #{config.login} #{_standard_auth_string(config)} #{client_name} #{location}"
end
Expand All @@ -39,14 +39,14 @@ def _kerberos_auth_klog(config)

def kerberos_auth(config)
unless _kerberos_get.build_token(config.login, config.unix_password)
raise Netsoul::Error, 'Impossible to retrieve the kerberos token.'.freeze
raise Netsoul::Error, 'Impossible to retrieve the kerberos token.'
end
_kerberos_auth_klog(config)
end
# :nocov:

def auth_ag
'auth_ag ext_user none none'.freeze
'auth_ag ext_user none none'
end

def send_message(user, msg)
Expand Down Expand Up @@ -74,7 +74,7 @@ def watch_users(user_list)
end

def attach
'user_cmd attach'.freeze
'user_cmd attach'
end

def user_state(state, timestamp)
Expand Down Expand Up @@ -102,16 +102,16 @@ def xfer_cancel(user, id)
end

def ping
'pong'.freeze
'pong'
end

def ns_exit
'exit'.freeze
'exit'
end

def _escape(str)
str = URI.escape(str, Regexp.new("#{URI::PATTERN::ALNUM}[:graph:][:punct:][:cntrl:][:print:][:blank:]", false, 'N'.freeze))
URI.escape(str, Regexp.new("[^#{URI::PATTERN::ALNUM}]", false, 'N'.freeze))
str = URI.escape(str, Regexp.new("#{URI::PATTERN::ALNUM}[:graph:][:punct:][:cntrl:][:print:][:blank:]", false, 'N'))
URI.escape(str, Regexp.new("[^#{URI::PATTERN::ALNUM}]", false, 'N'))
end

def _unescape(str)
Expand All @@ -126,45 +126,45 @@ def get(ip)
locations.each do |key, val|
return key.to_s if ip =~ /^#{val}/
end
'ext'.freeze
'ext'
end

# rubocop:disable all
def locations
@locations ||= {
:'lab-cisco-mid-sr' => '10.251.'.freeze,
etna: '10.245.'.freeze,
lse: '10.227.42.'.freeze,
:'sda-1' => '10.227.4.'.freeze,
lab: '10.227.'.freeze,
:'lab-tcom' => '10.226.7.'.freeze,
:'lab-acu' => '10.226.6.'.freeze,
:'lab-console' => '10.226.5.'.freeze,
:'lab-mspe' => '10.226.'.freeze,
epitanim: '10.225.19.'.freeze,
epidemic: '10.225.18.'.freeze,
:'sda-2' => '10.225.10.'.freeze,
cycom: '10.225.8.'.freeze,
epx: '10.225.7.'.freeze,
prologin: '10.225.6.'.freeze,
nomad: '10.225.2.'.freeze,
assos: '10.225.'.freeze,
sda: '10.224.14.'.freeze,
www: '10.223.106.'.freeze,
episport: '10.223.104.'.freeze,
epicom: '10.223.103.'.freeze,
:'bde-epita' => '10.223.100.'.freeze,
omatis: '10.223.42.'.freeze,
ipsa: '10.223.15.'.freeze,
lrde: '10.223.13.'.freeze,
cvi: '10.223.7.'.freeze,
epi: '10.223.1.'.freeze,
pasteur: '10.223.'.freeze,
bocal: '10.42.42.'.freeze,
sm: '10.42.'.freeze,
vpn: '10.10.'.freeze,
adm: '10.1.'.freeze,
epita: '10.'.freeze
:'lab-cisco-mid-sr' => '10.251.',
etna: '10.245.',
lse: '10.227.42.',
:'sda-1' => '10.227.4.',
lab: '10.227.',
:'lab-tcom' => '10.226.7.',
:'lab-acu' => '10.226.6.',
:'lab-console' => '10.226.5.',
:'lab-mspe' => '10.226.',
epitanim: '10.225.19.',
epidemic: '10.225.18.',
:'sda-2' => '10.225.10.',
cycom: '10.225.8.',
epx: '10.225.7.',
prologin: '10.225.6.',
nomad: '10.225.2.',
assos: '10.225.',
sda: '10.224.14.',
www: '10.223.106.',
episport: '10.223.104.',
epicom: '10.223.103.',
:'bde-epita' => '10.223.100.',
omatis: '10.223.42.',
ipsa: '10.223.15.',
lrde: '10.223.13.',
cvi: '10.223.7.',
epi: '10.223.1.',
pasteur: '10.223.',
bocal: '10.42.42.',
sm: '10.42.',
vpn: '10.10.',
adm: '10.1.',
epita: '10.'
}
end
# rubocop:enable all
Expand Down
2 changes: 1 addition & 1 deletion lib/netsoul/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Netsoul
VERSION = '2.4.5'.freeze
VERSION = '2.5.0'
end
Loading

0 comments on commit fa23155

Please sign in to comment.