-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WKS-1193 - Use dynamic actions #10
base: main
Are you sure you want to change the base?
Conversation
.github/workflows/analysis.yml
Outdated
@@ -36,6 +36,9 @@ jobs: | |||
go-version-file: go.mod | |||
|
|||
- name: Run Gosec Security Scanner | |||
uses: securego/[email protected] | |||
uses: securego/[email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't gosec part of golangci-lint?
See https://golangci-lint.run/usage/linters/#gosec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, we copied it as is from other plugins. We can definitely improve.
return names | ||
} | ||
|
||
func (c ActionsMetadata) FindAction(actionName string, service ...string) (*model.ActionMetadata, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an "option" pattern instead of service ...string
to create optional parameters.
Example:
am.FindAction("my-action", WithApplication("my-app"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is over engineering for just one option. We wont have others.
commands/common/cmd_api.go
Outdated
return apiError(http.StatusInternalServerError, "%+v", err) | ||
} | ||
|
||
apiEndpoint := fmt.Sprintf("%sworker/api/v%d/%s", utils.AddTrailingSlashIfNeeded(params.ServerUrl), params.ApiVersion+1, strings.Join(params.Path, "/")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
params.ApiVersion+1
seems rather awkward.
I suggest to use ApiVersion == 0
to mean default (1
now, but may change in the future) and to use any other value "as is".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an package internal type declared using the go iota thing.
So ApiVersion == 0 is already the default.
But we can set it to 1 explicitely so that we dont have to use +1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is internal, no worries. It is just weird...
return apiError(http.StatusInternalServerError, "unexpected error: %+v", err) | ||
} | ||
|
||
if slices.Index(params.OkStatuses, res.StatusCode) == -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we provide meaningful default value for params.OkStatuses
?
commands/common/cmd_api.go
Outdated
|
||
defer CloseQuietly(res.Body) | ||
|
||
if res.ContentLength > 0 || res.ContentLength == -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: invert the condition
if res.ContentLength > 0 || res.ContentLength == -1 { | |
if res.ContentLength == 0 { | |
// discard | |
} else { | |
//consume | |
} |
) | ||
|
||
// ReadManifest reads a manifest from the working directory or from the directory provided as argument. | ||
func ReadManifest(dir ...string) (*model.Manifest, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using a variadic function to implement optional arg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, used only for tests.
tsFieldAccessPattern = regexp.MustCompile(`\W([A-Z][a-zA-Z0-9]+)\.[a-zA-Z0-9]+`) | ||
tsTypeInTypeParameters = regexp.MustCompile(`<([A-Z][a-zA-Z0-9]+)>`) | ||
tsExcludeTypes = []string{"PlatformContext"} | ||
tsUnexportedType = regexp.MustCompile(`^(class|type|interface|enum|const)\s+[A-Za-z_$][0-9A-Za-z_$]*`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accept whitespace at the beginning
tsUnexportedType = regexp.MustCompile(`^(class|type|interface|enum|const)\s+[A-Za-z_$][0-9A-Za-z_$]*`) | |
tsUnexportedType = regexp.MustCompile(`^\s*(class|type|interface|enum|const)\s+[A-Za-z_$][0-9A-Za-z_$]*`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each line is actually trimmed before matching.
} | ||
|
||
return callWorkerApiWithOutput(c, server.GetUrl(), server.GetAccessToken(), http.MethodGet, nil, http.StatusOK, queryParams, "actions") | ||
return common.Print("%s", strings.Join(actions, ", ")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return common.Print("%s", strings.Join(actions, ", ")) | |
return common.Print(strings.Join(actions, ", ")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it causes a govet
lint error, that the reason is like this.
type ActionMetadata struct { | ||
Action Action `json:"action"` | ||
Description string `json:"description"` | ||
SamplePayload string `json:"samplePayload"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be snake_case instead of camelCase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backend uses this case.
model/flags.go
Outdated
func GetApplicationFlag() components.StringFlag { | ||
return components.NewStringFlag( | ||
FlagApplication, | ||
"The application that provides the event. If omitted worker will try to guess it and will raised an error if it could not.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The application that provides the event. If omitted worker will try to guess it and will raised an error if it could not.", | |
"The application that provides the event. If omitted, worker will try to guess it and will raise an error if it cannot.", |
timeout, err := model.GetTimeoutParameter(c) | ||
if err != nil { | ||
return apiError(http.StatusInternalServerError, "%+v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isnt it confusing to return an http error when we didnt call the server ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status is for internal use only.
Only err.Error()
meaning the message is showed to the end user.
commands/common/cmd_api.go
Outdated
|
||
apiEndpoint := fmt.Sprintf("%sworker/api/v%d/%s", utils.AddTrailingSlashIfNeeded(params.ServerUrl), params.ApiVersion+1, strings.Join(params.Path, "/")) | ||
|
||
if params.Query != nil || params.ProjectKey != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there isnt a built in way to generate query params ? with url apis
} | ||
} | ||
|
||
reqCtx, cancelReq := context.WithTimeout(context.Background(), timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the context should be a parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context is only used for request timeout.
I want to avoid duplicating context creation and cancellation on all the command.
7ac397e
to
a38304d
Compare
main
branch.go vet ./...
.go fmt ./...
.