move osquery enroll secret to appconfig (#1004)

For #995
This commit is contained in:
Victor Vrantchan
2017-01-20 14:48:54 -05:00
committed by GitHub
parent 60062834c8
commit 54408ff9e4
11 changed files with 113 additions and 70 deletions
+20 -10
View File
@@ -11,12 +11,14 @@ type setupRequest struct {
Admin *kolide.UserPayload `json:"admin"`
OrgInfo *kolide.OrgInfo `json:"org_info"`
KolideServerURL *string `json:"kolide_server_url"`
EnrollSecret *string `json:"osquery_enroll_secret"`
}
type setupResponse struct {
Admin *kolide.User `json:"admin,omitempty"`
OrgInfo *kolide.OrgInfo `json:"org_info,omitempty"`
KolideServerURL *string `json:"kolide_server_url"`
EnrollSecret *string `json:"osquery_enroll_secret"`
Token *string `json:"token,omitempty"`
Err error `json:"error,omitempty"`
}
@@ -32,22 +34,29 @@ func makeSetupEndpoint(svc kolide.Service) endpoint.Endpoint {
err error
)
req := request.(setupRequest)
if req.OrgInfo != nil {
configPayload.OrgInfo = req.OrgInfo
}
configPayload.ServerSettings = &kolide.ServerSettings{}
if req.KolideServerURL != nil {
configPayload.ServerSettings.KolideServerURL = req.KolideServerURL
}
if req.EnrollSecret != nil {
configPayload.ServerSettings.EnrollSecret = req.EnrollSecret
}
config, err = svc.NewAppConfig(ctx, configPayload)
if err != nil {
return setupResponse{Err: err}, nil
}
// creating the user should be the last action. If there's a user
// present and other errors occur, the setup endpoint closes.
if req.Admin != nil {
admin, err = svc.NewAdminCreatedUser(ctx, *req.Admin)
if err != nil {
return setupResponse{Err: err}, nil
}
}
if req.OrgInfo != nil {
configPayload.OrgInfo = req.OrgInfo
}
if req.KolideServerURL != nil {
configPayload.ServerSettings = &kolide.ServerSettings{KolideServerURL: req.KolideServerURL}
}
config, err = svc.NewAppConfig(ctx, configPayload)
if err != nil {
return setupResponse{Err: err}, nil
}
// If everything works to this point, log the user in and return token. If
// the login fails for some reason, ignore the error and don't return
// a token, forcing the user to log in manually
@@ -63,6 +72,7 @@ func makeSetupEndpoint(svc kolide.Service) endpoint.Endpoint {
OrgLogoURL: &config.OrgLogoURL,
},
KolideServerURL: &config.KolideServerURL,
EnrollSecret: &config.EnrollSecret,
Token: token,
}, nil
}