Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
223 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package rand | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
const LOWER_CASE = "abcdefghijklmnopqrstuvwxyz" | ||
const UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
const NUMERIC = "1234567890" | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
func StringWithCharset(length int, charset string) string { | ||
b := make([]byte, length) | ||
for i := range b { | ||
b[i] = charset[rand.Intn(len(charset))] | ||
} | ||
return string(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ocistore | ||
|
||
func (s OCIStore) CreateAdminConsolePassword(passwordBcrypt string) (string, error) { | ||
return "", ErrNotImplemented | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package s3pg | ||
|
||
import ( | ||
"database/sql" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/kots/kotsadm/pkg/persistence" | ||
"github.com/replicatedhq/kots/kotsadm/pkg/rand" | ||
) | ||
|
||
func (s S3PGStore) CreateAdminConsolePassword(passwordBcrypt string) (string, error) { | ||
db := persistence.MustGetPGSession() | ||
tx, err := db.Begin() | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to begin transaction") | ||
} | ||
defer tx.Rollback() | ||
|
||
query := `select user_id from ship_user_local where email = $1` | ||
row := tx.QueryRow(query, "default-user@none.com") | ||
|
||
var userID string | ||
if err := row.Scan(&userID); err != nil { | ||
if err != sql.ErrNoRows { | ||
return "", errors.Wrap(err, "failed lookup existing user") | ||
} | ||
|
||
userID = rand.StringWithCharset(32, rand.LOWER_CASE) | ||
query := `insert into ship_user (id, created_at, last_login) values ($1, $2, $3)` | ||
|
||
_, err := tx.Exec(query, userID, time.Now(), time.Now()) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to create ship user") | ||
} | ||
} | ||
|
||
query = `insert into ship_user_local (user_id, password_bcrypt, first_name, last_name, email) | ||
values ($1, $2, $3, $4, $5) ON CONFLICT (email) do update set password_bcrypt = EXCLUDED.password_bcrypt` | ||
_, err = tx.Exec(query, userID, passwordBcrypt, "Default", "User", "default-user@none.com") | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to create ship user local") | ||
} | ||
|
||
if err := tx.Commit(); err != nil { | ||
return "", errors.Wrap(err, "failed to commit transaction") | ||
} | ||
|
||
return userID, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters