sigs.k8s.io/cluster-api-provider-aws@v1.5.5/cmd/clusterawsadm/resource/type.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package resource
    18  
    19  import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    20  
    21  // AWSResource defines an AWS resource.
    22  type AWSResource struct {
    23  	Partition string `json:"partition"`
    24  	Service   string `json:"service"`
    25  	Region    string `json:"region"`
    26  	AccountID string `json:"account_id"`
    27  	Resource  string `json:"resource"`
    28  	ARN       string `json:"arn"`
    29  }
    30  
    31  // AWSResourceList defines list of AWSResources.
    32  type AWSResourceList struct {
    33  	ClusterName  string        `json:"cluster_name"`
    34  	AWSResources []AWSResource `json:"aws_resources"`
    35  }
    36  
    37  // ToTable converts AWSResourceList to Table.
    38  func (a *AWSResourceList) ToTable() *metav1.Table {
    39  	table := &metav1.Table{
    40  		TypeMeta: metav1.TypeMeta{
    41  			APIVersion: metav1.SchemeGroupVersion.String(),
    42  			Kind:       "Table",
    43  		},
    44  		ColumnDefinitions: []metav1.TableColumnDefinition{
    45  			{
    46  				Name: "Partition",
    47  				Type: "string",
    48  			},
    49  			{
    50  				Name: "Service",
    51  				Type: "string",
    52  			},
    53  			{
    54  				Name: "Region",
    55  				Type: "string",
    56  			},
    57  			{
    58  				Name: "AccountID",
    59  				Type: "string",
    60  			},
    61  			{
    62  				Name: "Resource",
    63  				Type: "string",
    64  			},
    65  			{
    66  				Name: "ARN",
    67  				Type: "string",
    68  			},
    69  		},
    70  	}
    71  
    72  	for _, resource := range a.AWSResources {
    73  		row := metav1.TableRow{
    74  			Cells: []interface{}{resource.Partition, resource.Service, resource.Region, resource.AccountID, resource.Resource, resource.ARN},
    75  		}
    76  		table.Rows = append(table.Rows, row)
    77  	}
    78  	return table
    79  }