Skip to content

Commit 2cbf21c

Browse files
author
lleadbet
committed
addreses #111
1 parent d628aaa commit 2cbf21c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cmd/events.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func init() {
7878
// flags for forwarding functionality/changing payloads
7979
triggerCmd.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event.")
8080
triggerCmd.Flags().StringVarP(&transport, "transport", "T", "eventsub", fmt.Sprintf("Preferred transport method for event. Defaults to /EventSub.\nSupported values: %s", events.ValidTransports()))
81-
triggerCmd.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC.")
81+
triggerCmd.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be greater than or equal to 10 characters and less than or equal to 100.")
8282

8383
// per-topic flags
8484
triggerCmd.Flags().StringVarP(&toUser, "to-user", "t", "", "User ID of the receiver of the event. For example, the user that receives a follow. In most contexts, this is the broadcaster.")
@@ -96,13 +96,13 @@ func init() {
9696
// retrigger flags
9797
retriggerCmd.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event.")
9898
retriggerCmd.Flags().StringVarP(&eventID, "id", "i", "", "ID of the event to be refired.")
99-
retriggerCmd.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC.")
99+
retriggerCmd.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be greater than or equal to 10 characters and less than or equal to 100.")
100100
retriggerCmd.MarkFlagRequired("id")
101101

102102
// verify-subscription flags
103103
verifyCmd.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event.")
104104
verifyCmd.Flags().StringVarP(&transport, "transport", "T", "eventsub", fmt.Sprintf("Preferred transport method for event. Defaults to EventSub.\nSupported values: %s", events.ValidTransports()))
105-
verifyCmd.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC.")
105+
verifyCmd.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be greater than or equal to 10 characters and less than or equal to 100.")
106106
verifyCmd.MarkFlagRequired("forward-address")
107107
}
108108

@@ -112,6 +112,11 @@ func triggerCmdRun(cmd *cobra.Command, args []string) {
112112
return
113113
}
114114

115+
if secret != "" && (len(secret) < 10 || len(secret) > 100) {
116+
fmt.Println("Invalid secret provided. Secrets must be between 10-100 characters")
117+
return
118+
}
119+
115120
// Validate that the forward address is actually a URL
116121
if len(forwardAddress) > 0 {
117122
_, err := url.ParseRequestURI(forwardAddress)
@@ -149,6 +154,11 @@ func triggerCmdRun(cmd *cobra.Command, args []string) {
149154
}
150155

151156
func retriggerCmdRun(cmd *cobra.Command, args []string) {
157+
if secret != "" && (len(secret) < 10 || len(secret) > 100) {
158+
fmt.Println("Invalid secret provided. Secrets must be between 10-100 characters")
159+
return
160+
}
161+
152162
res, err := trigger.RefireEvent(eventID, trigger.TriggerParameters{
153163
ForwardAddress: forwardAddress,
154164
Secret: secret,
@@ -167,6 +177,11 @@ func verifyCmdRun(cmd *cobra.Command, args []string) {
167177
return
168178
}
169179

180+
if secret != "" && (len(secret) < 10 || len(secret) > 100) {
181+
fmt.Println("Invalid secret provided. Secrets must be between 10-100 characters")
182+
return
183+
}
184+
170185
// Validate that the forward address is actually a URL
171186
if len(forwardAddress) > 0 {
172187
_, err := url.ParseRequestURI(forwardAddress)

0 commit comments

Comments
 (0)