Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Support plugin only request during plugin initialization #221

Merged
merged 2 commits into from
Nov 10, 2016

Conversation

ben181231
Copy link
Contributor

connect #219

@oursky-travis
Copy link
Collaborator

@ben181231, thanks for your PR! By analyzing the annotation information on this pull request, we identified @rickmak to be a potential reviewer

rickmak
rickmak previously requested changes Nov 9, 2016
Copy link
Member

@rickmak rickmak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isFormPlugin() should only have effect if there is present of master_key. Not either one present.

skyerr.PluginUnavailable,
"plugins are unavailable at the moment",
)
return http.StatusServiceUnavailable
Copy link
Member

@rickmak rickmak Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a test case for this preprocessor is needed as it become more complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

return http.StatusOK

if p.PluginContext.IsInitialized() {
if !payload.HasMasterKey() || !payload.IsFromPlugin() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isFormPlugin() should only have effect if there is present of master_key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Maybe I should rename it to IsPluginRequest()

@cheungpat
Copy link
Contributor

I will leave more comments

@@ -119,6 +119,9 @@ const (
// PluginTimeout occurs when an operation carried by a plugin is timed out
PluginTimeout

// PluginInitializing occurs when any of the plugins are initializing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Error codes for expected error condition should be placed above this line.”

i.e. do not insert errors in the middle of a list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I see.

// IsValidPluginRequest returns true when the payload indicate that the
// request is from plugin AND the master key is used
func (p Payload) IsValidPluginRequest() bool {
fromPlugin, _ := p.Data["_from_plugin"].(bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the job of a preprocessor to decide whether the request is a valid plugin request, not the Request struct. Move this function out of here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially that the “HasMasterKey” function only returns valid value after a auth preprocessor update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it conflict with this comment ?

Copy link
Contributor

@cheungpat cheungpat Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow UserAuthenticator in preprocessor/auth.go

} else if h.AccessKeyRequired {
h.preprocessors = h.PreprocessorList.GetByNames(
"plugin", "authenticator")
"authenticator",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need access_key here? (and above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The access_key is needed since the plugin handler is setting AccessKeyRequired to be true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see now, either accesskey or authenticator is required. So authenticator fits the bill here.

@cheungpat cheungpat dismissed rickmak’s stale review November 10, 2016 10:10

His comments are addressed in my review.

@cheungpat cheungpat merged commit 135042b into SkygearIO:master Nov 10, 2016
@ben181231 ben181231 deleted the plugin-init-state branch December 5, 2016 10:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants