Class: Occi::Api::Client::AuthnUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/occi/api/client/authn_utils.rb

Constant Summary collapse

CERT_REGEXP =
/\n?(-----BEGIN CERTIFICATE-----\n.+?\n-----END CERTIFICATE-----)\n/m

Class Method Summary collapse

Class Method Details

.certs_to_file_ary(ca_file) ⇒ Array<String>

Reads X.509 certificates from a file to an array.

Examples:

AuthnUtils.certs_to_file_ary "~/.globus/usercert.pem"
  # => [#<String>, #<String>, ...]

Parameters:

  • ca_file (String)

    Path to a PEM file containing certificates

Returns:

  • (Array<String>)

    An array of read certificates

Raises:

  • (ArgumentError)

15
16
17
18
19
20
21
22
# File 'lib/occi/api/client/authn_utils.rb', line 15

def self.certs_to_file_ary(ca_file)
  raise ArgumentError, "PKCS12 file #{ca_file.inspect} " \
                       "is not supported in VOMS mode!" if /\A(.)+\.p12\z/ =~ ca_file
  certs_str = File.open(ca_file).read

  certs_ary = certs_str.scan(CERT_REGEXP)
  certs_ary ? certs_ary.flatten : []
end