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..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() @@ -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) diff --git a/components/docker-auth/pkg/db/connection.go b/components/docker-auth/pkg/db/connection.go index 761b932..e197c7d 100644 --- a/components/docker-auth/pkg/db/connection.go +++ b/components/docker-auth/pkg/db/connection.go @@ -52,13 +52,21 @@ func GetDbConnectionPool() (*sql.DB, error) { return nil, fmt.Errorf("error occurred while establishing database connection pool "+ " : %v", err) } - log.Printf("DB connection pool established") 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. 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=?"