From ad22f2ca1270d10547b1159f367e3cb2a6a6ed50 Mon Sep 17 00:00:00 2001 From: madushajg Date: Wed, 17 Jul 2019 13:49:51 +0530 Subject: [PATCH 1/3] Refactor logs --- components/docker-auth/cmd/authserver/auth_server.go | 3 +-- components/docker-auth/pkg/auth/authn_handler.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/docker-auth/cmd/authserver/auth_server.go b/components/docker-auth/cmd/authserver/auth_server.go index 626fa32..6a1d791 100644 --- a/components/docker-auth/cmd/authserver/auth_server.go +++ b/components/docker-auth/cmd/authserver/auth_server.go @@ -61,8 +61,7 @@ func main() { log.Printf("[%s] Error occured while decoding POST request for authentication : %s", execId, err) } - log.Printf("[%s] Authentication request received by server. Uname : %s, Token : %s", execId, - authParams.UName, authParams.Token) + log.Printf("[%s] Authentication request received by server for Uname : %s", execId, authParams.UName) authnRes := auth.Authenticate(authParams.UName, authParams.Token, execId) diff --git a/components/docker-auth/pkg/auth/authn_handler.go b/components/docker-auth/pkg/auth/authn_handler.go index caac8cb..a75fb79 100644 --- a/components/docker-auth/pkg/auth/authn_handler.go +++ b/components/docker-auth/pkg/auth/authn_handler.go @@ -284,7 +284,7 @@ func resolveCredentials(execId string) (string, string, bool) { func isValidUser(tokenUsername interface{}, providedUsername string, execId string) bool { if username, ok := tokenUsername.(string); ok { usernameTokens := strings.Split(username, "@") - log.Printf("[%s] User needed to be validated %s with provided username %s\n", + log.Printf("[%s] User %s, needed to be validated with provided username %s\n", execId, usernameTokens[0], providedUsername) if providedUsername == usernameTokens[0] { log.Printf("[%s] User received is valid\n", execId) From e0184437fc0dfc9bc50937f9653abc9c93b7b797 Mon Sep 17 00:00:00 2001 From: madushajg Date: Wed, 17 Jul 2019 21:02:41 +0530 Subject: [PATCH 2/3] fix mysql restart in minikube issue --- components/docker-auth/pkg/db/connection.go | 11 ++++++++++- components/docker-auth/pkg/extension/constants.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/docker-auth/pkg/db/connection.go b/components/docker-auth/pkg/db/connection.go index 761b932..1884050 100644 --- a/components/docker-auth/pkg/db/connection.go +++ b/components/docker-auth/pkg/db/connection.go @@ -52,13 +52,22 @@ func GetDbConnectionPool() (*sql.DB, error) { return nil, fmt.Errorf("error occurred while establishing database connection pool "+ " : %v", err) } - log.Printf("DB connection pool established") + + err = dbConnection.Ping() + if err != nil { + log.Printf("Failed to ping database connection pool: %s", err) + return nil, fmt.Errorf("error occurred while pinging database connection pool "+ + " : %v", err) + } + log.Printf("Ping successful") dbConnection.SetMaxOpenConns(dbPoolConfigurations[extension.MaxIdleConnectionsEnvVar]) dbConnection.SetMaxIdleConns(dbPoolConfigurations[extension.ConnectionMaxLifetimeEnvVar]) dbConnection.SetConnMaxLifetime(time.Minute * time.Duration(dbPoolConfigurations[extension. ConnectionMaxLifetimeEnvVar])) + log.Printf("DB connection pool established") + return dbConnection, nil } diff --git a/components/docker-auth/pkg/extension/constants.go b/components/docker-auth/pkg/extension/constants.go index 1639bdb..81f8c80 100644 --- a/components/docker-auth/pkg/extension/constants.go +++ b/components/docker-auth/pkg/extension/constants.go @@ -41,7 +41,7 @@ const ExecIdHeaderName = "x-cellery-hub-exec-id" const getVisibilityQuery = "SELECT VISIBILITY FROM REGISTRY_ARTIFACT_IMAGE " + "INNER JOIN REGISTRY_ORGANIZATION ON REGISTRY_ORGANIZATION.ORG_NAME=REGISTRY_ARTIFACT_IMAGE.ORG_NAME " + "WHERE REGISTRY_ARTIFACT_IMAGE.IMAGE_NAME=? AND " + - "REGISTRY_ORGANIZATION.ORG_NAME = ? LIMIT 1" + "REGISTRY_ORGANIZATION.ORG_NAME=? LIMIT 1" const getUserAvailabilityQuery = "SELECT 1 FROM " + "REGISTRY_ORG_USER_MAPPING " + "WHERE REGISTRY_ORG_USER_MAPPING.USER_UUID=? AND REGISTRY_ORG_USER_MAPPING.ORG_NAME=?" From 609e79a5cb136928460ccd59c733893ebf87eebb Mon Sep 17 00:00:00 2001 From: madushajg Date: Fri, 19 Jul 2019 09:40:00 +0530 Subject: [PATCH 3/3] Fix wrong exit in docker auth --- components/docker-auth/pkg/auth/authn_handler.go | 2 +- components/docker-auth/pkg/db/connection.go | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/components/docker-auth/pkg/auth/authn_handler.go b/components/docker-auth/pkg/auth/authn_handler.go index a75fb79..ab51b2b 100644 --- a/components/docker-auth/pkg/auth/authn_handler.go +++ b/components/docker-auth/pkg/auth/authn_handler.go @@ -218,7 +218,7 @@ func validateAccessToken(token string, providedUsername string, execId string) b } else if res.StatusCode != http.StatusOK { log.Printf("[%s] Error while calling IDP, status code :%d. Exiting without authorization\n", execId, res.StatusCode) - os.Exit(extension.ErrorExitCode) + return false } defer res.Body.Close() diff --git a/components/docker-auth/pkg/db/connection.go b/components/docker-auth/pkg/db/connection.go index 1884050..e197c7d 100644 --- a/components/docker-auth/pkg/db/connection.go +++ b/components/docker-auth/pkg/db/connection.go @@ -53,20 +53,19 @@ func GetDbConnectionPool() (*sql.DB, error) { " : %v", err) } + dbConnection.SetMaxOpenConns(dbPoolConfigurations[extension.MaxIdleConnectionsEnvVar]) + dbConnection.SetMaxIdleConns(dbPoolConfigurations[extension.ConnectionMaxLifetimeEnvVar]) + dbConnection.SetConnMaxLifetime(time.Minute * time.Duration(dbPoolConfigurations[extension. + ConnectionMaxLifetimeEnvVar])) + err = dbConnection.Ping() if err != nil { log.Printf("Failed to ping database connection pool: %s", err) return nil, fmt.Errorf("error occurred while pinging database connection pool "+ " : %v", err) } - log.Printf("Ping successful") - - dbConnection.SetMaxOpenConns(dbPoolConfigurations[extension.MaxIdleConnectionsEnvVar]) - dbConnection.SetMaxIdleConns(dbPoolConfigurations[extension.ConnectionMaxLifetimeEnvVar]) - dbConnection.SetConnMaxLifetime(time.Minute * time.Duration(dbPoolConfigurations[extension. - ConnectionMaxLifetimeEnvVar])) - log.Printf("DB connection pool established") + log.Printf("Ping successful. DB connection pool established") return dbConnection, nil }