Class: Bim::Action::SSL
- Inherits:
-
Object
- Object
- Bim::Action::SSL
- Extended by:
- Util
- Defined in:
- lib/bim/action/ssl.rb
Overview
SSL class used by Bim::Subcommands::SSL
Constant Summary collapse
- UPLOAD_PATH =
'/mgmt/shared/file-transfer/uploads/'.freeze
- INSTALL_PATH =
{ key: '/mgmt/tm/sys/crypto/key', crt: '/mgmt/tm/sys/crypto/cert' }.freeze
- CREATE_SSL_PROFILE_PATH =
'/mgmt/tm/ltm/profile/clientSsl'.freeze
- VS_PATH =
'/mgmt/tm/ltm/virtual'.freeze
- CRT_FILES_PATH =
'/mgmt/tm/sys/file/sslCert'.freeze
- CRT_PROFILES_PATH =
'/mgmt/tm/ltm/profile/client-ssl'.freeze
Class Method Summary collapse
- .bundles ⇒ Object
- .create_ssl_profile(profilename, chain) ⇒ Object
- .detail(profile_name) ⇒ Object
- .install(type, crt_name, local_file_path) ⇒ Object
- .profiles ⇒ Object
-
.replace(old_profilename, new_profilename, test = nil) ⇒ Object
rubocop:disable Metrics/AbcSize.
- .upload(filepath) ⇒ Object
Class Method Details
.bundles ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/bim/action/ssl.rb', line 18 def bundles uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_FILES_PATH) JSON .parse(get_body(uri))['items'] .select { |item| item['isBundle'] == 'true' } .map do |item| { 'name' => item['name'].split('.')[0...-1].join('.') } end.to_json end |
.create_ssl_profile(profilename, chain) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bim/action/ssl.rb', line 72 def create_ssl_profile(profilename, chain) uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CREATE_SSL_PROFILE_PATH) j = { 'name' => profilename, 'ciphers' => 'DEFAULT:!SSLv3', 'certKeyChain' => [ { 'name' => 'default', 'key' => "#{profilename}.key", 'cert' => "#{profilename}.crt", 'chain' => "#{chain}.crt" } ] }.to_json req = request(uri, Bim::AUTH, 'application/json', 'POST', j) http(uri).request(req).body end |
.detail(profile_name) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/bim/action/ssl.rb', line 35 def detail(profile_name) uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_PROFILES_PATH) JSON .parse(get_body(uri))['items'] .select { |item| item['name'] == profile_name || item['fullPath'] == profile_name } .map do |item| { 'name' => item['name'], 'fullPath' => item['fullPath'], 'key' => item['key'], 'chain' => item['chain'] } end.to_json end |
.install(type, crt_name, local_file_path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bim/action/ssl.rb', line 57 def install(type, crt_name, local_file_path) uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::INSTALL_PATH[type.to_sym]) req = request( uri, Bim::AUTH, 'application/json', 'POST', { 'command' => 'install', 'name' => crt_name, 'from-local-file' => local_file_path }.to_json ) http(uri).request(req).body end |
.profiles ⇒ Object
28 29 30 31 32 33 |
# File 'lib/bim/action/ssl.rb', line 28 def profiles uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_PROFILES_PATH) JSON.parse(get_body(uri))['items'].map do |item| { 'name' => item['name'], 'fullPath' => item['fullPath'], 'key' => item['key'], 'chain' => item['chain'] } end.to_json end |
.replace(old_profilename, new_profilename, test = nil) ⇒ Object
rubocop:disable Metrics/AbcSize
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/bim/action/ssl.rb', line 89 def replace(old_profilename, new_profilename, test = nil) result = { target_vs: [], change_vs: [], fail_vs: [] } JSON.parse(vs_list)['items'].each do |vs| next if test && vs['name'] != Bim::TEST_VS names = JSON.parse(profiles_items(vs['profilesReference']['link']))['items'].map { |p| p['name'] } next unless names.include?(old_profilename) # can not update only diff. old_names = names.map { |name| "/Common/#{name}" } names.delete(old_profilename) && names.push(new_profilename) names = names.map { |name| "/Common/#{name}" } next unless yes_or_no?(output_msg(vs['name'], old_names, names)) result[:target_vs] << vs['name'] res = update_profiles(vs['selfLink'], names) res.code == '200' ? result[:change_vs] << vs['name'] : result[:fail_vs] << vs['name'] end result.to_json end |
.upload(filepath) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bim/action/ssl.rb', line 45 def upload(filepath) f = File.read(filepath) uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::UPLOAD_PATH, File.basename(filepath)) req = request(uri, Bim::AUTH, 'application/octet-stream', 'POST', f) do |req_in| req_in['Content-Length'] = f.size req_in['Content-Range'] = "0-#{f.size - 1}/#{f.size}" req_in end http(uri).request(req).body end |