-
Notifications
You must be signed in to change notification settings - Fork 8
/
certificate_subresource.go
146 lines (141 loc) · 4.41 KB
/
certificate_subresource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2023 Broadcom. All Rights Reserved.
// SPDX-License-Identifier: MPL-2.0
package certificates
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/vcf-sdk-go/models"
)
func CertificateSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Description: "Domain of the resource certificate",
Computed: true,
},
"expiration_status": {
Type: schema.TypeString,
Description: "Certificate expiry status. One among: ACTIVE, ABOUT_TO_EXPIRE, EXPIRED",
Computed: true,
},
"certificate_error": {
Type: schema.TypeString,
Description: "Error if certificate cannot be fetched. Example: Status : NOT_TRUSTED, Message : Certificate Expired",
Computed: true,
},
"issued_by": {
Type: schema.TypeString,
Description: "The certificate authority that issued the certificate",
Computed: true,
},
"issued_to": {
Type: schema.TypeString,
Description: "To whom the certificate is issued",
Computed: true,
},
"key_size": {
Type: schema.TypeString,
Description: "The key size of the certificate",
Computed: true,
},
"not_after": {
Type: schema.TypeString,
Description: "The timestamp after which certificate is not valid",
Computed: true,
},
"not_before": {
Type: schema.TypeString,
Description: "The timestamp before which certificate is not valid",
Computed: true,
},
"number_of_days_to_expire": {
Type: schema.TypeInt,
Description: "Number of days left for the certificate to expire",
Computed: true,
},
"pem_encoded": {
Type: schema.TypeString,
Description: "The PEM encoded certificate content",
Sensitive: true,
Computed: true,
},
"public_key": {
Type: schema.TypeString,
Description: "The public key of the certificate",
Computed: true,
},
"public_key_algorithm": {
Type: schema.TypeString,
Description: "The public key algorithm of the certificate",
Computed: true,
},
"serial_number": {
Type: schema.TypeString,
Description: "The serial number of the certificate",
Computed: true,
},
"signature_algorithm": {
Type: schema.TypeString,
Description: "Algorithm used to sign the certificate",
Computed: true,
},
"subject": {
Type: schema.TypeString,
Description: "Complete distinguished name to which the certificate is issued",
Computed: true,
},
"subject_alternative_name": {
Type: schema.TypeList,
Description: "The alternative names to which the certificate is issued",
Computed: true,
Elem: schema.TypeString,
},
"thumbprint": {
Type: schema.TypeString,
Description: "Thumbprint generated using certificate content",
Computed: true,
},
"thumbprint_algorithm": {
Type: schema.TypeString,
Description: "Algorithm used to generate thumbprint",
Computed: true,
},
"version": {
Type: schema.TypeString,
Description: "The X.509 version of the certificate",
Computed: true,
},
},
}
}
func FlattenCertificate(cert *models.Certificate) map[string]interface{} {
result := make(map[string]interface{})
if cert.Domain == nil {
result["domain"] = "nil"
} else {
result["domain"] = *cert.Domain
}
if cert.GetCertificateError == nil {
result["certificate_error"] = "nil"
} else {
result["certificate_error"] = *cert.GetCertificateError
}
result["expiration_status"] = *cert.ExpirationStatus
result["issued_by"] = *cert.IssuedBy
result["issued_to"] = *cert.IssuedTo
result["key_size"] = *cert.KeySize
result["not_after"] = *cert.NotAfter
result["not_before"] = *cert.NotBefore
result["number_of_days_to_expire"] = *cert.NumberOfDaysToExpire
result["pem_encoded"] = *cert.PemEncoded
result["public_key"] = *cert.PublicKey
result["public_key_algorithm"] = *cert.PublicKeyAlgorithm
result["serial_number"] = *cert.SerialNumber
result["signature_algorithm"] = *cert.SignatureAlgorithm
result["subject"] = *cert.Subject
result["subject_alternative_name"] = cert.SubjectAlternativeName
result["thumbprint"] = *cert.Thumbprint
result["thumbprint_algorithm"] = *cert.ThumbprintAlgorithm
result["version"] = *cert.Version
return result
}