David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Ciena Corporation |
| 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 | package config |
| 17 | |
| 18 | import ( |
| 19 | "strconv" |
| 20 | |
| 21 | configv1 "github.com/opencord/voltctl/internal/pkg/apis/config/v1" |
| 22 | configv2 "github.com/opencord/voltctl/internal/pkg/apis/config/v2" |
| 23 | ) |
| 24 | |
| 25 | func FromConfigV1(v1 *configv1.GlobalConfigSpec) *GlobalConfigSpec { |
| 26 | v3 := NewDefaultConfig() |
| 27 | s3 := v3.Current() |
| 28 | |
| 29 | s3.Server = v1.Server |
| 30 | s3.Kafka = v1.Kafka |
| 31 | s3.KvStore = v1.KvStore |
| 32 | s3.Tls.UseTls = v1.Tls.UseTls |
| 33 | s3.Tls.CACert = v1.Tls.CACert |
| 34 | s3.Tls.Cert = v1.Tls.Cert |
| 35 | s3.Tls.Key = v1.Tls.Key |
| 36 | if v1.Tls.Verify != "" { |
| 37 | if b, err := strconv.ParseBool(v1.Tls.Verify); err == nil { |
| 38 | s3.Tls.Verify = b |
| 39 | } |
| 40 | } |
| 41 | s3.Grpc.Timeout = v1.Grpc.Timeout |
| 42 | s3.Grpc.MaxCallRecvMsgSize = v1.Grpc.MaxCallRecvMsgSize |
| 43 | s3.KvStoreConfig.Timeout = v1.KvStoreConfig.Timeout |
| 44 | s3.K8sConfig = v1.K8sConfig |
| 45 | return v3 |
| 46 | } |
| 47 | |
| 48 | func FromConfigV2(v2 *configv2.GlobalConfigSpec) *GlobalConfigSpec { |
| 49 | v3 := NewDefaultConfig() |
| 50 | s3 := v3.Current() |
| 51 | |
| 52 | s3.Server = v2.Server |
| 53 | s3.Kafka = v2.Kafka |
| 54 | s3.KvStore = v2.KvStore |
| 55 | s3.Tls.UseTls = v2.Tls.UseTls |
| 56 | s3.Tls.CACert = v2.Tls.CACert |
| 57 | s3.Tls.Cert = v2.Tls.Cert |
| 58 | s3.Tls.Key = v2.Tls.Key |
| 59 | s3.Tls.Verify = v2.Tls.Verify |
| 60 | s3.Grpc.ConnectTimeout = v2.Grpc.ConnectTimeout |
| 61 | s3.Grpc.Timeout = v2.Grpc.Timeout |
| 62 | s3.Grpc.MaxCallRecvMsgSize = v2.Grpc.MaxCallRecvMsgSize |
| 63 | s3.KvStoreConfig.Timeout = v2.KvStoreConfig.Timeout |
| 64 | s3.K8sConfig = v2.K8sConfig |
| 65 | return v3 |
| 66 | } |