/
endpoint_certificate.go
109 lines (83 loc) · 4.33 KB
/
endpoint_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
105
106
107
108
109
package isegosdk
import (
"fmt"
"strings"
"github.com/go-resty/resty/v2"
)
type EndpointCertificateService service
type ResponseEndpointCertificateGetVersion struct {
VersionInfo *ResponseEndpointCertificateGetVersionVersionInfo `json:"VersionInfo,omitempty"` //
}
type ResponseEndpointCertificateGetVersionVersionInfo struct {
CurrentServerVersion string `json:"currentServerVersion,omitempty"` //
SupportedVersions string `json:"supportedVersions,omitempty"` //
Link *ResponseEndpointCertificateGetVersionVersionInfoLink `json:"link,omitempty"` //
}
type ResponseEndpointCertificateGetVersionVersionInfoLink struct {
Rel string `json:"rel,omitempty"` //
Href string `json:"href,omitempty"` //
Type string `json:"type,omitempty"` //
}
type RequestEndpointCertificateCreateEndpointCertificate struct {
ERSEndPointCert *RequestEndpointCertificateCreateEndpointCertificateERSEndPointCert `json:"ERSEndPointCert,omitempty"` //
}
type RequestEndpointCertificateCreateEndpointCertificateERSEndPointCert struct {
CertTemplateName string `json:"certTemplateName,omitempty"` // Name of an Internal CA template
Format string `json:"format,omitempty"` // Allowed values: - PKCS12, - PKCS12_CHAIN, - PKCS8, - PKCS8_CHAIN
Password string `json:"password,omitempty"` // Protects the private key. Must have more than 8 characters, less than 15 characters, at least one upper case letter, at least one lower case letter, at least one digit, and can only contain [A-Z][a-z][0-9]_#
CertificateRequest *RequestEndpointCertificateCreateEndpointCertificateERSEndPointCertCertificateRequest `json:"certificateRequest,omitempty"` // Key value map. Must have CN and SAN entries
}
type RequestEndpointCertificateCreateEndpointCertificateERSEndPointCertCertificateRequest struct {
San string `json:"san,omitempty"` // Valid MAC Address, delimited by '-'
Cn string `json:"cn,omitempty"` // Matches the requester's User Name, unless the Requester is an ERS Admin. ERS Admins are allowed to create requests for any CN
}
//GetVersion Get endpoint certificate version information
/* This API helps to retrieve the version information related to the endpoint certificate.
*/
func (s *EndpointCertificateService) GetVersion() (*ResponseEndpointCertificateGetVersion, *resty.Response, error) {
setHost(s.client, "_ers")
path := "/ers/config/endpointcert/versioninfo"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetResult(&ResponseEndpointCertificateGetVersion{}).
SetError(&Error).
Get(path)
if err != nil {
return nil, nil, err
}
if response.IsError() {
return nil, response, fmt.Errorf("error with operation GetVersion")
}
getCSFRToken(response.Header())
result := response.Result().(*ResponseEndpointCertificateGetVersion)
return result, response, err
}
//CreateEndpointCertificate Create endpoint certificate
/* This API allows the client to create an endpoint certificate.
*/
func (s *EndpointCertificateService) CreateEndpointCertificate(requestEndpointCertificateCreateEndpointCertificate *RequestEndpointCertificateCreateEndpointCertificate) (FileDownload, *resty.Response, error) {
setHost(s.client, "_ers")
path := "/ers/config/endpointcert/certRequest"
setCSRFToken(s.client)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetBody(requestEndpointCertificateCreateEndpointCertificate).
SetError(&Error).
Put(path)
fdownload := FileDownload{}
if err != nil {
return fdownload, nil, err
}
if response.IsError() {
return fdownload, response, fmt.Errorf("error with operation ExportTrustedCertificate")
}
fdownload.FileData = response.Body()
headerVal := response.Header()["Content-Disposition"][0]
fname := strings.SplitAfter(headerVal, "=")
fdownload.FileName = strings.ReplaceAll(fname[1], "\"", "")
getCSFRToken(response.Header())
return fdownload, response, err
}