mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-19 07:45:00 +02:00
Allow Logging to stdout with separate Error Log Channel (#718)
* Add dedicated error logging writer * Document new errors to stdout flag * Update changelog * Thread-safe the log buffer * Address feedback * Remove duplication by adding log level * Clean up error formatting * Apply suggestions from code review Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
co-authored by
Joel Speed
parent
33e04cc52f
commit
d69fd6af22
+2
-2
@@ -202,12 +202,12 @@ func (p *AzureProvider) GetEmailAddress(ctx context.Context, s *sessions.Session
|
||||
|
||||
email, err = json.Get("userPrincipalName").String()
|
||||
if err != nil {
|
||||
logger.Printf("failed making request %s", err)
|
||||
logger.Errorf("failed making request %s", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if email == "" {
|
||||
logger.Printf("failed to get email address")
|
||||
logger.Errorf("failed to get email address")
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ func (p *BitbucketProvider) GetEmailAddress(ctx context.Context, s *sessions.Ses
|
||||
Do().
|
||||
UnmarshalInto(&emails)
|
||||
if err != nil {
|
||||
logger.Printf("failed making request: %v", err)
|
||||
logger.Errorf("failed making request: %v", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func (p *BitbucketProvider) GetEmailAddress(ctx context.Context, s *sessions.Ses
|
||||
Do().
|
||||
UnmarshalInto(&teams)
|
||||
if err != nil {
|
||||
logger.Printf("failed requesting teams membership: %v", err)
|
||||
logger.Errorf("failed requesting teams membership: %v", err)
|
||||
return "", err
|
||||
}
|
||||
var found = false
|
||||
@@ -134,7 +134,7 @@ func (p *BitbucketProvider) GetEmailAddress(ctx context.Context, s *sessions.Ses
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
logger.Print("team membership test failed, access denied")
|
||||
logger.Error("team membership test failed, access denied")
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func (p *BitbucketProvider) GetEmailAddress(ctx context.Context, s *sessions.Ses
|
||||
Do().
|
||||
UnmarshalInto(&repositories)
|
||||
if err != nil {
|
||||
logger.Printf("failed checking repository access: %v", err)
|
||||
logger.Errorf("failed checking repository access: %v", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func (p *BitbucketProvider) GetEmailAddress(ctx context.Context, s *sessions.Ses
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
logger.Print("repository access test failed, access denied")
|
||||
logger.Error("repository access test failed, access denied")
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -212,7 +212,7 @@ func userInGroup(service *admin.Service, groups []string, email string) bool {
|
||||
gerr, ok := err.(*googleapi.Error)
|
||||
switch {
|
||||
case ok && gerr.Code == 404:
|
||||
logger.Printf("error checking membership in group %s: group does not exist", group)
|
||||
logger.Errorf("error checking membership in group %s: group does not exist", group)
|
||||
case ok && gerr.Code == 400:
|
||||
// It is possible for Members.HasMember to return false even if the email is a group member.
|
||||
// One case that can cause this is if the user email is from a different domain than the group,
|
||||
@@ -222,7 +222,7 @@ func userInGroup(service *admin.Service, groups []string, email string) bool {
|
||||
r, err := req.Do()
|
||||
|
||||
if err != nil {
|
||||
logger.Printf("error using get API to check member %s of google group %s: user not in the group", email, group)
|
||||
logger.Errorf("error using get API to check member %s of google group %s: user not in the group", email, group)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func userInGroup(service *admin.Service, groups []string, email string) bool {
|
||||
return true
|
||||
}
|
||||
default:
|
||||
logger.Printf("error checking group membership: %v", err)
|
||||
logger.Errorf("error checking group membership: %v", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@ func stripToken(endpoint string) string {
|
||||
func stripParam(param, endpoint string) string {
|
||||
u, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
logger.Printf("error attempting to strip %s: %s", param, err)
|
||||
logger.Errorf("error attempting to strip %s: %s", param, err)
|
||||
return endpoint
|
||||
}
|
||||
|
||||
if u.RawQuery != "" {
|
||||
values, err := url.ParseQuery(u.RawQuery)
|
||||
if err != nil {
|
||||
logger.Printf("error attempting to strip %s: %s", param, err)
|
||||
logger.Errorf("error attempting to strip %s: %s", param, err)
|
||||
return u.String()
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ func validateToken(ctx context.Context, p Provider, accessToken string, header h
|
||||
WithHeaders(header).
|
||||
Do()
|
||||
if result.Error() != nil {
|
||||
logger.Printf("GET %s", stripToken(endpoint))
|
||||
logger.Printf("token validation request failed: %s", result.Error())
|
||||
logger.Errorf("GET %s", stripToken(endpoint))
|
||||
logger.Errorf("token validation request failed: %s", result.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -71,6 +71,6 @@ func validateToken(ctx context.Context, p Provider, accessToken string, header h
|
||||
if result.StatusCode() == 200 {
|
||||
return true
|
||||
}
|
||||
logger.Printf("token validation request failed: status %d - %s", result.StatusCode(), result.Body())
|
||||
logger.Errorf("token validation request failed: status %d - %s", result.StatusCode(), result.Body())
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (p *KeycloakProvider) GetEmailAddress(ctx context.Context, s *sessions.Sess
|
||||
Do().
|
||||
UnmarshalJSON()
|
||||
if err != nil {
|
||||
logger.Printf("failed making request %s", err)
|
||||
logger.Errorf("failed making request %s", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ func (p *ProviderData) GetClientSecret() (clientSecret string, err error) {
|
||||
// Getting ClientSecret can fail in runtime so we need to report it without returning the file name to the user
|
||||
fileClientSecret, err := ioutil.ReadFile(p.ClientSecretFile)
|
||||
if err != nil {
|
||||
logger.Printf("error reading client secret file %s: %s", p.ClientSecretFile, err)
|
||||
logger.Errorf("error reading client secret file %s: %s", p.ClientSecretFile, err)
|
||||
return "", errors.New("could not read client secret file")
|
||||
}
|
||||
return string(fileClientSecret), nil
|
||||
|
||||
Reference in New Issue
Block a user