abiraj 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/abiraj.rb +286 -122
 - metadata +4 -4
 - /data/lib/{securden → abiraj}/version.rb +0 -0
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 07dd79f7c92f15bf9aa690977178a66a52dfc9d7bb050721d3beee183b8b2de3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 64d625886da84d225c3ccdc8cf2e38af4835cb7fd55c7c7e02699fc54b7c2a0f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f75573ba26f415d651d21538fb32e1341d3c9ad417d3bd8e0c7fa63b2603866dd4c00817592e54811256e0f49f800392dc13dbdce9aa264588ead0366517350e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d8824ca8b7af97b590b80cff3d353373e11d013d9109f904f5f1b52f3a6353b6fd3556c59c1e3f8520abf6397eb9cdea319fc10c611da8f1bde431e146ac4ac2
         
     | 
    
        data/lib/abiraj.rb
    CHANGED
    
    | 
         @@ -1,122 +1,286 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "net/http"
         
     | 
| 
       2 
     | 
    
         
            -
            require "json"
         
     | 
| 
       3 
     | 
    
         
            -
            require  
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            module Abiraj
         
     | 
| 
       6 
     | 
    
         
            -
              class Error < StandardError; end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                   
     | 
| 
       13 
     | 
    
         
            -
                   
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
       17 
     | 
    
         
            -
                  when " 
     | 
| 
       18 
     | 
    
         
            -
                    Chef::Log. 
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
       20 
     | 
    
         
            -
                    Chef::Log. 
     | 
| 
       21 
     | 
    
         
            -
                   
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
               
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                   
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
       43 
     | 
    
         
            -
                   
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                   
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
                   
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                   
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                   
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                  Abiraj. 
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                   
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
                   
     | 
| 
       99 
     | 
    
         
            -
                     
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                     
     | 
| 
       108 
     | 
    
         
            -
                     
     | 
| 
       109 
     | 
    
         
            -
                    
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
                       
     | 
| 
       114 
     | 
    
         
            -
                    end
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
                     
     | 
| 
       119 
     | 
    
         
            -
                  end
         
     | 
| 
       120 
     | 
    
         
            -
                end
         
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require "net/http"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "json"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "openssl"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Abiraj
         
     | 
| 
      
 6 
     | 
    
         
            +
              class Error < StandardError; end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              class << self
         
     | 
| 
      
 9 
     | 
    
         
            +
                attr_accessor :server_url, :authtoken, :org, :certificate
         
     | 
| 
      
 10 
     | 
    
         
            +
                def log(message:, level: "info")
         
     | 
| 
      
 11 
     | 
    
         
            +
                  prefix = "[Abiraj] "
         
     | 
| 
      
 12 
     | 
    
         
            +
                  message = message.to_s
         
     | 
| 
      
 13 
     | 
    
         
            +
                  case level.downcase
         
     | 
| 
      
 14 
     | 
    
         
            +
                  when "error"
         
     | 
| 
      
 15 
     | 
    
         
            +
                    Chef::Log.error(prefix + message)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 17 
     | 
    
         
            +
                  when "debug"
         
     | 
| 
      
 18 
     | 
    
         
            +
                    Chef::Log.debug(prefix + message)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  when "warn"
         
     | 
| 
      
 20 
     | 
    
         
            +
                    Chef::Log.warn(prefix + message)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  when "info"
         
     | 
| 
      
 22 
     | 
    
         
            +
                    Chef::Log.info(prefix + message)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              class Init
         
     | 
| 
      
 28 
     | 
    
         
            +
                def initialize(server_url:, authtoken:, org: nil, certificate: nil)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  if server_url.nil? || authtoken.nil? || server_url.strip.empty? || authtoken.strip.empty?
         
     | 
| 
      
 30 
     | 
    
         
            +
                    Abiraj.log(message: "Server URL and authtoken are required to initialize Abiraj", level: "error")
         
     | 
| 
      
 31 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  unless server_url.start_with?("http://", "https://")
         
     | 
| 
      
 35 
     | 
    
         
            +
                    Abiraj.log(message: "Invalid server URL. It must start with http:// or https://", level: "error")
         
     | 
| 
      
 36 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  Abiraj.server_url = server_url.strip
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Abiraj.authtoken = authtoken.strip
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Abiraj.org = org unless org.to_s.strip.empty? || org.nil?
         
     | 
| 
      
 42 
     | 
    
         
            +
                  Abiraj.certificate = certificate
         
     | 
| 
      
 43 
     | 
    
         
            +
                  Abiraj.log(message: "Abiraj initialized successfully")
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              class Account
         
     | 
| 
      
 48 
     | 
    
         
            +
                def self.get(account_id: nil, account_name: nil, account_title: nil)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 50 
     | 
    
         
            +
                    unless Abiraj.server_url && Abiraj.authtoken
         
     | 
| 
      
 51 
     | 
    
         
            +
                      Abiraj.log(message: "Abiraj is not initialized. Please initialize before using.", level: "error")
         
     | 
| 
      
 52 
     | 
    
         
            +
                      return nil
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    Abiraj.log(message: "Fetching account data")
         
     | 
| 
      
 56 
     | 
    
         
            +
                    params = {}
         
     | 
| 
      
 57 
     | 
    
         
            +
                    params["account_id"] = account_id.to_s if account_id
         
     | 
| 
      
 58 
     | 
    
         
            +
                    params["account_name"] = account_name unless account_name.to_s.strip.empty?
         
     | 
| 
      
 59 
     | 
    
         
            +
                    params["account_title"] = account_title unless account_title.to_s.strip.empty?
         
     | 
| 
      
 60 
     | 
    
         
            +
                    account = self.new.send(:get_request, params, "/api/get_account_details_dict")
         
     | 
| 
      
 61 
     | 
    
         
            +
                    if account
         
     | 
| 
      
 62 
     | 
    
         
            +
                      Abiraj.log(message: "Account data fetched successfully")
         
     | 
| 
      
 63 
     | 
    
         
            +
                      return account
         
     | 
| 
      
 64 
     | 
    
         
            +
                    else
         
     | 
| 
      
 65 
     | 
    
         
            +
                      Abiraj.log(message: "Unable to fetch account data.", level: "error")
         
     | 
| 
      
 66 
     | 
    
         
            +
                      return nil
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 70 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to fetch account data: #{e.message}", level: "error")
         
     | 
| 
      
 71 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                protected
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                def get_request(params, endpoint)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  Abiraj.log(message: "Raising API request to Abiraj server.")
         
     | 
| 
      
 79 
     | 
    
         
            +
                  uri = URI(Abiraj.server_url + endpoint)
         
     | 
| 
      
 80 
     | 
    
         
            +
                  uri.query = URI.encode_www_form(params) unless params.empty?
         
     | 
| 
      
 81 
     | 
    
         
            +
                  http = set_http(uri)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  request = Net::HTTP::Get.new(uri)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  request["authtoken"] = Abiraj.authtoken
         
     | 
| 
      
 84 
     | 
    
         
            +
                  if Abiraj.org && !Abiraj.org.strip.empty?
         
     | 
| 
      
 85 
     | 
    
         
            +
                    request["org"] = Abiraj.org
         
     | 
| 
      
 86 
     | 
    
         
            +
                  end
         
     | 
| 
      
 87 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 88 
     | 
    
         
            +
                    response = http.request(request)
         
     | 
| 
      
 89 
     | 
    
         
            +
                    response = JSON.parse(response.body)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    if response['status_code'] == 200
         
     | 
| 
      
 91 
     | 
    
         
            +
                      return response
         
     | 
| 
      
 92 
     | 
    
         
            +
                    else
         
     | 
| 
      
 93 
     | 
    
         
            +
                      Abiraj.log(message: "#{response['status_code']}: #{response['message']}", level: "error")
         
     | 
| 
      
 94 
     | 
    
         
            +
                    end
         
     | 
| 
      
 95 
     | 
    
         
            +
                  rescue JSON::ParserError => e
         
     | 
| 
      
 96 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to parse JSON response: #{e.message}", level: "error")
         
     | 
| 
      
 97 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 98 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 99 
     | 
    
         
            +
                    Abiraj.log(message: "HTTP request failed: #{e.message}", level: "error")
         
     | 
| 
      
 100 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                def set_http(uri)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 106 
     | 
    
         
            +
                    Abiraj.log(message: "Setting up HTTP connection.")
         
     | 
| 
      
 107 
     | 
    
         
            +
                    
         
     | 
| 
      
 108 
     | 
    
         
            +
                    http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 109 
     | 
    
         
            +
                    http.use_ssl = uri.scheme == "https"
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                    if uri.scheme == "https"
         
     | 
| 
      
 112 
     | 
    
         
            +
                      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
         
     | 
| 
      
 113 
     | 
    
         
            +
                      configure_ssl(http, uri)
         
     | 
| 
      
 114 
     | 
    
         
            +
                    end
         
     | 
| 
      
 115 
     | 
    
         
            +
                    http
         
     | 
| 
      
 116 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 117 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to set HTTP connection: #{e.message}", level: "error")
         
     | 
| 
      
 118 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 119 
     | 
    
         
            +
                  end
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                def configure_ssl(http, uri)
         
     | 
| 
      
 123 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 124 
     | 
    
         
            +
                    if Abiraj.server_url.start_with?("https://")
         
     | 
| 
      
 125 
     | 
    
         
            +
                      if Abiraj.certificate
         
     | 
| 
      
 126 
     | 
    
         
            +
                        handle_ssl_certificate(http)
         
     | 
| 
      
 127 
     | 
    
         
            +
                      else
         
     | 
| 
      
 128 
     | 
    
         
            +
                        Abiraj.log(message: "No SSL certificate provided. Attempting to fetch from server.")
         
     | 
| 
      
 129 
     | 
    
         
            +
                        fetch_and_set_server_certificate(http, uri)
         
     | 
| 
      
 130 
     | 
    
         
            +
                      end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    end
         
     | 
| 
      
 132 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 133 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to configure SSL: #{e.message}", level: "error")
         
     | 
| 
      
 134 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 135 
     | 
    
         
            +
                  end
         
     | 
| 
      
 136 
     | 
    
         
            +
                end
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                def handle_ssl_certificate(http)
         
     | 
| 
      
 139 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 140 
     | 
    
         
            +
                    Abiraj.log(message: "Adding SSL certificate.")
         
     | 
| 
      
 141 
     | 
    
         
            +
                    if Abiraj.certificate.start_with?("-----BEGIN CERTIFICATE-----")
         
     | 
| 
      
 142 
     | 
    
         
            +
                      cert_object = OpenSSL::X509::Certificate.new(Abiraj.certificate)
         
     | 
| 
      
 143 
     | 
    
         
            +
                      http.cert_store = OpenSSL::X509::Store.new
         
     | 
| 
      
 144 
     | 
    
         
            +
                      http.cert_store.add_cert(cert_object)
         
     | 
| 
      
 145 
     | 
    
         
            +
                    elsif File.exist?(Abiraj.certificate)
         
     | 
| 
      
 146 
     | 
    
         
            +
                      http.ca_file = Abiraj.certificate
         
     | 
| 
      
 147 
     | 
    
         
            +
                    else
         
     | 
| 
      
 148 
     | 
    
         
            +
                      Abiraj.log(message: "Invalid certificate value or file path", level: "error")
         
     | 
| 
      
 149 
     | 
    
         
            +
                      return nil
         
     | 
| 
      
 150 
     | 
    
         
            +
                    end
         
     | 
| 
      
 151 
     | 
    
         
            +
                    http
         
     | 
| 
      
 152 
     | 
    
         
            +
                  rescue OpenSSL::X509::CertificateError => e
         
     | 
| 
      
 153 
     | 
    
         
            +
                    Abiraj.log(message: "Invalid certificate format: #{e.message}", level: "error")
         
     | 
| 
      
 154 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 155 
     | 
    
         
            +
                  end
         
     | 
| 
      
 156 
     | 
    
         
            +
                end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                def fetch_and_set_server_certificate(http, uri)
         
     | 
| 
      
 159 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 160 
     | 
    
         
            +
                    tcp_socket = TCPSocket.new(uri.host, uri.port || 443)
         
     | 
| 
      
 161 
     | 
    
         
            +
                    ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket)
         
     | 
| 
      
 162 
     | 
    
         
            +
                    ssl_socket.connect
         
     | 
| 
      
 163 
     | 
    
         
            +
                    server_cert = ssl_socket.peer_cert
         
     | 
| 
      
 164 
     | 
    
         
            +
                    ssl_socket.close
         
     | 
| 
      
 165 
     | 
    
         
            +
                    tcp_socket.close
         
     | 
| 
      
 166 
     | 
    
         
            +
                    http.cert_store = OpenSSL::X509::Store.new
         
     | 
| 
      
 167 
     | 
    
         
            +
                    http.cert_store.add_cert(server_cert)
         
     | 
| 
      
 168 
     | 
    
         
            +
                    Abiraj.log(message: "Certificate fetched and added to HTTP connection.")
         
     | 
| 
      
 169 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 170 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to fetch SSL certificate: #{e.message}. Disabling SSL verification.", level: "warn")
         
     | 
| 
      
 171 
     | 
    
         
            +
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 172 
     | 
    
         
            +
                  end
         
     | 
| 
      
 173 
     | 
    
         
            +
                end
         
     | 
| 
      
 174 
     | 
    
         
            +
              end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
              class Accounts
         
     | 
| 
      
 177 
     | 
    
         
            +
                def self.get(account_ids: [])
         
     | 
| 
      
 178 
     | 
    
         
            +
                  if Abiraj.server_url.nil? || Abiraj.authtoken.nil? || Abiraj.server_url.strip.empty? || Abiraj.authtoken.strip.empty?
         
     | 
| 
      
 179 
     | 
    
         
            +
                    Abiraj.log(message: "Abiraj is not initialized. Please initialize before using.", level: "error")
         
     | 
| 
      
 180 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 181 
     | 
    
         
            +
                  end
         
     | 
| 
      
 182 
     | 
    
         
            +
                  securden_accounts = self.new.send(:post_request, account_ids, "/api/get_multiple_accounts_details")
         
     | 
| 
      
 183 
     | 
    
         
            +
                end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
                protected
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                def post_request(data, request_path)
         
     | 
| 
      
 188 
     | 
    
         
            +
                  Abiraj.log(message: "Raising API request to Abiraj server.")
         
     | 
| 
      
 189 
     | 
    
         
            +
                  payload = { "account_ids": data }
         
     | 
| 
      
 190 
     | 
    
         
            +
                  uri = URI(Abiraj.server_url + request_path)
         
     | 
| 
      
 191 
     | 
    
         
            +
                  http = set_http(uri)
         
     | 
| 
      
 192 
     | 
    
         
            +
                  request = Net::HTTP::Post.new(uri)
         
     | 
| 
      
 193 
     | 
    
         
            +
                  request["authtoken"] = Abiraj.authtoken
         
     | 
| 
      
 194 
     | 
    
         
            +
                  request["Content-Type"] = "application/json" # Set the content type for JSON data
         
     | 
| 
      
 195 
     | 
    
         
            +
                  request["org"] = Abiraj.org if Abiraj.org && !Abiraj.org.strip.empty?
         
     | 
| 
      
 196 
     | 
    
         
            +
                  request.body = payload.to_json unless payload.nil? || payload.empty?
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 199 
     | 
    
         
            +
                    response = http.request(request)
         
     | 
| 
      
 200 
     | 
    
         
            +
                    response = JSON.parse(response.body)
         
     | 
| 
      
 201 
     | 
    
         
            +
                    if response['status_code'] == 200
         
     | 
| 
      
 202 
     | 
    
         
            +
                      return response
         
     | 
| 
      
 203 
     | 
    
         
            +
                    else
         
     | 
| 
      
 204 
     | 
    
         
            +
                      Abiraj.log(message: "#{response['status_code']}: #{response['message']}", level: "error")
         
     | 
| 
      
 205 
     | 
    
         
            +
                    end
         
     | 
| 
      
 206 
     | 
    
         
            +
                  rescue JSON::ParserError => e
         
     | 
| 
      
 207 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to parse JSON response: #{e.message}", level: "error")
         
     | 
| 
      
 208 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 209 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 210 
     | 
    
         
            +
                    Abiraj.log(message: "HTTP request failed: #{e.message}", level: "error")
         
     | 
| 
      
 211 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 212 
     | 
    
         
            +
                  end
         
     | 
| 
      
 213 
     | 
    
         
            +
                end
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                def set_http(uri)
         
     | 
| 
      
 216 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 217 
     | 
    
         
            +
                    Abiraj.log(message: "Setting up HTTP connection.")
         
     | 
| 
      
 218 
     | 
    
         
            +
                    
         
     | 
| 
      
 219 
     | 
    
         
            +
                    http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 220 
     | 
    
         
            +
                    http.use_ssl = uri.scheme == "https"
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
                    if uri.scheme == "https"
         
     | 
| 
      
 223 
     | 
    
         
            +
                      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
         
     | 
| 
      
 224 
     | 
    
         
            +
                      configure_ssl(http, uri)
         
     | 
| 
      
 225 
     | 
    
         
            +
                    end
         
     | 
| 
      
 226 
     | 
    
         
            +
                    http
         
     | 
| 
      
 227 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 228 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to set HTTP connection: #{e.message}", level: "error")
         
     | 
| 
      
 229 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 230 
     | 
    
         
            +
                  end
         
     | 
| 
      
 231 
     | 
    
         
            +
                end
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
                def configure_ssl(http, uri)
         
     | 
| 
      
 234 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 235 
     | 
    
         
            +
                    if Abiraj.server_url.start_with?("https://")
         
     | 
| 
      
 236 
     | 
    
         
            +
                      if Abiraj.certificate
         
     | 
| 
      
 237 
     | 
    
         
            +
                        handle_ssl_certificate(http)
         
     | 
| 
      
 238 
     | 
    
         
            +
                      else
         
     | 
| 
      
 239 
     | 
    
         
            +
                        Abiraj.log(message: "No SSL certificate provided. Attempting to fetch from server.")
         
     | 
| 
      
 240 
     | 
    
         
            +
                        fetch_and_set_server_certificate(http, uri)
         
     | 
| 
      
 241 
     | 
    
         
            +
                      end
         
     | 
| 
      
 242 
     | 
    
         
            +
                    end
         
     | 
| 
      
 243 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 244 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to configure SSL: #{e.message}", level: "error")
         
     | 
| 
      
 245 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 246 
     | 
    
         
            +
                  end
         
     | 
| 
      
 247 
     | 
    
         
            +
                end
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
                def handle_ssl_certificate(http)
         
     | 
| 
      
 250 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 251 
     | 
    
         
            +
                    Abiraj.log(message: "Adding SSL certificate.")
         
     | 
| 
      
 252 
     | 
    
         
            +
                    if Abiraj.certificate.start_with?("-----BEGIN CERTIFICATE-----")
         
     | 
| 
      
 253 
     | 
    
         
            +
                      cert_object = OpenSSL::X509::Certificate.new(Abiraj.certificate)
         
     | 
| 
      
 254 
     | 
    
         
            +
                      http.cert_store = OpenSSL::X509::Store.new
         
     | 
| 
      
 255 
     | 
    
         
            +
                      http.cert_store.add_cert(cert_object)
         
     | 
| 
      
 256 
     | 
    
         
            +
                    elsif File.exist?(Abiraj.certificate)
         
     | 
| 
      
 257 
     | 
    
         
            +
                      http.ca_file = Abiraj.certificate
         
     | 
| 
      
 258 
     | 
    
         
            +
                    else
         
     | 
| 
      
 259 
     | 
    
         
            +
                      Abiraj.log(message: "Invalid certificate value or file path", level: "error")
         
     | 
| 
      
 260 
     | 
    
         
            +
                      return nil
         
     | 
| 
      
 261 
     | 
    
         
            +
                    end
         
     | 
| 
      
 262 
     | 
    
         
            +
                    http
         
     | 
| 
      
 263 
     | 
    
         
            +
                  rescue OpenSSL::X509::CertificateError => e
         
     | 
| 
      
 264 
     | 
    
         
            +
                    Abiraj.log(message: "Invalid certificate format: #{e.message}", level: "error")
         
     | 
| 
      
 265 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 266 
     | 
    
         
            +
                  end
         
     | 
| 
      
 267 
     | 
    
         
            +
                end
         
     | 
| 
      
 268 
     | 
    
         
            +
             
     | 
| 
      
 269 
     | 
    
         
            +
                def fetch_and_set_server_certificate(http, uri)
         
     | 
| 
      
 270 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 271 
     | 
    
         
            +
                    tcp_socket = TCPSocket.new(uri.host, uri.port || 443)
         
     | 
| 
      
 272 
     | 
    
         
            +
                    ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket)
         
     | 
| 
      
 273 
     | 
    
         
            +
                    ssl_socket.connect
         
     | 
| 
      
 274 
     | 
    
         
            +
                    server_cert = ssl_socket.peer_cert
         
     | 
| 
      
 275 
     | 
    
         
            +
                    ssl_socket.close
         
     | 
| 
      
 276 
     | 
    
         
            +
                    tcp_socket.close
         
     | 
| 
      
 277 
     | 
    
         
            +
                    http.cert_store = OpenSSL::X509::Store.new
         
     | 
| 
      
 278 
     | 
    
         
            +
                    http.cert_store.add_cert(server_cert)
         
     | 
| 
      
 279 
     | 
    
         
            +
                    Abiraj.log(message: "Certificate fetched and added to HTTP connection.")
         
     | 
| 
      
 280 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 281 
     | 
    
         
            +
                    Abiraj.log(message: "Failed to fetch SSL certificate: #{e.message}. Disabling SSL verification.", level: "warn")
         
     | 
| 
      
 282 
     | 
    
         
            +
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 283 
     | 
    
         
            +
                  end
         
     | 
| 
      
 284 
     | 
    
         
            +
                end
         
     | 
| 
      
 285 
     | 
    
         
            +
              end
         
     | 
| 
      
 286 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,25 +1,25 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: abiraj
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Abiraj
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2025-01-01 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: This plugin sends a GET request to an API to fetch account data (passwords,
         
     | 
| 
       14 
14 
     | 
    
         
             
              etc.) based on the account ID, name, and title.
         
     | 
| 
       15 
15 
     | 
    
         
             
            email:
         
     | 
| 
       16 
     | 
    
         
            -
            -  
     | 
| 
      
 16 
     | 
    
         
            +
            - devops-support@abiraj.com
         
     | 
| 
       17 
17 
     | 
    
         
             
            executables: []
         
     | 
| 
       18 
18 
     | 
    
         
             
            extensions: []
         
     | 
| 
       19 
19 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       20 
20 
     | 
    
         
             
            files:
         
     | 
| 
       21 
21 
     | 
    
         
             
            - lib/abiraj.rb
         
     | 
| 
       22 
     | 
    
         
            -
            - lib/ 
     | 
| 
      
 22 
     | 
    
         
            +
            - lib/abiraj/version.rb
         
     | 
| 
       23 
23 
     | 
    
         
             
            homepage: 
         
     | 
| 
       24 
24 
     | 
    
         
             
            licenses: []
         
     | 
| 
       25 
25 
     | 
    
         
             
            metadata: {}
         
     | 
| 
         
            File without changes
         
     |