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

Refactor setup config #3694

Merged
merged 41 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3a51850
Refactor setup config
nwmac May 27, 2019
5a26673
Fix error logging issues
nwmac May 27, 2019
10c664e
Fixed some typos
richard-cox May 31, 2019
a4553fc
Add initial schema and login method skeletons
kreinecke May 20, 2019
9b9b424
Rename LocalUsers datastore with a unique ID. More code to auth.go
kreinecke May 22, 2019
a304f05
Add last login field to users table. Add unique version string to Reg…
kreinecke May 22, 2019
9323e4b
Added skeleton code for local users repo.
kreinecke May 22, 2019
7b190bb
Add function to find password hash, to local users repository
kreinecke May 22, 2019
a70924c
Add function to add new local user, to local users repository
kreinecke May 22, 2019
00cf310
Add remainder of code for local user login. Fix build.
kreinecke May 23, 2019
8b54416
Code to initialise local users table on startup when a local user is …
kreinecke May 23, 2019
8596a52
Fix incorrect field ordering on new user insert
kreinecke May 23, 2019
3f934c4
Initial auth test function added to test local login
kreinecke May 23, 2019
b3c5582
Fix convey function ordering for several tests
kreinecke May 29, 2019
e35345c
More tests for local login error cases
kreinecke May 29, 2019
d71dd69
Add unit tests for local user auth and creation. Start work on implem…
kreinecke May 30, 2019
ab982d8
Finish tests for adding local user. Finish config of remote/local use…
kreinecke May 31, 2019
7b83ce9
Finish auth login code and associated unit tests. Fix backend tests, …
kreinecke Jun 4, 2019
caee9df
Tidy up and fix lint errors
kreinecke Jun 5, 2019
9e385f5
Change name of env var for local user scope. Modify console output on…
kreinecke Jun 5, 2019
73e28fa
Refactor portalProxy.AddLocalUser and portalProxy.doLocalLogin for Co…
kreinecke Jun 5, 2019
c695fd3
Fix code climate issues
kreinecke Jun 5, 2019
f07878a
Add LocalUser struct to encapsulate attributes of a local user
kreinecke Jun 6, 2019
1870939
Fix ungraceful jetstream crash during config setup if AUTH_ENDPOINT_T…
kreinecke Jun 6, 2019
607221a
Set auth endpoint to local for Travis build/review verification.
kreinecke Jun 7, 2019
a2d1606
Fix skipping local user creation bug
kreinecke Jun 10, 2019
829294c
Codeclimate fix
kreinecke Jun 10, 2019
d558478
backend test fix
kreinecke Jun 10, 2019
4b2d786
push default config for e2e tests
kreinecke Jun 10, 2019
892fb95
Codeclimate fix
kreinecke Jun 10, 2019
2d00baf
Merge remote-tracking branch 'origin/v2-master' into refactor-setup-c…
richard-cox Jun 14, 2019
3fb9d71
Resolve conflicts
kreinecke Jun 17, 2019
036502c
Merge remote-tracking branch 'origin/v2-master' into refactor-setup-c…
nwmac Jun 18, 2019
0c945f5
Address PR feedback. Add initiial unit test
nwmac Jun 18, 2019
d9ef065
Add a few unit tests while we're here
nwmac Jun 19, 2019
e2fb3ba
Merge local auth changes
nwmac Jun 19, 2019
4bc807a
Clean legacy data from old table on migration
nwmac Jun 19, 2019
bb34148
Fixes
nwmac Jun 19, 2019
0411adc
Fix
nwmac Jun 19, 2019
7d8eedd
Merge remote-tracking branch 'origin/v2-master' into refactor-setup2
nwmac Jul 8, 2019
e7fe908
Fix merge issues
nwmac Jul 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add function to add new local user, to local users repository
Signed-off-by: Kate E. Reinecke <50168367+kreinecke@users.noreply.github.com>
  • Loading branch information
kreinecke committed Jun 10, 2019
commit a70924c42cbf13bb44ec9c243fb062d6c80d6c67
2 changes: 1 addition & 1 deletion src/jetstream/datastore/20190522121200_LocalUsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
createLocalUsers += "password_hash " + binaryDataType + " NOT NULL, "
createLocalUsers += "user_name VARCHAR(36) NOT NULL, "
createLocalUsers += "user_email VARCHAR(36), "
createLocalUsers += "last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP), "
createLocalUsers += "last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP), "
createLocalUsers += "last_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"

if strings.Contains(conf.Driver.Name, "postgres") {
Expand Down
17 changes: 3 additions & 14 deletions src/jetstream/repository/local_users/local_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@ package local_users

import "github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"

//TODO: Can we use the existing ConnectedUser struct here?
// Token -
type Token struct {
UserGUID string
TokenType string
Record interfaces.TokenRecord
}

//TODO: this is currently defined in tokens - do we want to pull this up a level now so it can be referenced for local users as well as token endpoints?
const SystemSharedUserGuid = "00000000-1111-2222-3333-444444444444" // User ID for the system shared user for endpoints

// Repository is an application of the repository pattern for storing tokens
type Repository interface {

SaveUser(userGUID string, username string, email string, role string, passwordHash byte[]) error
AddUser(userGUID string, username string, email string, role string, passwordHash byte[]) error
FindPasswordHash(userGUID string) (hash []byte, error)

//TODO what is best pattern here - varargs e.g. just UpdateUser? or function for each update?
UpdatePasswordHash(userGUID string, passwordHash byte[]) error
UpdateLastLogin(userGUID string, /*TODO: datetime here*/ ) error
//UpdatePasswordHash(userGUID string, passwordHash byte[]) error
//UpdateLastLogin(userGUID string, /*TODO: datetime here*/ ) error

}
53 changes: 51 additions & 2 deletions src/jetstream/repository/local_users/psql_local_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
var findPasswordHash = `SELECT password_hash
FROM local_users
WHERE user_guid = $1`
var insertLocalUser = `INSERT INTO local_users (user_guid, user_guid, token_type, auth_token, refresh_token, token_expiry)
VALUES ($1, $2, $3, $4, $5, $6)`
var insertLocalUser = `INSERT INTO local_users (user_guid, password_hash, user_name, user_email, last_login, last_updated) VALUES ($1, $2, $3, $4, $5, $6)`

// PgsqlTokenRepository is a PostgreSQL-backed token repository
type PgsqlLocalUsersRepository struct {
Expand Down Expand Up @@ -59,3 +58,53 @@ func (p *PgsqlTokenRepository) FindPasswordHash(userGUID string) (hash []byte, e

return passwordHash, nil
}

// AddLocalUser - Add a new local user to the datastore
func (p *PgsqlTokenRepository) AddLocalUser(userGUID string, passwordHash []byte, string, name string, email string) error {

log.Debug("AddLocalUser")

if userGUID == "" {
msg := "Unable to add new local user without a valid User GUID."
log.Debug(msg)
return errors.New(msg)
}

if len(passwordHash) == 0 {
msg := "Unable to add new local user without a valid password hash."
log.Debug(msg)
return errors.New(msg)
}

if name == "" {
msg := "Unable to add new local user without a valid User name."
log.Debug(msg)
return errors.New(msg)
}

// Add the new local user to the DB
var lastLogin, lastUpdated = nil
result, err := p.db.Exec(insertLocalUser, userGUID, passwordHash, name, email, lastLogin, lastUpdated)
if err != nil {
msg := "Unable to INSERT local user: %v"
log.Debugf(msg, err)
return fmt.Errorf(msg, err)
}

rowsUpdates, err := result.RowsAffected()
if err != nil {
return errors.New("Unable to INSERT local user: could not determine number of rows that were updated")
}

if rowsUpdates < 1 {
return errors.New("Unable to INSERT local user: no rows were updated")
}

if rowsUpdates > 1 {
log.Warn("INSERT local user: More than 1 row was updated (expected only 1)")
}

log.Debug("Local user INSERT complete")

return nil
}