-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_ibm_certificate_manager_certificate.go
104 lines (89 loc) · 5.28 KB
/
table_ibm_certificate_manager_certificate.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
package ibm
import (
"context"
"github.com/IBM-Cloud/bluemix-go/api/certificatemanager"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
//// TABLE DEFINITION
func tableIbmCertificateManagerCertificate(ctx context.Context) *plugin.Table {
return &plugin.Table{
Name: "ibm_certificate_manager_certificate",
Description: "Retrieve the details of an existing certificate instance resource and lists all the certificates.",
GetMatrixItemFunc: BuildServiceInstanceList,
List: &plugin.ListConfig{
Hydrate: listCertificate,
KeyColumns: []*plugin.KeyColumn{
{
Name: "certificate_manager_instance_id",
Require: plugin.Optional,
},
},
},
Columns: []*plugin.Column{
{Name: "id", Type: proto.ColumnType_STRING, Description: "The ID of the certificate that is managed in certificate manager."},
{Name: "name", Type: proto.ColumnType_STRING, Description: "The display name of the certificate."},
{Name: "description", Type: proto.ColumnType_STRING, Description: "The description of the certificate."},
{Name: "status", Type: proto.ColumnType_STRING, Description: "The status of a certificate."},
{Name: "serial_number", Type: proto.ColumnType_STRING, Description: "The serial number of a certificate."},
{Name: "certificate_manager_instance_id", Type: proto.ColumnType_STRING, Description: "The CRN of the certificate manager service instance.", Hydrate: plugin.HydrateFunc(getServiceInstanceCRN)},
{Name: "algorithm", Type: proto.ColumnType_STRING, Description: "The Algorithm of a certificate."},
{Name: "auto_renew_enabled", Type: proto.ColumnType_BOOL, Description: "The automatic renewal status of the certificate.", Transform: transform.FromField("OrderPolicy.AutoRenewEnabled"), Default: false},
{Name: "begins_on", Type: proto.ColumnType_TIMESTAMP, Description: "The creation date of the certificate.", Transform: transform.FromField("BeginsOn").Transform(transform.UnixMsToTimestamp)},
{Name: "expires_on", Type: proto.ColumnType_TIMESTAMP, Description: "The expiration date of the certificate.", Transform: transform.FromField("ExpiresOn").Transform(transform.UnixMsToTimestamp)},
{Name: "domains", Type: proto.ColumnType_JSON, Description: "An array of valid domains for the issued certificate. The first domain is the primary domain, extra domains are secondary domains."},
{Name: "has_previous", Type: proto.ColumnType_BOOL, Description: "Indicates whether a certificate has a previous version."},
{Name: "rotate_keys", Type: proto.ColumnType_BOOL, Description: "Rotate keys."},
{Name: "imported", Type: proto.ColumnType_BOOL, Description: "Indicates whether a certificate has imported or not."},
{Name: "issuance_info", Type: proto.ColumnType_JSON, Description: "The issuance information of a certificate."},
{Name: "issuer", Type: proto.ColumnType_STRING, Description: "The issuer of the certificate."},
{Name: "key_algorithm", Type: proto.ColumnType_STRING, Description: "An alphanumeric value identifying the account ID."},
{Name: "order_policy_name", Type: proto.ColumnType_STRING, Description: "The order policy name of the certificate.", Transform: transform.FromField("OrderPolicy.Name")},
// Standard columns
{Name: "account_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("ID").Transform(crnToAccountID), Description: "The account ID of this certificate."},
{Name: "region", Type: proto.ColumnType_STRING, Description: "The region of this certificate.", Hydrate: plugin.HydrateFunc(getRegion)},
{Name: "title", Type: proto.ColumnType_STRING, Transform: transform.FromField("Name"), Description: resourceInterfaceDescription("title")},
{Name: "akas", Type: proto.ColumnType_JSON, Transform: transform.FromField("ID").Transform(ensureStringArray), Description: resourceInterfaceDescription("akas")},
},
}
}
//// LIST FUNCTION
func listCertificate(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listCertificate")
instanceCRN := d.EqualsQualString("instance_crn")
serviceType := d.EqualsQualString("service_type")
// Invalid service type
if serviceType != "cloudcerts" {
return nil, nil
}
// Return if specified instanceID not matched
if d.EqualsQuals["certificate_manager_instance_id"] != nil && d.EqualsQuals["certificate_manager_instance_id"].GetStringValue() != instanceCRN {
return nil, nil
}
// Create service connection
conn, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ibm_certificate_manager_certificate.listCertificate", "connection_error", err)
return nil, err
}
svc, err := certificatemanager.New(conn)
if err != nil {
plugin.Logger(ctx).Error("ibm_certificate_manager_certificate.listCertificate", "connection_error", err)
return nil, err
}
client := svc.Certificate()
certificates, err := client.ListCertificates(instanceCRN)
if err != nil {
plugin.Logger(ctx).Error("ibm_certificate_manager_certificate.listCertificate", "query_error", err)
return nil, err
}
for _, i := range certificates {
d.StreamListItem(ctx, i)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
return nil, nil
}