github.com/GoogleCloudPlatform/compute-image-tools/cli_tools@v0.0.0-20240516224744-de2dabc4ed1b/common/utils/logging/service/outputinfo_loggable.go (about)

     1  //  Copyright 2020 Google Inc. All Rights Reserved.
     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 service
    16  
    17  import "github.com/GoogleCloudPlatform/compute-image-tools/proto/go/pb"
    18  
    19  // outputInfoLoggable is an implementation of Loggable that exposes fields
    20  // from an OutputInfo object.
    21  type outputInfoLoggable struct {
    22  	outputInfo *pb.OutputInfo
    23  }
    24  
    25  // NewOutputInfoLoggable returns a Loggable that is bacaked by a concrete instance
    26  // of pb.OutputInfo. It's intended as a temporary shim while we
    27  // transition tools to use the ToolLogger type.
    28  func NewOutputInfoLoggable(outputInfo *pb.OutputInfo) Loggable {
    29  	return &outputInfoLoggable{outputInfo}
    30  }
    31  
    32  func (o *outputInfoLoggable) GetValue(key string) string {
    33  	switch key {
    34  	case importFileFormat:
    35  		return o.outputInfo.GetImportFileFormat()
    36  	case inflationType:
    37  		return o.outputInfo.GetInflationType()
    38  	case inflationFallbackReason:
    39  		return o.outputInfo.GetInflationFallbackReason()
    40  	case shadowDiskMatchResult:
    41  		return o.outputInfo.GetShadowDiskMatchResult()
    42  	}
    43  	return ""
    44  }
    45  
    46  func (o *outputInfoLoggable) GetValueAsBool(key string) bool {
    47  	switch key {
    48  	case isUEFICompatibleImage:
    49  		return o.outputInfo.GetIsUefiCompatibleImage()
    50  	case isUEFIDetected:
    51  		return o.outputInfo.GetIsUefiDetected()
    52  	}
    53  	return false
    54  }
    55  
    56  func (o *outputInfoLoggable) GetValueAsInt64Slice(key string) []int64 {
    57  	switch key {
    58  	case targetSizeGb:
    59  		return o.outputInfo.GetTargetsSizeGb()
    60  	case sourceSizeGb:
    61  		return o.outputInfo.GetSourcesSizeGb()
    62  	case inflationTime:
    63  		return o.outputInfo.GetInflationTimeMs()
    64  	case shadowInflationTime:
    65  		return o.outputInfo.GetShadowInflationTimeMs()
    66  	}
    67  	return nil
    68  }
    69  
    70  func (o *outputInfoLoggable) GetInspectionResults() *pb.InspectionResults {
    71  	return o.outputInfo.GetInspectionResults()
    72  }
    73  
    74  func (o *outputInfoLoggable) ReadSerialPortLogs() []string {
    75  	return o.outputInfo.SerialOutputs
    76  }