Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.0.8 #10

Merged
merged 13 commits into from
May 30, 2024
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
cookbook-nginx CHANGELOG
==========================
===============

## 0.0.8
- Miguel Negron
- [717936a] lint avoid use constants for OpenSSL
- [7d575d6] lint file.write instead of file.open
- [fc2b48b] lint resources 2
- [1862ff6] lint solo
- [4311a8a] lint providers 2
- [7720b9b] lint helper
- [b4fdc17] lint providers
- [b0618e1] lint resources
- [2b065d7] lint recipes
- [b12293f] lint attributes
- [42a9d18] Update metadata.rb

This file is used to list changes made in each version of the nginx cookbook.

Expand Down
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["nginx"]["registered"] = false
# Flags
default['nginx']['registered'] = false
62 changes: 33 additions & 29 deletions resources/libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,63 @@ module Helper
require 'resolv'
require 'base64'


def create_cert(cn)
# Return a hash with private key and certificate in x509 format
key = OpenSSL::PKey::RSA.new 4096
name = OpenSSL::X509::Name.parse "CN=#{cn}/DC=redborder"
cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
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.")
key = OpenSSL::PKey::RSA.new 4096
name = OpenSSL::X509::Name.parse "CN=#{cn}/DC=redborder"
cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
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.')
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
end
ret_json
end

end
end
9 changes: 4 additions & 5 deletions resources/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name 'nginx'
maintainer 'Juan J. Prieto'
maintainer_email 'jjprieto@redborder.com'
license 'All rights reserved'
maintainer 'Eneo Tecnología S.L.'
maintainer_email 'git@redborder.com'
license 'AGPL-3.0'
description 'Installs/Configures cookbook-nginx'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.0.7'
version '0.0.8'
Loading
Loading