istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/util/configdump/util.go (about)

     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  
    15  package configdump
    16  
    17  import (
    18  	"fmt"
    19  
    20  	anypb "google.golang.org/protobuf/types/known/anypb"
    21  )
    22  
    23  type configTypeURL string
    24  
    25  // See https://www.envoyproxy.io/docs/envoy/latest/api-v3/admin/v3/config_dump.proto
    26  const (
    27  	bootstrap configTypeURL = "type.googleapis.com/envoy.admin.v3.BootstrapConfigDump"
    28  	listeners configTypeURL = "type.googleapis.com/envoy.admin.v3.ListenersConfigDump"
    29  	endpoints configTypeURL = "type.googleapis.com/envoy.admin.v3.EndpointsConfigDump"
    30  	clusters  configTypeURL = "type.googleapis.com/envoy.admin.v3.ClustersConfigDump"
    31  	routes    configTypeURL = "type.googleapis.com/envoy.admin.v3.RoutesConfigDump"
    32  	secrets   configTypeURL = "type.googleapis.com/envoy.admin.v3.SecretsConfigDump"
    33  	ecds      configTypeURL = "type.googleapis.com/envoy.admin.v3.EcdsConfigDump"
    34  )
    35  
    36  // getSection takes a TypeURL and returns the types.Any from the config dump corresponding to that URL
    37  func (w *Wrapper) getSection(sectionTypeURL configTypeURL) (*anypb.Any, error) {
    38  	var dumpAny *anypb.Any
    39  	for _, conf := range w.Configs {
    40  		if conf.TypeUrl == string(sectionTypeURL) {
    41  			dumpAny = conf
    42  		}
    43  	}
    44  	if dumpAny == nil {
    45  		return nil, fmt.Errorf("config dump has no configuration type %s", sectionTypeURL)
    46  	}
    47  
    48  	return dumpAny, nil
    49  }
    50  
    51  func (w *Wrapper) getSections(sectionTypeURL configTypeURL) ([]*anypb.Any, error) {
    52  	var dumpAny []*anypb.Any
    53  	for _, conf := range w.Configs {
    54  		if conf.TypeUrl == string(sectionTypeURL) {
    55  			dumpAny = append(dumpAny, conf)
    56  		}
    57  	}
    58  	if dumpAny == nil {
    59  		return nil, fmt.Errorf("config dump has no configuration type %s", sectionTypeURL)
    60  	}
    61  
    62  	return dumpAny, nil
    63  }