istio
1// Copyright Istio Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package builder16
17import (18"fmt"19"strings"20
21"github.com/hashicorp/go-multierror"22
23"istio.io/istio/pkg/log"24"istio.io/istio/pkg/util/istiomultierror"25)
26
27var authzLog = log.RegisterScope("authorization", "Istio Authorization Policy")28
29type AuthzLogger struct {30debugMsg []string31errMsg *multierror.Error32}
33
34func (al *AuthzLogger) AppendDebugf(format string, args ...any) {35al.debugMsg = append(al.debugMsg, fmt.Sprintf(format, args...))36}
37
38func (al *AuthzLogger) AppendError(err error) {39al.errMsg = multierror.Append(al.errMsg, err)40}
41
42func (al *AuthzLogger) Report() {43if al.errMsg != nil {44al.errMsg.ErrorFormat = istiomultierror.MultiErrorFormat()45authzLog.Errorf("Processed authorization policy: %s", al.errMsg)46}47if authzLog.DebugEnabled() && len(al.debugMsg) != 0 {48out := strings.Join(al.debugMsg, "\n\t* ")49authzLog.Debugf("Processed authorization policy with details:\n\t* %v", out)50} else {51authzLog.Debugf("Processed authorization policy")52}53}
54