github.com/zntrio/harp/v2@v2.0.9/pkg/bundle/template/visitor/decorator.go (about)

     1  // Licensed to Elasticsearch B.V. under one or more contributor
     2  // license agreements. See the NOTICE file distributed with
     3  // this work for additional information regarding copyright
     4  // ownership. Elasticsearch B.V. licenses this file to you under
     5  // the Apache License, Version 2.0 (the "License"); you may
     6  // not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  package visitor
    19  
    20  import (
    21  	bundlev1 "github.com/zntrio/harp/v2/api/gen/go/harp/bundle/v1"
    22  )
    23  
    24  // -----------------------------------------------------------------------------
    25  
    26  // InfrastructureDecorator decorates an bundle template infrastructure namespace
    27  // to make it visitable.
    28  func InfrastructureDecorator(entity *bundlev1.InfrastructureNS) InfrastructureAcceptor {
    29  	return &infrastructureDecorator{
    30  		entity: entity,
    31  	}
    32  }
    33  
    34  type infrastructureDecorator struct {
    35  	entity *bundlev1.InfrastructureNS
    36  }
    37  
    38  func (w *infrastructureDecorator) Accept(v InfrastructureVisitor) {
    39  	v.VisitForProvider(w.entity)
    40  }
    41  
    42  // -----------------------------------------------------------------------------
    43  
    44  // PlatformDecorator decorates an bundle template platform namespace
    45  // to make it visitable.
    46  func PlatformDecorator(entity *bundlev1.PlatformRegionNS) PlatformAcceptor {
    47  	return &platformDecorator{
    48  		entity: entity,
    49  	}
    50  }
    51  
    52  type platformDecorator struct {
    53  	entity *bundlev1.PlatformRegionNS
    54  }
    55  
    56  func (w *platformDecorator) Accept(v PlatformVisitor) {
    57  	v.VisitForRegion(w.entity)
    58  }
    59  
    60  // -----------------------------------------------------------------------------
    61  
    62  // ProductDecorator decorates an bundle template product namespace
    63  // to make it visitable.
    64  func ProductDecorator(entity *bundlev1.ProductComponentNS) ProductAcceptor {
    65  	return &productDecorator{
    66  		entity: entity,
    67  	}
    68  }
    69  
    70  type productDecorator struct {
    71  	entity *bundlev1.ProductComponentNS
    72  }
    73  
    74  func (w *productDecorator) Accept(v ProductVisitor) {
    75  	v.VisitForComponent(w.entity)
    76  }
    77  
    78  // -----------------------------------------------------------------------------
    79  
    80  // ApplicationDecorator decorates an bundle template application namespace
    81  // to make it visitable.
    82  func ApplicationDecorator(entity *bundlev1.ApplicationComponentNS) ApplicationAcceptor {
    83  	return &applicationDecorator{
    84  		entity: entity,
    85  	}
    86  }
    87  
    88  type applicationDecorator struct {
    89  	entity *bundlev1.ApplicationComponentNS
    90  }
    91  
    92  func (w *applicationDecorator) Accept(v ApplicationVisitor) {
    93  	v.VisitForComponent(w.entity)
    94  }