github.com/hernad/nomad@v1.6.112/nomad/structs/config/sentinel.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package config
     5  
     6  import (
     7  	"github.com/hernad/nomad/helper"
     8  	"golang.org/x/exp/slices"
     9  )
    10  
    11  // SentinelConfig is configuration specific to Sentinel
    12  type SentinelConfig struct {
    13  	// Imports are the configured imports
    14  	Imports []*SentinelImport `hcl:"import,expand"`
    15  }
    16  
    17  func (s *SentinelConfig) Copy() *SentinelConfig {
    18  	if s == nil {
    19  		return nil
    20  	}
    21  
    22  	ns := *s
    23  	ns.Imports = helper.CopySlice(s.Imports)
    24  	return &ns
    25  }
    26  
    27  // SentinelImport is used per configured import
    28  type SentinelImport struct {
    29  	Name string   `hcl:",key"`
    30  	Path string   `hcl:"path"`
    31  	Args []string `hcl:"args"`
    32  }
    33  
    34  func (s *SentinelImport) Copy() *SentinelImport {
    35  	if s == nil {
    36  		return nil
    37  	}
    38  
    39  	ns := *s
    40  	ns.Args = slices.Clone(s.Args)
    41  	return &ns
    42  }
    43  
    44  // Merge is used to merge two Sentinel configs together. The settings from the input always take precedence.
    45  func (a *SentinelConfig) Merge(b *SentinelConfig) *SentinelConfig {
    46  	result := *a
    47  	if len(b.Imports) > 0 {
    48  		result.Imports = append(result.Imports, b.Imports...)
    49  	}
    50  	return &result
    51  }