-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleanup.go
42 lines (36 loc) · 1.2 KB
/
cleanup.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
package main
import (
"github.com/ovh/kmip-go"
"github.com/ovh/kmip-go/kmipclient"
)
func cleanupDomain(client *kmipclient.Client) {
println("Listing all objects")
resp := client.Locate().MustExec()
for _, id := range resp.UniqueIdentifier {
resp := client.GetAttributes(id, kmip.AttributeNameState).MustExec()
for _, attr := range resp.Attribute {
if attr.AttributeName == kmip.AttributeNameState && attr.AttributeValue.(kmip.State) == kmip.StateActive {
println("Revoking", id)
client.Revoke(id).WithRevocationReasonCode(kmip.RevocationReasonCodeCessationOfOperation).MustExec()
break
}
}
println("Deleting", id)
client.Destroy(id).MustExec()
}
println("Deleted", len(resp.UniqueIdentifier), "managed objects")
}
func activateAll(client *kmipclient.Client) {
println("Listing all objects")
resp := client.Locate().MustExec()
for _, id := range resp.UniqueIdentifier {
resp := client.GetAttributes(id, kmip.AttributeNameState).MustExec()
for _, attr := range resp.Attribute {
if attr.AttributeName == kmip.AttributeNameState && attr.AttributeValue.(kmip.State) == kmip.StatePreActive {
println("Activating", id)
client.Activate(id).MustExec()
break
}
}
}
}