-
Notifications
You must be signed in to change notification settings - Fork 510
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
Minor refactoring (nicer lib usage) #1081
Conversation
Can one of the admins verify this patch? |
jenkins, test this please |
d5fa7ff
to
c78d906
Compare
server/server.go
Outdated
invalidGUNErr := errors.ErrInvalidGUN.WithDetail(fmt.Sprintf("Require GUNs with prefix: %v", repoPrefixes)) | ||
notFoundError := errors.ErrMetadataNotFound.WithDetail(nil) | ||
|
||
r := mux.NewRouter() | ||
r.Methods("GET").Path("/v2/").Handler(authWrapper(handlers.MainHandler)) | ||
|
||
r.Methods("POST").Path("/v2/{imageName:[^*]+}/_trust/tuf/").Handler(createHandler(_serverEndpoint{ | ||
r.Methods("POST").Path("/v2/{imageName:[^*]+}/_trust/tuf/").Handler(CreateHandler(EndpointConfig{ |
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.
How about changing the imageName
to gun
in this PR as well, see #1069
jenkins, test this please |
server/storage/sql_models.go
Outdated
@@ -11,6 +11,16 @@ const ( | |||
changeCategoryDeletion = "deletion" | |||
) | |||
|
|||
// TUFFileTableName returns the name used for the tuf file table | |||
var TUFFileTableName = func() string { |
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.
Non-blocking: perhaps these should just be string constants?
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.
As they're not modifiable, yeah, they should be string consts.
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.
Then again, they should also NEVER be used in more than one context (i.e. through the appropriate struct) so I actually prefer them being defined directly in the struct methods. It tightly binds them to the correct context.
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.
@ecordell I think these functions are the only thing that I really don't like in this PR. the rest of it I'm fine with (I've been waiting to see if you wanted to make the EndpointConfig updates here).
I really preferred them attached to the struct, it keeps it very clear what it's appropriate to use them for. However, if you want to break them out, it makes a lot more sense to just make them const
's.
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.
Agreed with @endophage , I don't see the explicit benefit we can from these functions, it's not that directly and clear.
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.
Didn't mean to let this stagnate, I've been trying to evaluate which of these changes are really needed.
I was thinking that the functions might help for threshold "witnessing" (or whatever the term is now) by creating a different table for "staged" metadata. Constants would also work for that, though. Since that design is still very up in the air I will change this and update the PR.
utils/http.go
Outdated
ctxu.GetResponseLogger(ctx).Info("response completed") | ||
}() | ||
}(ctx) |
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.
👍 Thank you for this fix!
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.
Is this correct? Don't we want to use the possibly modified context (which may contain additional info) when the function exits?
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.
doAuth
does not currently updates the logger, but I suppose it's possible in the future that it may. I'm not sure if we necessarily care though about all the other fields in a "response completed" log.
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.
You may be right and we may want the modified context if the logger gets updated in the future. I have no strong opinions either way. I had originally assumed we just wanted the base logger. :)
I'm curious what the use case is here. My assumption is that you're adding additional http routes to the server (on the object returned by |
Piggy-backing off of @endophage's comment - I'm cool with making |
On a related note, I'm wondering if I think at some point (scraping my memory) we did it so you didn't end up with If we think it's still useful, maybe it makes sense to pull out the 3 fields every entrypoint is using: |
Took a while to get back around to this, but I believe I've addressed everything now! |
server/server.go
Outdated
@@ -116,13 +116,27 @@ func filterImagePrefixes(requiredPrefixes []string, err error, handler http.Hand | |||
}) | |||
} | |||
|
|||
type _serverEndpoint struct { | |||
// EndpointConfig stores settings used to create a ServerHandler | |||
type EndpointConfig struct { |
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.
We can delete this now right?
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.
Yup, I think the rebase added it back...
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.
fixed
server/server.go
Outdated
RepoPrefixes []string | ||
} | ||
|
||
// CreateHandler creates a server handler from an EndpointConfig |
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.
Comment needs update now that we don't take an EndpointConfig any more
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.
fixed
Signed-off-by: Evan Cordell <[email protected]>
Signed-off-by: Evan Cordell <[email protected]>
Signed-off-by: Evan Cordell <[email protected]>
Signed-off-by: Evan Cordell <[email protected]>
Signed-off-by: Evan Cordell <[email protected]>
server/storage/sql_models.go
Outdated
@@ -11,6 +11,12 @@ const ( | |||
changeCategoryDeletion = "deletion" | |||
) | |||
|
|||
// TUFFileTableName returns the name used for the tuf file table | |||
var TUFFileTableName = "tuf_files" |
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.
const
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.
fixed
Signed-off-by: Evan Cordell <[email protected]>
Jenkins had a random Java failure. I've given it a kick. I'm good to go on this once Jenkins goes green. |
LGTM! |
When using Notary as a library, I ran into some visibility issues that I've addressed here.
I'm a little uneasy about this PR because I can only justify it from my own experience, but I don't think there's anything egregious here. Personally, I think this changeset a slight readability improvement, regardless.