Skip to content

Commit 050c9d2

Browse files
committed
Remove --no-read-only flag and make it closer to human nature
1 parent 31c4461 commit 050c9d2

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

cmd/flags.go

-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ var Flags = []cli.Flag{
7373
Usage: "Filter events with ReadOnly=true",
7474
Required: false,
7575
},
76-
&cli.BoolFlag{
77-
Name: "no-read-only",
78-
Usage: "Filter events with ReadOnly=false",
79-
Required: false,
80-
},
8176
&cli.StringFlag{
8277
Name: "max-results",
8378
Aliases: []string{"n"},

cmd/wrapper.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import (
66
)
77

88
func Wrapper(c *cli.Context) {
9+
var isReadOnlyFlagSet bool
10+
if c.IsSet("read-only") {
11+
isReadOnlyFlagSet = true
12+
}
13+
914
utils.EventsHandler(
1015
c.String("profile"),
1116
c.String("region"),
@@ -18,8 +23,8 @@ func Wrapper(c *cli.Context) {
1823
c.String("resource-type"),
1924
c.String("event-source"),
2025
c.String("access-key-id"),
26+
isReadOnlyFlagSet,
2127
c.Bool("read-only"),
22-
c.Bool("no-read-only"),
2328
c.Int("max-results"),
2429
c.Bool("error-only"),
2530
c.Bool("truncate-user-name"),

pkg/utils/handlers.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ import (
1414
"github.com/jedib0t/go-pretty/v6/text"
1515
)
1616

17-
func EventsHandler(profile, region string, startTime, endTime *time.Time, eventId, eventName, userName, resourceName, resourceType, eventSource, accessKeyId string, readOnly, noReadOnly bool, maxResults int, errorOnly, truncateUserName, truncateUserAgent bool) {
17+
func EventsHandler(profile, region string, startTime, endTime *time.Time, eventId, eventName, userName, resourceName, resourceType, eventSource, accessKeyId string, isReadOnlyFlagSet, readOnly bool, maxResults int, errorOnly, truncateUserName, truncateUserAgent bool) {
1818
// do nothing if maxResults is invalid input
1919
if maxResults <= 0 {
2020
log.Fatalf("Can not pass --max-results with a value lower or equal to 0.\n")
2121
}
2222

23-
// --read-only and --no-read-only should be mutually exclusive
24-
if readOnly && noReadOnly {
25-
log.Fatalf("Can not pass --read-only and --no-read-only at the same time.\n")
26-
}
27-
2823
cfg, err := config.LoadDefaultConfig(
2924
context.TODO(),
3025
config.WithRegion(region),
@@ -42,8 +37,8 @@ func EventsHandler(profile, region string, startTime, endTime *time.Time, eventI
4237
LookupAttributes: composeLookupAttributesInput(
4338
eventId,
4439
eventName,
40+
isReadOnlyFlagSet,
4541
readOnly,
46-
noReadOnly,
4742
userName,
4843
resourceName,
4944
resourceType,

pkg/utils/utils.go

+10-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"context"
5+
"strconv"
56
"strings"
67
"unicode/utf8"
78

@@ -79,7 +80,7 @@ func LookupEvents(ctx context.Context, svc *cloudtrail.Client, input *cloudtrail
7980
return events[:returnSize], nil
8081
}
8182

82-
func composeLookupAttributesInput(eventId, eventName string, readOnly, noReadOnly bool, userName, resourceName, resourceType, eventSource, accessKeyId string) []ctypes.LookupAttribute {
83+
func composeLookupAttributesInput(eventId, eventName string, isReadOnlyFlagSet, readOnly bool, userName, resourceName, resourceType, eventSource, accessKeyId string) []ctypes.LookupAttribute {
8384
lookupAttributesInput := []ctypes.LookupAttribute{}
8485

8586
// LookupAttributeKeyEventId
@@ -101,23 +102,14 @@ func composeLookupAttributesInput(eventId, eventName string, readOnly, noReadOnl
101102
}
102103

103104
// LookupAttributeKeyReadOnly
104-
var shouldPassReadonly bool
105-
var lookupAttributeKeyReadOnlyValue *string
106-
if readOnly != noReadOnly {
107-
shouldPassReadonly = true
108-
if readOnly {
109-
lookupAttributeKeyReadOnlyValue = aws.String("true")
110-
}
111-
if noReadOnly {
112-
lookupAttributeKeyReadOnlyValue = aws.String("false")
113-
}
114-
}
115-
if shouldPassReadonly {
116-
attrReadOnly := ctypes.LookupAttribute{
117-
AttributeKey: ctypes.LookupAttributeKeyReadOnly,
118-
AttributeValue: lookupAttributeKeyReadOnlyValue,
119-
}
120-
lookupAttributesInput = append(lookupAttributesInput, attrReadOnly)
105+
if isReadOnlyFlagSet {
106+
lookupAttributesInput = append(
107+
lookupAttributesInput,
108+
ctypes.LookupAttribute{
109+
AttributeKey: ctypes.LookupAttributeKeyReadOnly,
110+
AttributeValue: aws.String(strconv.FormatBool(readOnly)),
111+
},
112+
)
121113
}
122114

123115
// LookupAttributeKeyUsername

0 commit comments

Comments
 (0)