You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
7.8 KiB
202 lines
7.8 KiB
// Code generated by go generate; DO NOT EDIT.
|
|
// Copyright 2021 HAProxy Technologies
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
package configuration
|
|
|
|
import (
|
|
"github.com/jessevdk/go-flags"
|
|
"github.com/haproxytech/client-native/v6/models"
|
|
|
|
"github.com/haproxytech/dataplaneapi/misc"
|
|
dpapilog "github.com/haproxytech/dataplaneapi/log"
|
|
)
|
|
{{- range $MainGroup := .Groups}}
|
|
{{- if ne .Name ""}}
|
|
|
|
type configType{{ .Name | Capitalize }} struct {
|
|
{{- range .Attributes}}
|
|
{{- if eq .Type "AtomicString"}}
|
|
{{ .Name }} *string `yaml:"{{ .FileName }},omitempty"`
|
|
{{- else if eq .Type "AtomicInt"}}
|
|
{{ .Name }} *int `yaml:"{{ .FileName }},omitempty"`
|
|
{{- else if eq .Type "AtomicBool"}}
|
|
{{ .Name }} *bool `yaml:"{{ .FileName }},omitempty"`
|
|
{{- else if eq .Type "time.Duration" }}
|
|
{{ .Name }} *string `yaml:"{{ .FileName }},omitempty"`
|
|
{{- else if eq .Type "flagext.ByteSize" }}
|
|
{{ .Name }} *string `yaml:"{{ .FileName }},omitempty"`
|
|
{{- else }}
|
|
{{ .Name }} *{{ .Type }} `yaml:"{{ .FileName }},omitempty"`
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- range $.Groups}}
|
|
{{- if eq $MainGroup.Name .Parent }}
|
|
{{- if .IsList }}
|
|
{{ .Name | Capitalize }} []configType{{ .Name | Capitalize }} `yaml:"{{ .Name }},omitempty"`
|
|
{{- else}}
|
|
{{ .Name | Capitalize }} *configType{{ .Name | Capitalize }} `yaml:"{{ .Name }},omitempty"`
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
}
|
|
{{- end}}
|
|
{{- end}}
|
|
|
|
type StorageDataplaneAPIConfiguration struct {
|
|
Version *int `yaml:"config_version,omitempty"`
|
|
{{- range .Groups}}
|
|
{{- if ne .Name ""}}
|
|
{{- if eq .Parent ""}}
|
|
{{ .Name | Capitalize }} *configType{{ .Name | Capitalize }} `yaml:"{{ .Name }},omitempty"`
|
|
{{- end}}
|
|
{{- else}}
|
|
{{- range .Attributes}}
|
|
{{- if eq .Type "AtomicString"}}
|
|
{{ .Name }} *string `yaml:"{{ .SpecName }},omitempty"`
|
|
{{- else if eq .Type "AtomicInt"}}
|
|
{{ .Name }} *int `yaml:"{{ .SpecName }},omitempty"`
|
|
{{- else if eq .Type "AtomicBool"}}
|
|
{{ .Name }} *bool `yaml:"{{ .SpecName }},omitempty"`
|
|
{{- else if eq .Type "int"}}
|
|
{{ .Name }} *int `yaml:"{{ .SpecName }},omitempty"`
|
|
{{- else}}
|
|
err {{ .Type }} is not supported
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
}
|
|
|
|
func copyToConfiguration(cfg *Configuration) {
|
|
cfgStorage := cfg.storage.Get()
|
|
{{- range $group := .Groups}}
|
|
{{- if $group.IsList }}
|
|
if cfgStorage.{{ $group.Parent | Capitalize }} != nil && cfgStorage.{{ $group.Parent | Capitalize }}.{{ .Name | Capitalize}} != nil {
|
|
cfg.{{ .AttName }} = []{{ .OriginalGroup }}{}
|
|
for _, item := range cfgStorage.{{ $group.Parent | Capitalize }}.{{ .Name | Capitalize}} {
|
|
item{{ $group.OriginalGroup }} := {{ .OriginalGroup }}{
|
|
}
|
|
{{- range .Attributes}}
|
|
if item.{{ .Name }} != nil {
|
|
item{{ $group.OriginalGroup }}.{{ .Name }}= *item.{{ .Name }}
|
|
}
|
|
{{- end}}
|
|
cfg.{{ .AttName }} = append(cfg.{{ .AttName }}, item{{ $group.OriginalGroup }})
|
|
}
|
|
}
|
|
{{- else}}
|
|
{{- range .Attributes}}
|
|
{{- if eq $group.AttName "-" }}
|
|
if cfgStorage.{{ .Name }} != nil {
|
|
cfg.{{ .Name }}.Store(*cfgStorage.{{ .Name }})
|
|
}
|
|
{{- else if ne $group.AttName "" }}
|
|
{{- if eq $group.Parent "" }}
|
|
if cfgStorage.{{ $group.Name | Capitalize }} != nil && cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }} != nil && !misc.HasOSArg("{{ .Short }}", "{{ .Long }}", "{{ .ENV }}") {
|
|
{{- if eq .Type "AtomicString"}}
|
|
cfg.{{ .AttName }}.{{ .Name }}.Store(*cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }})
|
|
{{- else if eq .Type "AtomicInt"}}
|
|
cfg.{{ .AttName }}.{{ .Name }}.Store(*cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }})
|
|
{{- else if eq .Type "AtomicBool"}}
|
|
cfg.{{ .AttName }}.{{ .Name }}.Store(*cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }})
|
|
{{- else}}
|
|
cfg.{{ .AttName }}.{{ .Name }} = *cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }}
|
|
{{- end }}
|
|
{{- else }}
|
|
if cfgStorage.{{ $group.Parent | Capitalize }} !=nil && cfgStorage.{{ $group.Parent | Capitalize }}.{{ $group.Name | Capitalize }} != nil && cfgStorage.{{ $group.Parent | Capitalize }}.{{ $group.Name | Capitalize }}.{{ .Name }} != nil && !misc.HasOSArg("{{ .Short }}", "{{ .Long }}", "{{ .ENV }}") {
|
|
cfg.{{ .AttName }}.{{ .Name }} = *cfgStorage.{{ $group.Parent | Capitalize }}.{{ $group.Name | Capitalize }}.{{ .Name }}
|
|
{{- end }}
|
|
}
|
|
{{- else if ne .StructName "Server"}}
|
|
if cfgStorage.{{ $group.Name | Capitalize }} != nil && cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }} != nil && !misc.HasOSArg("{{ .Short }}", "{{ .Long }}", "{{ .ENV }}") {
|
|
cfg.{{ .AttName }}.{{ .Name }} = *cfgStorage.{{ $group.Name | Capitalize }}.{{ .Name }}
|
|
}
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
}
|
|
|
|
func copyConfigurationToStorage(cfg *Configuration) {
|
|
cfgStorage := cfg.storage.Get()
|
|
|
|
version := 2
|
|
cfgStorage.Version = &version
|
|
|
|
{{ range $group := .Groups}}
|
|
{{ range .Attributes}}
|
|
{{ if eq $group.AttName "-" }}
|
|
{{- if eq .Type "AtomicString" }}
|
|
{{- if not .Deprecated }}
|
|
value{{ .Name }} := cfg.{{ .Name }}.Load()
|
|
cfgStorage.{{ .Name }}= &value{{ .Name }}
|
|
{{- else }}
|
|
cfgStorage.{{ .Name }}= nil
|
|
{{- end }}
|
|
{{- else }}
|
|
|
|
cfgStorage.{{ .Name }} = &cfg.{{ .Name }}
|
|
{{- end}}
|
|
{{ else }}
|
|
{{- if .Save }}
|
|
{{- if eq .Type "AtomicString" }}
|
|
{{- if not .Deprecated }}
|
|
value{{$group.Name | Capitalize}}{{ .Name }} := cfg.{{ .AttName }}.{{ .Name }}.Load()
|
|
if cfgStorage.Cluster == nil {
|
|
cfgStorage.{{ .AttName }} = &configType{{ .AttName }}{}
|
|
}
|
|
cfgStorage.{{ .AttName }}.{{ .Name }}= &value{{$group.Name | Capitalize}}{{ .Name }}
|
|
{{- else }}
|
|
if cfgStorage.Cluster != nil {
|
|
cfgStorage.{{ .AttName }}.{{ .Name }}= nil
|
|
}
|
|
{{- end }}
|
|
{{- else if eq .Type "AtomicBool" }}
|
|
value{{$group.Name | Capitalize}}{{ .Name }} := cfg.{{ .AttName }}.{{ .Name }}.Load()
|
|
if cfgStorage.Cluster == nil {
|
|
cfgStorage.{{ .AttName }} = &configType{{ .AttName }}{}
|
|
}
|
|
if cfgStorage.Cluster != nil {
|
|
cfgStorage.{{ .AttName }}.{{ .Name }}= &value{{$group.Name | Capitalize}}{{ .Name }}
|
|
}
|
|
{{- else if eq .Type "AtomicInt" }}
|
|
{{- if not .Deprecated }}
|
|
value{{$group.Name | Capitalize}}{{ .Name }} := cfg.{{ .AttName }}.{{ .Name }}.Load()
|
|
if cfgStorage.Cluster == nil {
|
|
cfgStorage.{{ .AttName }} = &configType{{ .AttName }}{}
|
|
}
|
|
cfgStorage.{{ .AttName }}.{{ .Name }}= &value{{$group.Name | Capitalize}}{{ .Name }}
|
|
{{- else }}
|
|
if cfgStorage.Cluster != nil {
|
|
cfgStorage.{{ .AttName }}.{{ .Name }}= nil
|
|
}
|
|
{{- end }}
|
|
{{- else}}
|
|
{{- if $group.Parent }}
|
|
if cfgStorage.{{ $group.Parent | Capitalize }} == nil {
|
|
cfgStorage.{{ $group.Parent | Capitalize }} = &configType{{ $group.Parent | Capitalize }}{}
|
|
}
|
|
{{- end }}
|
|
if cfgStorage{{ if $group.Parent }}.{{ $group.Parent | Capitalize }}{{ end }}.{{$group.Name | Capitalize}} == nil {
|
|
cfgStorage{{ if $group.Parent }}.{{ $group.Parent | Capitalize }}{{ end }}.{{$group.Name | Capitalize }} = &configType{{$group.Name | Capitalize}}{}
|
|
}
|
|
cfgStorage{{ if $group.Parent }}.{{ $group.Parent | Capitalize }}{{ end }}.{{$group.Name | Capitalize}}.{{ .Name }} = &cfg.{{ .AttName }}.{{ .Name }}
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
}
|
|
|