镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Refactoring for config patterns - #159

Merged
zwass merged 9 commits into
kolide:masterfrom
zwass:use_config
Sep 14, 2016
Merged

zwass merged 9 commits into
kolide:masterfrom
zwass:use_config

Conversation

@zwass

@zwass zwass commented Sep 12, 2016 •

Copy link
Copy Markdown
Contributor

This PR refactors most of the codebase to use the new config patterns implemented in #149. Now the core service keeps a copy of the KolideConfig struct, and service methods can reference the configuration in that struct when they need it. The most significant refactoring is in the sessions code, separating the business logic from the storage layer.

Comment thread cli/prepare.go
}

admin, err := kolide.NewUser("admin", "admin", "admin@kolide.co", true, false)
admin, err := kolide.NewUser("admin", "admin", "admin@kolide.co", true, false, config.Auth.BcryptCost)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm deleting the kolide.NewUser method as new users should only be created through the Service interface.
Having it in two places causes confusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cool. When I rebase I'll deal with that conflict.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Don't worry about it, I got this." - @zwass

@zwass

zwass commented Sep 12, 2016

Copy link
Copy Markdown
Contributor Author

@marpaia @groob I have a bunch of questions about this sessions code that I'm trying to refactor.

In which situations do we need to "validate" sessions, and in which do we not? Currently FindSessionByID and FindSessionByKey do validation, but FindAllSessionsForUser does not.

Per #158 (comment), are we in agreement that MakeSession should be moved to a private helper?

Can you help me get a general sense for what all the Get methods in the interface would be used for? It looks like the authorization code doesn't hit these but hits the datastore directly. Should there be a method in this interface that setViewerContext calls?

Comment thread datastore/gorm_sessions.go Outdated

func (orm gormDB) validateSession(session *kolide.Session) error {
sessionLifeSpan := viper.GetFloat64("session.expiration_seconds")
func (orm gormDB) validateSession(session *kolide.Session, sessionLifeSpan time.Duration) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intending to kill this in favor of service.validateSession.

@zwass

zwass commented Sep 13, 2016

Copy link
Copy Markdown
Contributor Author

@marpaia Can you please take a look at my other questions above? #159 (comment)

@zwass

zwass commented Sep 13, 2016

Copy link
Copy Markdown
Contributor Author

It looks like we are in agreement that MakeSession does not need to be in the public interface: #158 (comment)

@zwass zwass assigned zwass and unassigned marpaia Sep 13, 2016
Comment thread config/config.go Outdated
Session: SessionConfig{
KeySize: 64,
Duration: 24 * 90 * time.Hour,
CookieName: "KolideSession",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're not using cookies anymore, maybe drop this field altogether?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are we using localstorage now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yep, with the token sent to the server using the Authorization Bearer token. See #131

@zwass

zwass commented Sep 13, 2016

Copy link
Copy Markdown
Contributor Author

@groob I've tried not to make changes in the areas that your PR is touching, but some already got in there before you warned me. When do you expect to merge that PR? If it won't be for a while, I may merge this beforehand.

@groob

groob commented Sep 13, 2016

Copy link
Copy Markdown
Contributor

It's not a problem. I'll rebase once you merge.
I'm hoping to finish later tonight or tomorrow if I can find a good way to deal with email templates.

Comment thread cli/serve.go Outdated
JWTKey: "foobar",
ds, err := datastore.New("inmem", "")
if err != nil {
panic("Could not create datastore: " + err.Error())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we avoid using panics in favor of returning an error, or at least logging it an calling os.Exit() instead?

@zwass

zwass commented Sep 14, 2016

Copy link
Copy Markdown
Contributor Author

@marpaia please take a look at this when you get a chance. There's some major refactoring, and I think it's pretty much ready to merge.

Comment thread cli/root.go
}

// initFatal prints an error message and exits with a non-zero status.
func initFatal(err error, message string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's SO silly that we don't panic here, lest the go kids don't think we're cool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMO (and I saw your and @groob's discussion on this in chat) rather than having a holy war on this subject, we just need to decide what the user experience should be for fatal errors. Do we want to exit with a clean and simple error message, or do we want the backtrace that comes with a panic?

As a developer, I would prefer to see the backtrace. I'm not sure that's what our customers will prefer. Ultimately I don't think it matters much, as long as we are giving messages that are helpful enough to locate and then fix the error.

Comment thread config/config.go

// TestConfig returns a barebones configuration suitable for use in tests.
// Individual tests may want to override some of the values provided.
func TestConfig() KolideConfig {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not super duper psyched about having a public TestXXX symbol although I see why you're doing it and I don't have a better suggestion.

@marpaia

marpaia commented Sep 14, 2016

Copy link
Copy Markdown
Contributor

I don't see anything egregious here. If you think we should add MySQL back in a separate commit, then feel free to merge this. Good work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants