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
- CRT_FILES_URI =
URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_FILES_PATH)
- CRT_PROFILES_URI =
URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_PROFILES_PATH)
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
20 21 22 23 24 25 |
# File 'lib/bim/action/ssl.rb', line 20 def bundles cond = proc { |item| item['isBundle'] == 'true' } select_map(CRT_FILES_URI, cond) do |item| { 'name' => item['name'].split('.')[0...-1].join('.') } end end |
.create_ssl_profile(profilename, chain) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bim/action/ssl.rb', line 66 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
33 34 35 36 37 |
# File 'lib/bim/action/ssl.rb', line 33 def detail(profile_name) specify(CRT_PROFILES_URI) do |item| item['name'] == profile_name || item['fullPath'] == profile_name end end |
.install(type, crt_name, local_file_path) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bim/action/ssl.rb', line 51 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
27 28 29 30 31 |
# File 'lib/bim/action/ssl.rb', line 27 def profiles map(CRT_PROFILES_URI) do |item| { 'name' => item['name'], 'fullPath' => item['fullPath'], 'key' => item['key'], 'chain' => item['chain'] } end end |
.replace(old_profilename, new_profilename, test = nil) ⇒ Object
rubocop:disable Metrics/AbcSize
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/bim/action/ssl.rb', line 83 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
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bim/action/ssl.rb', line 39 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 |