-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
GetServerCert.go
72 lines (61 loc) · 2.54 KB
/
GetServerCert.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// snippet-start:[iam.go.get_server_cert]
package main
// snippet-start:[iam.go.get_server_cert.imports]
import (
"flag"
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/iam/iamiface"
)
// snippet-end:[iam.go.get_server_cert.imports]
// FindServerCert retrieves the metadata for an IAM server certificate.
// Inputs:
// svc is an IAM service client
// certName is the name of the service certificate
// Output:
// If success, the metadata of the server certificate and nil
// Otherwise, nil and an error from the call to GetServerCertificate
func FindServerCert(svc iamiface.IAMAPI, certName *string) (*iam.GetServerCertificateOutput, error) {
// snippet-start:[iam.go.get_server_cert.call]
result, err := svc.GetServerCertificate(&iam.GetServerCertificateInput{
ServerCertificateName: certName,
})
// snippet-end:[iam.go.get_server_cert.call]
return result, err
}
func main() {
// snippet-start:[iam.go.get_server_cert.args]
certName := flag.String("c", "", "The name of the certificate")
flag.Parse()
if *certName == "" {
fmt.Println("You must supply the name of a certificate (-c CERT-NAME)")
return
}
// snippet-end:[iam.go.get_server_cert.args]
// snippet-start:[iam.go.get_server_cert.session]
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := iam.New(sess)
// snippet-end:[iam.go.get_server_cert.session]
result, err := FindServerCert(svc, certName)
if err != nil {
fmt.Println("Got an error retrieving the server certificate:")
fmt.Println(err)
return
}
// snippet-start:[iam.go.get_server_cert.display]
metadata := result.ServerCertificate.ServerCertificateMetadata
fmt.Println("ARN: " + *metadata.Arn)
fmt.Println("Expiration: " + (*metadata.Expiration).Format("2006-01-02 15:04:05 Monday"))
fmt.Println("Path: " + *metadata.Path)
fmt.Println("ServerCertificateId " + *metadata.ServerCertificateId)
fmt.Println("ServerCertificateName " + *metadata.ServerCertificateName)
fmt.Println("UploadDate: " + (*metadata.UploadDate).Format("2006-01-02 15:04:05 Monday"))
fmt.Println("")
// snippet-end:[iam.go.get_server_cert.display]
}
// snippet-end:[iam.go.get_server_cert]