Skip to content

Commit

Permalink
Merge pull request #27 from redBorder/improvement/fix_lint
Browse files Browse the repository at this point in the history
Improvement/fix lint
  • Loading branch information
nilsver authored Jun 4, 2024
2 parents 423775a + 02252f6 commit 2dd52af
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 476 deletions.
4 changes: 2 additions & 2 deletions resources/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Flags
default["webui"]["registered"] = false
# Flags
default['webui']['registered'] = false
53 changes: 28 additions & 25 deletions resources/libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ def local_routes

# Ejecuta el comando `ip route` y captura su salida
ip_route_output = `ip route`

ip_route_output.each_line do |line|
if line.include?('link')
# Obtiene el prefijo (por ejemplo, "192.168.1.0/24")
prefix = line.split[0]
routes.push(prefix) unless routes.include?(prefix)
end
next unless line.include?('link')

# Obtiene el prefijo (por ejemplo, '192.168.1.0/24')
prefix = line.split[0]
routes.push(prefix) unless routes.include?(prefix)
end

routes
end

Expand All @@ -29,44 +27,49 @@ def create_cert(cn)
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
cert.not_after = Time.now + (3600 *24 *365 *10)
cert.not_after = Time.now + (3600 * 24 * 365 * 10)
cert.public_key = key.public_key
cert.subject = name
cert.issuer = name
if cn.start_with?("s3.")
if cn.start_with?('s3.')
extension_factory = OpenSSL::X509::ExtensionFactory.new nil, cert
cert.add_extension extension_factory.create_extension("subjectAltName","DNS:redborder.#{cn}",false)
cert.add_extension extension_factory.create_extension("subjectAltName","DNS:rbookshelf.#{cn}",false)
cert.add_extension extension_factory.create_extension("subjectAltName","DNS:#{cn}",false)
cert.add_extension extension_factory.create_extension('subjectAltName', "DNS:redborder.#{cn}", false)
cert.add_extension extension_factory.create_extension('subjectAltName', "DNS:rbookshelf.#{cn}", false)
cert.add_extension extension_factory.create_extension('subjectAltName', "DNS:#{cn}", false)
end
cert.sign key, OpenSSL::Digest::SHA1.new
{ :key => key, :crt => cert}
cert.sign key, OpenSSL::Digest.new('SHA1')
{ key: key, crt: cert }
end

def create_json_cert(app,cdomain)
ret_json = { "id" => app }
def create_json_cert(app, cdomain)
ret_json = { id: app }
cert_hash = create_cert("#{app}.#{cdomain}")
ret_json["#{app}_crt"] = Base64.urlsafe_encode64(cert_hash[:crt].to_pem)
ret_json["#{app}_key"] = Base64.urlsafe_encode64(cert_hash[:key].to_pem)
ret_json
end

def nginx_certs(app,cdomain)
def nginx_certs(app, cdomain)
ret_json = {}
#Check if certs exists in a data bag
nginx_cert_item = data_bag_item("certs",app) rescue nginx_cert_item = {}
# Check if certs exists in a data bag
begin
nginx_cert_item = data_bag_item('certs', app)
rescue
nginx_cert_item = {}
end

if nginx_cert_item.empty?
if !File.exists?("/var/chef/data/data_bag/certs/#{app}.json")
unless File.exist?("/var/chef/data/data_bag/certs/#{app}.json")
# Create S3 certificate
ret_json = create_json_cert(app,cdomain)
system("mkdir -p /var/chef/data/data_bag/certs")
File.open("/var/chef/data/data_bag/certs/#{app}.json", 'w') { |file| file.write(ret_json.to_json) }
ret_json = create_json_cert(app, cdomain)
system('mkdir -p /var/chef/data/data_bag/certs')
File.write("/var/chef/data/data_bag/certs/#{app}.json", ret_json.to_json)
end
# Upload cert to data bag
if File.exists?("/root/.chef/knife.rb")
if File.exist?('/root/.chef/knife.rb')
system("knife data bag from file certs /var/chef/data/data_bag/certs/#{app}.json")
else
Chef::Log.warn("knife command not available, certs databag wont be uploaded")
Chef::Log.warn('knife command not available, certs databag wont be uploaded')
end
else
ret_json = nginx_cert_item
Expand Down
Loading

0 comments on commit 2dd52af

Please sign in to comment.