Class: Spaceship::ConnectAPI::Certificate

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
spaceship/lib/spaceship/connect_api/models/certificate.rb

Defined Under Namespace

Modules: CertificateType

Instance Attribute Summary collapse

Attributes included from Model

#id, #reverse_attr_map

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#attr_mapping, included, #initialize, #reverse_attr_mapping, #to_json, #update_attributes

Instance Attribute Details

#certificate_contentObject

Returns the value of attribute certificate_content.



10
11
12
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 10

def certificate_content
  @certificate_content
end

#certificate_typeObject

Returns the value of attribute certificate_type.



16
17
18
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 16

def certificate_type
  @certificate_type
end

#display_nameObject

Returns the value of attribute display_name.



11
12
13
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 11

def display_name
  @display_name
end

#expiration_dateObject

Returns the value of attribute expiration_date.



12
13
14
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 12

def expiration_date
  @expiration_date
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 13

def name
  @name
end

#platformObject

Returns the value of attribute platform.



14
15
16
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 14

def platform
  @platform
end

#requester_emailObject

Returns the value of attribute requester_email.



17
18
19
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 17

def requester_email
  @requester_email
end

#requester_first_nameObject

Returns the value of attribute requester_first_name.



18
19
20
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 18

def requester_first_name
  @requester_first_name
end

#requester_last_nameObject

Returns the value of attribute requester_last_name.



19
20
21
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 19

def requester_last_name
  @requester_last_name
end

#serial_numberObject

Returns the value of attribute serial_number.



15
16
17
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 15

def serial_number
  @serial_number
end

Class Method Details

.all(client: nil, filter: {}, includes: nil, fields: nil, limit: Spaceship::ConnectAPI::MAX_OBJECTS_PER_PAGE_LIMIT, sort: nil) ⇒ Object

API



82
83
84
85
86
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 82

def self.all(client: nil, filter: {}, includes: nil, fields: nil, limit: Spaceship::ConnectAPI::MAX_OBJECTS_PER_PAGE_LIMIT, sort: nil)
  client ||= Spaceship::ConnectAPI
  resps = client.get_certificates(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort).all_pages
  return resps.flat_map(&:to_models)
end

.create(client: nil, certificate_type: nil, csr_content: nil) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 88

def self.create(client: nil, certificate_type: nil, csr_content: nil)
  client ||= Spaceship::ConnectAPI
  attributes = {
    certificateType: certificate_type,
    csrContent: csr_content
  }
  resp = client.post_certificate(attributes: attributes)
  return resp.to_models.first
end

.create_certificate_signing_requestObject

Create a new cert signing request that can be used to generate a new certificate

Examples:

Create a new certificate signing request
csr, pkey = Spaceship.certificate.create_certificate_signing_request

# Use the signing request to create a new distribution certificate
Spaceship.certificate.production.create!(csr: csr)


66
67
68
69
70
71
72
73
74
75
76
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 66

def self.create_certificate_signing_request
  key = OpenSSL::PKey::RSA.new(2048)
  csr = OpenSSL::X509::Request.new
  csr.version = 0
  csr.subject = OpenSSL::X509::Name.new([
                                          ['CN', 'PEM', OpenSSL::ASN1::UTF8STRING]
                                        ])
  csr.public_key = key.public_key
  csr.sign(key, OpenSSL::Digest::SHA256.new)
  return [csr, key]
end

.get(client: nil, certificate_id: nil, includes: nil) ⇒ Object



98
99
100
101
102
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 98

def self.get(client: nil, certificate_id: nil, includes: nil)
  client ||= Spaceship::ConnectAPI
  resp = client.get_certificate(certificate_id: certificate_id, includes: includes)
  return resp.to_models.first
end

.typeObject



50
51
52
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 50

def self.type
  return "certificates"
end

Instance Method Details

#delete!(client: nil) ⇒ Object



104
105
106
107
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 104

def delete!(client: nil)
  client ||= Spaceship::ConnectAPI
  client.delete_certificate(certificate_id: id)
end

#valid?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 54

def valid?
  Time.parse(expiration_date) > Time.now
end