-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasource_certificates.go
143 lines (134 loc) · 4.43 KB
/
datasource_certificates.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
package routeros
// Script generated from sampled device MikroTik 7.11.2 (stable) on CHR AMD-x86_64
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DatasourceCertificates() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceCertificatesRead,
Schema: map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/certificate"),
MetaId: PropId(Id),
KeyFilter: PropFilterRw,
"Certificates": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": { // Sample = .id: "*1"
Type: schema.TypeString,
Computed: true,
},
"akid": { // Sample = akid: ""
Type: schema.TypeString,
Computed: true,
},
"common_name": { // Sample = common-name: "home.arpa"
Type: schema.TypeString,
Computed: true,
},
"country": { // Sample = country: "AU"
Type: schema.TypeString,
Computed: true,
},
"crl": { // Sample = crl: "false"
Type: schema.TypeBool,
Computed: true,
},
"days_valid": { // Sample = days-valid: "45"
Type: schema.TypeInt,
Computed: true,
},
"digest_algorithm": { // Sample = digest-algorithm: "sha512"
Type: schema.TypeString,
Computed: true,
},
"expires_after": { // Sample = expires-after: "1w6d22h54m7s"
Type: schema.TypeString,
Computed: true,
},
"fingerprint": { // Sample = fingerprint: "b7e51a21658fc7f5b2686033d490e2450bd9e47318075967a3edcfcab0beefb7"
Type: schema.TypeString,
Computed: true,
},
"invalid_after": { // Sample = invalid-after: "2023-11-20 19:37:38"
Type: schema.TypeString,
Computed: true,
},
"invalid_before": { // Sample = invalid-before: "2023-10-06 19:37:38"
Type: schema.TypeString,
Computed: true,
},
"issuer": { // Sample = issuer: "C=NL,S=Friesland,L=Burgum,CN=Tjibbes Personal Root CA"
Type: schema.TypeString,
Computed: true,
},
"key_size": { // Sample = key-size: "4096"
Type: schema.TypeInt,
Computed: true,
},
"key_type": { // Sample = key-type: "rsa"
Type: schema.TypeString,
Computed: true,
},
"key_usage": { // Sample = key-usage: "digital-signature,content-commitment,key-encipherment,tls-server"
Type: schema.TypeString,
Computed: true,
},
"locality": { // Sample = locality: "Melbourne"
Type: schema.TypeString,
Computed: true,
},
"name": { // Sample = name: "home-arpa"
Type: schema.TypeString,
Computed: true,
},
"organization": { // Sample = organization: "My Company"
Type: schema.TypeString,
Computed: true,
},
"private_key": { // Sample = private-key: "true"
Type: schema.TypeBool,
Computed: true,
},
"serial_number": { // Sample = serial-number: "2c0fa8a659aecd074e65221549f5bd1c4ca13b6b"
Type: schema.TypeString,
Computed: true,
},
"skid": { // Sample = skid: "54aeb135f6a693162ea5937de8488d60a4995f8b"
Type: schema.TypeString,
Computed: true,
},
"state": { // Sample = state: "Victoria"
Type: schema.TypeString,
Computed: true,
},
"subject_alt_name": { // Sample = subject-alt-name: "DNS:home.arpa,DNS:*.home.arpa"
Type: schema.TypeString,
Computed: true,
},
"trusted": { // Sample = trusted: "true"
Type: schema.TypeBool,
Computed: true,
},
"unit": { // Sample = unit: "My Division"
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
func datasourceCertificatesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
s := DatasourceCertificates().Schema
path := s[MetaResourcePath].Default.(string)
res, err := ReadItemsFiltered(buildReadFilter(d.Get(KeyFilter).(map[string]interface{})), path, m.(Client))
if err != nil {
return diag.FromErr(err)
}
return MikrotikResourceDataToTerraformDatasource(res, "data", s, d)
}