/
getAuditRecordCollectionCmd.auto.go
144 lines (123 loc) · 4.25 KB
/
getAuditRecordCollectionCmd.auto.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Code generated from specification version 1.0.0: DO NOT EDIT
package cmd
import (
"fmt"
"io"
"net/http"
"net/url"
"github.com/reubenmiller/go-c8y-cli/pkg/mapbuilder"
"github.com/reubenmiller/go-c8y/pkg/c8y"
"github.com/spf13/cobra"
)
type getAuditRecordCollectionCmd struct {
*baseCmd
}
func newGetAuditRecordCollectionCmd() *getAuditRecordCollectionCmd {
ccmd := &getAuditRecordCollectionCmd{}
cmd := &cobra.Command{
Use: "list",
Short: "Get collection of (user) audits",
Long: `Audit records contain information about modifications to other Cumulocity entities. For example the audit records contain each operation state transition, so they can be used to check when an operation transitioned from PENDING -> EXECUTING -> SUCCESSFUL.
`,
Example: `
$ c8y auditRecords list --pageSize 100
Get a list of audit records
`,
PreRunE: nil,
RunE: ccmd.getAuditRecordCollection,
}
cmd.SilenceUsage = true
cmd.Flags().String("source", "", "Source Id or object containing an .id property of the element that should be detected. i.e. AlarmID, or Operation ID. Note: Only one source can be provided")
cmd.Flags().String("type", "", "Type")
cmd.Flags().String("user", "", "Username")
cmd.Flags().String("application", "", "Application")
cmd.Flags().String("dateFrom", "", "Start date or date and time of audit record occurrence.")
cmd.Flags().String("dateTo", "", "End date or date and time of audit record occurrence.")
cmd.Flags().Bool("revert", false, "Return the newest instead of the oldest audit records. Must be used with dateFrom and dateTo parameters")
// Required flags
ccmd.baseCmd = newBaseCmd(cmd)
return ccmd
}
func (n *getAuditRecordCollectionCmd) getAuditRecordCollection(cmd *cobra.Command, args []string) error {
commonOptions, err := getCommonOptions(cmd)
if err != nil {
return newUserError(fmt.Sprintf("Failed to get common options. err=%s", err))
}
// query parameters
queryValue := url.QueryEscape("")
query := url.Values{}
if v, err := cmd.Flags().GetString("source"); err == nil {
if v != "" {
query.Add("source", url.QueryEscape(v))
}
} else {
return newUserError(fmt.Sprintf("Flag [%s] does not exist. %s", "source", err))
}
if v, err := cmd.Flags().GetString("type"); err == nil {
if v != "" {
query.Add("type", url.QueryEscape(v))
}
} else {
return newUserError(fmt.Sprintf("Flag [%s] does not exist. %s", "type", err))
}
if v, err := cmd.Flags().GetString("user"); err == nil {
if v != "" {
query.Add("user", url.QueryEscape(v))
}
} else {
return newUserError(fmt.Sprintf("Flag [%s] does not exist. %s", "user", err))
}
if v, err := cmd.Flags().GetString("application"); err == nil {
if v != "" {
query.Add("application", url.QueryEscape(v))
}
} else {
return newUserError(fmt.Sprintf("Flag [%s] does not exist. %s", "application", err))
}
if flagVal, err := cmd.Flags().GetString("dateFrom"); err == nil && flagVal != "" {
if v, err := tryGetTimestampFlag(cmd, "dateFrom"); err == nil && v != "" {
query.Add("dateFrom", v)
} else {
return newUserError("invalid date format", err)
}
}
if flagVal, err := cmd.Flags().GetString("dateTo"); err == nil && flagVal != "" {
if v, err := tryGetTimestampFlag(cmd, "dateTo"); err == nil && v != "" {
query.Add("dateTo", v)
} else {
return newUserError("invalid date format", err)
}
}
if cmd.Flags().Changed("revert") {
if v, err := cmd.Flags().GetBool("revert"); err == nil {
query.Add("revert", fmt.Sprintf("%v", v))
} else {
return newUserError("Flag does not exist")
}
}
commonOptions.AddQueryParameters(&query)
queryValue, err = url.QueryUnescape(query.Encode())
if err != nil {
return newSystemError("Invalid query parameter")
}
// headers
headers := http.Header{}
// form data
formData := make(map[string]io.Reader)
// body
body := mapbuilder.NewMapBuilder()
// path parameters
pathParameters := make(map[string]string)
path := replacePathParameters("/audit/auditRecords", pathParameters)
req := c8y.RequestOptions{
Method: "GET",
Path: path,
Query: queryValue,
Body: body.GetMap(),
FormData: formData,
Header: headers,
IgnoreAccept: false,
DryRun: globalFlagDryRun,
}
return processRequestAndResponse([]c8y.RequestOptions{req}, commonOptions)
}