Skip to content

Commit

Permalink
Merge branch 'master' into application-services-tab
Browse files Browse the repository at this point in the history
* master: (33 commits)
  Updated post-flight script in response to feedback
  Add issue_template and cf push log docs
  Fix incorrect caching and reset behaviour of app wall filters - Ensure that when we reset dodgy cluster/org values we also reset org/space - Previously we were showing filter by 'all' for org/space but still applying filter containing valid org/space guid - Reset fixed by not entering dodgy state
  Fix create app commit button text
  Fix the title of the manage users dialog - When managing a single user the user's name was missing from the title - Ensure async task dialog also includes translate-values just like detail view
  Add readme for deploy/uaa
  Temporary fix for gulp-sourcemaps
  Two minor fixes - Ensure we clear any invlaid locale from local storage - Token expired warning now covers the entire endpoint dashboard table again
  Fix another typo
  Changes in response to feedback
  Rename cnap headers to cap (#1235)
  Add context labels to CI tasks
  Fix e2e #2
  E2E fix
  Workaround for chome bug - Tripple click on endpoint dashboard endpoint url lead to selection of icon as well "https://api.10.84.93.96.nip.io:8443
  Update helm chart to use mariaDB
  Fix unit tests
  Fix unit tests
  Undo helm changes, as these will be done in a different PR
  Add support for mysql
  ...
  • Loading branch information
KlapTrap committed Sep 11, 2017
2 parents a2967dc + d335d72 commit 531e483
Show file tree
Hide file tree
Showing 171 changed files with 13,804 additions and 2,275 deletions.
10 changes: 5 additions & 5 deletions build/coverage.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
jasmine.getEnv().addReporter(new function () {
var deferred = [];
var results = [];
/*
this.specStarted = function (spec) {
console.log('Spec Start : ' + spec.id + ':: ' + spec.fullName);
};
*/
/*
this.specStarted = function (spec) {
console.log('Spec Start : ' + spec.id + ':: ' + spec.fullName);
};
*/
this.specDone = function (spec) {
//console.log('Spec Finished: ' + spec.id + ':: ' + spec.fullName);
if (spec.status !== 'failed' && spec.status !== 'disabled') {
Expand Down
2 changes: 1 addition & 1 deletion build/gulp.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
'bootstrap-sass': {
main: [
// 'assets/stylesheets/_bootstrap.scss'
// 'assets/stylesheets/_bootstrap.scss'
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions build/i18n.gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
contents: new Buffer(res)
});

// console.log(res);
// console.log(res);
that.push(file);
});

Expand Down Expand Up @@ -98,7 +98,7 @@
dest[k] = v;
}
} else {
// Merge again
// Merge again
merge(dest[k], v);
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
browser.addMockModule('disableNgAnimate', disableNgAnimate);

// Optional. Really nice to see the progress of the tests while executing
var SpecReporter = require('jasmine-spec-reporter');
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({
displayPendingSpec: false,
displayPendingSummary: false,
Expand Down
8 changes: 4 additions & 4 deletions components/about-app/src/plugin.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// register this plugin application to the platform
if (env && env.registerApplication) {
env.registerApplication(
'aboutApp', // plugin application identity
'about-app', // plugin application's root angular module name
'plugins/about-app/', // plugin application's base path
'about-app' // plugin applications's start state
'aboutApp', // plugin application identity
'about-app', // plugin application's root angular module name
'plugins/about-app/', // plugin application's base path
'about-app' // plugin applications's start state
);
}

Expand Down
13 changes: 11 additions & 2 deletions components/app-core/backend/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const UAAAdminIdentifier = "stratos.admin"
const CFAdminIdentifier = "cloud_controller.admin"

// SessionExpiresOnHeader Custom header for communicating the session expiry time to clients
const SessionExpiresOnHeader = "X-Cnap-Session-Expires-On"
const SessionExpiresOnHeader = "X-Cap-Session-Expires-On"

// EmptyCookieMatcher - Used to detect and remove empty Cookies sent by certain browsers
var EmptyCookieMatcher *regexp.Regexp = regexp.MustCompile(portalSessionName + "=(?:;[ ]*|$)")
Expand Down Expand Up @@ -184,7 +184,6 @@ func (p *portalProxy) DoLoginToCNSI(c echo.Context, cnsiGUID string) (*interface
}

func (p *portalProxy) verifyLoginToCNSI(c echo.Context) error {

log.Debug("verifyLoginToCNSI")

cnsiGUID := c.FormValue("cnsi_guid")
Expand Down Expand Up @@ -327,6 +326,7 @@ func (p *portalProxy) logout(c echo.Context) error {

func (p *portalProxy) getUAATokenWithCreds(skipSSLValidation bool, username, password, client, clientSecret, authEndpoint string) (*UAAResponse, error) {
log.Debug("getUAATokenWithCreds")

body := url.Values{}
body.Set("grant_type", "password")
body.Set("username", username)
Expand All @@ -338,6 +338,7 @@ func (p *portalProxy) getUAATokenWithCreds(skipSSLValidation bool, username, pas

func (p *portalProxy) getUAATokenWithRefreshToken(skipSSLValidation bool, refreshToken, client, clientSecret, authEndpoint string) (*UAAResponse, error) {
log.Debug("getUAATokenWithRefreshToken")

body := url.Values{}
body.Set("grant_type", "refresh_token")
body.Set("refresh_token", refreshToken)
Expand Down Expand Up @@ -386,6 +387,7 @@ func (p *portalProxy) getUAAToken(body url.Values, skipSSLValidation bool, clien

func (p *portalProxy) saveUAAToken(u userTokenInfo, authTok string, refreshTok string) (interfaces.TokenRecord, error) {
log.Debug("saveUAAToken")

key := u.UserGUID
tokenRecord := interfaces.TokenRecord{
AuthToken: authTok,
Expand All @@ -403,6 +405,7 @@ func (p *portalProxy) saveUAAToken(u userTokenInfo, authTok string, refreshTok s

func (p *portalProxy) saveCNSIToken(cnsiID string, u userTokenInfo, authTok string, refreshTok string) (interfaces.TokenRecord, error) {
log.Debug("saveCNSIToken")

tokenRecord := interfaces.TokenRecord{
AuthToken: authTok,
RefreshToken: refreshTok,
Expand All @@ -420,6 +423,7 @@ func (p *portalProxy) saveCNSIToken(cnsiID string, u userTokenInfo, authTok stri

func (p *portalProxy) deleteCNSIToken(cnsiID string, userGUID string) error {
log.Debug("deleteCNSIToken")

err := p.unsetCNSITokenRecord(cnsiID, userGUID)
if err != nil {
log.Errorf("%v", err)
Expand All @@ -431,6 +435,7 @@ func (p *portalProxy) deleteCNSIToken(cnsiID string, userGUID string) error {

func (p *portalProxy) GetUAATokenRecord(userGUID string) (interfaces.TokenRecord, error) {
log.Debug("GetUAATokenRecord")

tokenRepo, err := tokens.NewPgsqlTokenRepository(p.DatabaseConnectionPool)
if err != nil {
log.Errorf("Database error getting repo for UAA token: %v", err)
Expand All @@ -448,6 +453,7 @@ func (p *portalProxy) GetUAATokenRecord(userGUID string) (interfaces.TokenRecord

func (p *portalProxy) setUAATokenRecord(key string, t interfaces.TokenRecord) error {
log.Debug("setUAATokenRecord")

tokenRepo, err := tokens.NewPgsqlTokenRepository(p.DatabaseConnectionPool)
if err != nil {
return fmt.Errorf("Database error getting repo for UAA token: %v", err)
Expand All @@ -463,6 +469,7 @@ func (p *portalProxy) setUAATokenRecord(key string, t interfaces.TokenRecord) er

func (p *portalProxy) verifySession(c echo.Context) error {
log.Debug("verifySession")

sessionExpireTime, err := p.GetSessionInt64Value(c, "exp")
if err != nil {
msg := "Could not find session date"
Expand Down Expand Up @@ -542,6 +549,7 @@ func (p *portalProxy) verifySession(c echo.Context) error {

func (p *portalProxy) getUAAUser(userGUID string) (*interfaces.ConnectedUser, error) {
log.Debug("getUAAUser")

// get the uaa token record
uaaTokenRecord, err := p.GetUAATokenRecord(userGUID)
if err != nil {
Expand Down Expand Up @@ -573,6 +581,7 @@ func (p *portalProxy) getUAAUser(userGUID string) (*interfaces.ConnectedUser, er

func (p *portalProxy) GetCNSIUser(cnsiGUID string, userGUID string) (*interfaces.ConnectedUser, bool) {
log.Debug("GetCNSIUser")

// get the uaa token record
cfTokenRecord, ok := p.GetCNSITokenRecord(cnsiGUID, userGUID)
if !ok {
Expand Down
79 changes: 60 additions & 19 deletions components/app-core/backend/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@ import (
"github.com/SUSE/stratos-ui/components/app-core/backend/config"

log "github.com/Sirupsen/logrus"
// Mysql driver
_ "github.com/go-sql-driver/mysql"
"github.com/kat-co/vala"
// SQL Lite 3
// Sqlite driver
_ "github.com/mattn/go-sqlite3"
)

const (
// SQLite DB Provider
SQLITE string = "sqlite"
// PGSQL DB Provider
PGSQL = "pgsql"
// MYSQL DB Provider
MYSQL = "mysql"
)

// DatabaseConfig represents the connection configuration parameters
type DatabaseConfig struct {
DatabaseProvider string `configName:"DATABASE_PROVIDER"`
Username string `configName:"PGSQL_USER"`
Password string `configName:"PGSQL_PASSWORD"`
Database string `configName:"PGSQL_DATABASE"`
Host string `configName:"PGSQL_HOST"`
Port int `configName:"PGSQL_PORT"`
SSLMode string `configName:"PGSQL_SSL_MODE"`
ConnectionTimeoutInSecs int `configName:"PGSQL_CONNECT_TIMEOUT_IN_SECS"`
SSLCertificate string `configName:"PGSQL_CERT"`
SSLKey string `configName:"PGSQL_CERT_KEY"`
SSLRootCertificate string `configName:"PGSQL_ROOT_CERT"`
Username string `configName:"DB_USER"`
Password string `configName:"DB_PASSWORD"`
Database string `configName:"DB_DATABASE_NAME"`
Host string `configName:"DB_HOST"`
Port int `configName:"DB_PORT"`
SSLMode string `configName:"DB_SSL_MODE"`
ConnectionTimeoutInSecs int `configName:"DB_CONNECT_TIMEOUT_IN_SECS"`
SSLCertificate string `configName:"DB_CERT"`
SSLKey string `configName:"DB_CERT_KEY"`
SSLRootCertificate string `configName:"DB_ROOT_CERT"`
}

// SSLValidationMode is the PostgreSQL driver SSL validation modes
Expand All @@ -48,7 +59,7 @@ const (
// SQLiteDatabaseFile - SQLite database file
SQLiteDatabaseFile = "./console-database.db"
// Default database provider when not specified
DefaultDatabaseProvider = "pgsql"
DefaultDatabaseProvider = MYSQL
)

const (
Expand All @@ -73,7 +84,7 @@ func NewDatabaseConnectionParametersFromConfig(dc DatabaseConfig) (DatabaseConfi
}

// No configuration needed for SQLite
if dc.DatabaseProvider == "sqlite" {
if dc.DatabaseProvider == SQLITE {
return dc, nil
}

Expand All @@ -84,12 +95,15 @@ func NewDatabaseConnectionParametersFromConfig(dc DatabaseConfig) (DatabaseConfi
return dc, err
}

if dc.SSLMode == string(SSLDisabled) || dc.SSLMode == string(SSLRequired) ||
dc.SSLMode == string(SSLVerifyCA) || dc.SSLMode == string(SSLVerifyFull) {
if dc.DatabaseProvider == PGSQL {
if dc.SSLMode == string(SSLDisabled) || dc.SSLMode == string(SSLRequired) ||
dc.SSLMode == string(SSLVerifyCA) || dc.SSLMode == string(SSLVerifyFull) {
return dc, nil
}
} else if dc.DatabaseProvider == MYSQL {
return dc, nil
}

return dc, fmt.Errorf("Invalid SSL mode: %v", dc.SSLMode)
return dc, fmt.Errorf("Invalid provider %v", dc)
}

func validateRequiredDatabaseParams(username, password, database, host string, port int) (err error) {
Expand All @@ -114,10 +128,15 @@ func validateRequiredDatabaseParams(username, password, database, host string, p
func GetConnection(dc DatabaseConfig) (*sql.DB, error) {
log.Debug("GetConnection")

if dc.DatabaseProvider == "pgsql" {
if dc.DatabaseProvider == PGSQL {
return sql.Open("postgres", buildConnectionString(dc))
}

if dc.DatabaseProvider == MYSQL {
return sql.Open("mysql", buildConnectionStringForMysql(dc))

}

// SQL Lite
return GetSQLLiteConnection()
}
Expand Down Expand Up @@ -210,6 +229,28 @@ func buildConnectionString(dc DatabaseConfig) string {
return connStr
}

func buildConnectionStringForMysql(dc DatabaseConfig) string {
log.Println("buildConnectionString")
escapeStr := func(in string) string {
return strings.Replace(in, `'`, `\'`, -1)
}

connStr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true",
escapeStr(dc.Username),
escapeStr(dc.Password),
dc.Host,
dc.Port,
escapeStr(dc.Database))

log.Printf("DB Connection string: %s:*********@tcp(%s:%d)/%s?parseTime=true",
escapeStr(dc.Username),
dc.Host,
dc.Port,
escapeStr(dc.Database))

return connStr
}

// Ping - ping the database to ensure the connection/pool works.
func Ping(db *sql.DB) error {
log.Debug("Ping database")
Expand All @@ -226,7 +267,7 @@ func Ping(db *sql.DB) error {
// SQLite uses ?
func ModifySQLStatement(sql string, databaseProvider string) string {

if databaseProvider == "sqlite" {
if databaseProvider == SQLITE || databaseProvider == MYSQL {
sqlParamReplace := regexp.MustCompile("\\$[0-9]")
return sqlParamReplace.ReplaceAllString(sql, "?")
}
Expand Down
14 changes: 7 additions & 7 deletions components/app-core/backend/development.rc.sample
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export GITHUB_OAUTH_STATE=thisshouldberando
# All the things #
###################

export PGSQL_USER='console'
export PGSQL_PASSWORD='console'
export PGSQL_DATABASE='console-db'
export PGSQL_HOST='localhost'
export PGSQL_PORT=5432
export PGSQL_CONNECT_TIMEOUT_IN_SECS=100
export PGSQL_SSL_MODE='disable'
export DB_USER='console'
export DB_PASSWORD='console'
export DB_DATABASE_NAME='console-db'
export DB_HOST='localhost'
export DB_PORT=5432
export DB_CONNECT_TIMEOUT_IN_SECS=100
export DB_SSL_MODE='disable'

export HTTP_CLIENT_TIMEOUT_IN_SECS=100
export SKIP_SSL_VALIDATION='true'
Expand Down
18 changes: 10 additions & 8 deletions components/app-core/backend/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion components/app-core/backend/glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import:
version: ~1.1.0
- package: github.com/gorilla/websocket
version: ~1.1.0
# No release was cut
- package: github.com/kat-co/vala
version: 43c3f19f86f47a7a83ce5656a1dd8fee3da5d12b
- package: github.com/labstack/echo
Expand All @@ -32,6 +31,9 @@ import:
version: ^1.1.0
- package: github.com/gorilla/securecookie
version: ~1.1.0
- package: github.com/go-sql-driver/mysql
version: ^1.3.0
- package: github.com/irfanhabib/mysqlstore
testImport:
- package: github.com/smartystreets/goconvey
version: 1.6.2
Expand Down
Loading

0 comments on commit 531e483

Please sign in to comment.