Skip to content
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

Merged
merged 6 commits into from
Feb 23, 2017
Merged

Conversation

ecordell
Copy link
Contributor

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.

@docker-jenkins
Copy link

Can one of the admins verify this patch?

@cyli
Copy link
Contributor

cyli commented Jan 10, 2017

jenkins, test this please

@ecordell ecordell force-pushed the lib-fixes branch 3 times, most recently from d5fa7ff to c78d906 Compare January 11, 2017 14:17
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{
Copy link
Contributor

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

@cyli
Copy link
Contributor

cyli commented Jan 12, 2017

jenkins, test this please

@@ -11,6 +11,16 @@ const (
changeCategoryDeletion = "deletion"
)

// TUFFileTableName returns the name used for the tuf file table
var TUFFileTableName = func() string {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@ecordell ecordell Feb 16, 2017

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)
Copy link
Contributor

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!

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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. :)

@endophage
Copy link
Contributor

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 RootHandler), and want to apply the same EntrypointConfig over those additional routes?

@riyazdf
Copy link
Contributor

riyazdf commented Jan 12, 2017

Piggy-backing off of @endophage's comment - I'm cool with making createHandler exported, but I want to make sure that if it's because Notary could benefit from a particular endpoint that we can add that functionality to the released server?

@endophage
Copy link
Contributor

endophage commented Jan 12, 2017

On a related note, I'm wondering if EntrypointConfig has outlived its usefulness??? We construct a config inline to the CreateHandler function call only to immediately deconstruct it within the CreateHandler function. Should we just be passing the fields as arguments directly? Admittedly the argument list would be long-ish but it would be less obscure.

I think at some point (scraping my memory) we did it so you didn't end up with CreateHandler(nil, nil, nil, thingICareAbout, nil, nil, nil, nil), but looking at the handlers, only one directly sets 5 fields, and the rest all appear to set 6+ out of a total 8 fields.

If we think it's still useful, maybe it makes sense to pull out the 3 fields every entrypoint is using: OperationName, ServerHandler, and PermissionsRequired and make those arguments to CreateHandler

@ecordell
Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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...

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -11,6 +11,12 @@ const (
changeCategoryDeletion = "deletion"
)

// TUFFileTableName returns the name used for the tuf file table
var TUFFileTableName = "tuf_files"
Copy link
Contributor

Choose a reason for hiding this comment

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

const

Copy link
Contributor Author

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]>
@endophage
Copy link
Contributor

Jenkins had a random Java failure. I've given it a kick. I'm good to go on this once Jenkins goes green.

@endophage
Copy link
Contributor

@cyli @riyazdf @HuKeping can we get another LGTM?

@cyli
Copy link
Contributor

cyli commented Feb 23, 2017

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants