This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csr.go
70 lines (63 loc) · 1.38 KB
/
csr.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
package csr
import (
"encoding/json"
"errors"
"fmt"
)
type CSR struct {
Id int `json:"id"`
CountryName string `json:"c"`
StateOrProvinceName string `json:"st"`
LocalityName string `json:"l"`
OrganizationName string `json:"o"`
OrganizationalUnitName string `json:"ou,omitempty"`
CommonName string `json:"cn"`
EmailAddress string `json:"mail,omitempty"`
Status string `json:"status"`
CsrFilePath string `json:"csrpath,omitempty"`
}
type EmbeddedCSRs struct {
CSRs CSR `json:"csr"`
}
type CSRs struct {
CSRs []CSR `json:"csr"`
}
type Data struct {
*EmbeddedCSRs
*CSRs
}
func (d *Data) UnmarshalJSON(data []byte) error {
temp := struct {
Embedded interface{} `json:"csr"`
}{}
err := json.Unmarshal(data, &temp)
if err != nil {
return err
}
switch temp.Embedded.(type) {
case map[string]interface{}:
var c EmbeddedCSRs
if err := json.Unmarshal(data, &c); err != nil {
return err
}
d.EmbeddedCSRs = &c
d.CSRs = nil
fmt.Printf("%v\n", c)
case []interface{}:
var c CSRs
if err := json.Unmarshal(data, &c); err != nil {
return err
}
d.CSRs = &c
d.EmbeddedCSRs = nil
default:
return errors.New("Invalid object type")
}
return nil
}
const (
PendingStatus = "NEW"
ApprobedStatus = "APPROBED"
DeniedStatus = "DENIED"
RevokedStatus = "REVOKED"
)