Class: Spaceship::ConnectAPI::Certificate
- Inherits:
-
Object
- Object
- Spaceship::ConnectAPI::Certificate
- Includes:
- Model
- Defined in:
- spaceship/lib/spaceship/connect_api/models/certificate.rb
Defined Under Namespace
Modules: CertificateType
Constant Summary collapse
- UNSUPPORTED_CERTIFICATE_TYPE_FILTERS =
Certificate types not supported by the App Store Connect API. api.appstoreconnect.apple.com/v1/certificates?filter[certificateType]=DEVELOPER_ID_APPLICATION_G2 Radar: FB21181137.
[ CertificateType::DEVELOPER_ID_APPLICATION_G2 ]
Instance Attribute Summary collapse
-
#certificate_content ⇒ Object
Returns the value of attribute certificate_content.
-
#certificate_type ⇒ Object
Returns the value of attribute certificate_type.
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#requester_email ⇒ Object
Returns the value of attribute requester_email.
-
#requester_first_name ⇒ Object
Returns the value of attribute requester_first_name.
-
#requester_last_name ⇒ Object
Returns the value of attribute requester_last_name.
-
#serial_number ⇒ Object
Returns the value of attribute serial_number.
Attributes included from Model
Class Method Summary collapse
- .all(client: nil, filter: {}, includes: nil, fields: nil, limit: Spaceship::ConnectAPI::MAX_OBJECTS_PER_PAGE_LIMIT, sort: nil) ⇒ Object
- .create(client: nil, certificate_type: nil, csr_content: nil) ⇒ Object
-
.create_certificate_signing_request ⇒ Object
Create a new cert signing request that can be used to generate a new certificate.
- .get(client: nil, certificate_id: nil, includes: nil) ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
Methods included from Model
#attr_mapping, included, #initialize, #reverse_attr_mapping, #to_json, #update_attributes
Instance Attribute Details
#certificate_content ⇒ Object
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_type ⇒ Object
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_name ⇒ Object
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_date ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 13 def name @name end |
#platform ⇒ Object
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_email ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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_number ⇒ Object
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
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 115 116 117 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 90 def self.all(client: nil, filter: {}, includes: nil, fields: nil, limit: Spaceship::ConnectAPI::MAX_OBJECTS_PER_PAGE_LIMIT, sort: nil) client ||= Spaceship::ConnectAPI new_filter = filter.dup has_unsupported_cert_types_filter = filter[:certificateType] && UNSUPPORTED_CERTIFICATE_TYPE_FILTERS.any? { |type| filter[:certificateType].include?(type) } # If the filter contains unsupported certificate types: # - remove the certificateType filter completely and fetch all certificates # - filter fetched certificates later by the given certificate types if has_unsupported_cert_types_filter new_filter[:certificateType] = nil end new_filter.compact! resps = client.get_certificates(filter: new_filter, includes: includes, fields: fields, limit: limit, sort: sort).all_pages certs = resps.flat_map(&:to_models) if has_unsupported_cert_types_filter # Filter fetched certificates by the given certificate types if we encountered unsupported certificate types in the filter previously. certs.select! do |cert| filter[:certificateType].include?(cert.certificate_type) end end return certs end |
.create(client: nil, certificate_type: nil, csr_content: nil) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 119 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_request ⇒ Object
Create a new cert signing request that can be used to generate a new certificate
67 68 69 70 71 72 73 74 75 76 77 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 67 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
129 130 131 132 133 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 129 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 |
.type ⇒ Object
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
135 136 137 138 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 135 def delete!(client: nil) client ||= Spaceship::ConnectAPI client.delete_certificate(certificate_id: id) end |
#valid? ⇒ Boolean
54 55 56 57 |
# File 'spaceship/lib/spaceship/connect_api/models/certificate.rb', line 54 def valid? return false if expiration_date.nil? || expiration_date.empty? Time.parse(expiration_date) > Time.now end |