func (p *AWSProvider) certificateListACM() (structs.Certificates, error) { certs := structs.Certificates{} ares, err := p.acm().ListCertificates(nil) if err != nil { return nil, err } for _, cert := range ares.CertificateSummaryList { parts := strings.Split(*cert.CertificateArn, "-") id := fmt.Sprintf("acm-%s", parts[len(parts)-1]) c := structs.Certificate{ Id: id, Domain: *cert.DomainName, } res, err := p.acm().DescribeCertificate(&acm.DescribeCertificateInput{ CertificateArn: cert.CertificateArn, }) if err != nil { return nil, err } if res.Certificate.NotAfter != nil { c.Expiration = *res.Certificate.NotAfter } certs = append(certs, c) } return certs, nil }
func (p *AWSProvider) CertificateList() (structs.Certificates, error) { res, err := p.iam().ListServerCertificates(nil) if err != nil { return nil, err } certs := structs.Certificates{} for _, cert := range res.ServerCertificateMetadataList { res, err := p.iam().GetServerCertificate(&iam.GetServerCertificateInput{ ServerCertificateName: cert.ServerCertificateName, }) if err != nil { return nil, err } pem, _ := pem.Decode([]byte(*res.ServerCertificate.CertificateBody)) if err != nil { return nil, err } c, err := x509.ParseCertificate(pem.Bytes) if err != nil { return nil, err } certs = append(certs, structs.Certificate{ Id: *cert.ServerCertificateName, Domain: c.Subject.CommonName, Expiration: *cert.Expiration, }) } ares, err := p.acm().ListCertificates(nil) if err != nil { return nil, err } for _, cert := range ares.CertificateSummaryList { parts := strings.Split(*cert.CertificateArn, "-") id := fmt.Sprintf("acm-%s", parts[len(parts)-1]) c := structs.Certificate{ Id: id, Domain: *cert.DomainName, } res, err := p.acm().DescribeCertificate(&acm.DescribeCertificateInput{ CertificateArn: cert.CertificateArn, }) if err != nil { return nil, err } if res.Certificate.NotAfter != nil { c.Expiration = *res.Certificate.NotAfter } certs = append(certs, c) } return certs, nil }