func (v *Issuer) Issue(ctx context.Context, commonName string, conf *certify.CertConfig) (*tls.Certificate, error) {
	if v.cli == nil { // Could be set by FromClient
		err := v.connect(ctx)
		if err != nil {
			return nil, err
		}
	}

	// Convert Token to AuthMethod, if no AuthMethod set,
	// for backwards compatibility.
	if v.AuthMethod == nil {
		v.AuthMethod = ConstantToken(v.Token)
	}

	csrPEM, keyPEM, err := csr.FromCertConfig(commonName, conf)
	if err != nil {
		return nil, err
	}

	opts := csrOpts{
		CSR:               string(csrPEM),
		CommonName:        commonName,
		ExcludeCNFromSANS: true,
		Format:            "pem",
		AltNames:          v.SubjectAlternativeNames,
		IPSans:            v.IPSubjectAlternativeNames,
		URISans:           v.URISubjectAlternativeNames,
		OtherSans:         v.OtherSubjectAlternativeNames,
		TimeToLive:        ttl(v.TimeToLive),
	}

	secret, err := v.signCSR(ctx, opts)
	if err != nil {
		return nil, err
	}

	// https://www.vaultproject.io/api/secret/pki/index.html#sample-response-15
	certPEM := []byte(secret.Data["certificate"].(string))
	caChainPEM := certPEM
	if caChain, ok := secret.Data["ca_chain"]; ok {
		for _, pemData := range caChain.([]interface{}) {
			caChainPEM = append(append(caChainPEM, '\n'), []byte(pemData.(string))...)
		}
	} else if ca, ok := secret.Data["issuing_ca"]; ok {
		caChainPEM = append(append(caChainPEM, '\n'), []byte(ca.(string))...)
	}

	tlsCert, err := tls.X509KeyPair(caChainPEM, keyPEM)
	if err != nil {
		return nil, err
	}

	// This can't error since it's called in tls.X509KeyPair above successfully
	tlsCert.Leaf, _ = x509.ParseCertificate(tlsCert.Certificate[0])
	return &tlsCert, nil
}
// Issue issues a certificate from the configured Vault backend,
// establishing a connection if one doesn't already exist.
Issue issues a certificate from the configured Vault backend,
establishing a connection if one doesn't already exist.
// Issue issues a certificate from the configured Vault backend // establishing a connection if one doesn ' t already exist .
func (v *Issuer) Issue(ctx context.Context, commonName string, conf *certify.CertConfig) (*tls.Certificate, error) {
	if v.cli == nil { 
		err := v.connect(ctx)
		if err != nil {
			return nil, err
		}
	}
	if v.AuthMethod == nil {
		v.AuthMethod = ConstantToken(v.Token)
	}
	csrPEM, keyPEM, err := csr.FromCertConfig(commonName, conf)
	if err != nil {
		return nil, err
	}
	opts := csrOpts{
		CSR:               string(csrPEM),
		CommonName:        commonName,
		ExcludeCNFromSANS: true,
		Format:            "pem",
		AltNames:          v.SubjectAlternativeNames,
		IPSans:            v.IPSubjectAlternativeNames,
		URISans:           v.URISubjectAlternativeNames,
		OtherSans:         v.OtherSubjectAlternativeNames,
		TimeToLive:        ttl(v.TimeToLive),
	}
	secret, err := v.signCSR(ctx, opts)
	if err != nil {
		return nil, err
	}
	certPEM := []byte(secret.Data["certificate"].(string))
	caChainPEM := certPEM
	if caChain, ok := secret.Data["ca_chain"]; ok {
		for _, pemData := range caChain.([]interface{}) {
			caChainPEM = append(append(caChainPEM, '\n'), []byte(pemData.(string))...)
		}
	} else if ca, ok := secret.Data["issuing_ca"]; ok {
		caChainPEM = append(append(caChainPEM, '\n'), []byte(ca.(string))...)
	}
	tlsCert, err := tls.X509KeyPair(caChainPEM, keyPEM)
	if err != nil {
		return nil, err
	}
	tlsCert.Leaf, _ = x509.ParseCertificate(tlsCert.Certificate[0])
	return &tlsCert, nil
}
func ( v * Issuer ) Issue ( ctx context . Context , commonName string , conf * certify . CertConfig ) ( * tls . Certificate , error ) { if v . cli == nil { err := v . connect ( ctx ) if err != nil { return nil , err } } if v . AuthMethod == nil { v . AuthMethod = ConstantToken ( v . Token ) } csrPEM , keyPEM , err := csr . FromCertConfig ( commonName , conf ) if err != nil { return nil , err } opts := csrOpts { CSR : string ( csrPEM ) , CommonName : commonName , ExcludeCNFromSANS : true , Format : " " , AltNames : v . SubjectAlternativeNames , IPSans : v . IPSubjectAlternativeNames , URISans : v . URISubjectAlternativeNames , OtherSans : v . OtherSubjectAlternativeNames , TimeToLive : ttl ( v . TimeToLive ) , } secret , err := v . signCSR ( ctx , opts ) if err != nil { return nil , err } certPEM := [ ] byte ( secret . Data [ " " ] . ( string ) ) caChainPEM := certPEM if caChain , ok := secret . Data [ " " ] ; ok { for _ , pemData := range caChain . ( [ ] interface { } ) { caChainPEM = append ( append ( caChainPEM , '\n' ) , [ ] byte ( pemData . ( string ) ) ... ) } } else if ca , ok := secret . Data [ " " ] ; ok { caChainPEM = append ( append ( caChainPEM , '\n' ) , [ ] byte ( ca . ( string ) ) ... ) } tlsCert , err := tls . X509KeyPair ( caChainPEM , keyPEM ) if err != nil { return nil , err } tlsCert . Leaf , _ = x509 . ParseCertificate ( tlsCert . Certificate [ 0 ] ) return & tlsCert , nil }
Issue issues a certificate from the configured Vault backend,
establishing a connection if one doesn't already exist.
Issue issues a certificate from the configured Vault backend establishing a connection if one doesn ' t already exist .
// Could be set by FromClient // Convert Token to AuthMethod, if no AuthMethod set, // for backwards compatibility. // https://www.vaultproject.io/api/secret/pki/index.html#sample-response-15 // This can't error since it's called in tls.X509KeyPair above successfully