Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 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 | |
| 17 | package config |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "flag" |
Elia Battiston | aa7a048 | 2022-08-17 12:24:02 +0000 | [diff] [blame^] | 22 | "time" |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | type BBFAdapterConfig struct { |
| 26 | PrintVersion bool |
| 27 | PrintBanner bool |
| 28 | LogLevel string |
| 29 | ProbeAddress string |
| 30 | TraceEnabled bool |
| 31 | TraceAgentAddress string |
| 32 | LogCorrelationEnabled bool |
Elia Battiston | be9edc1 | 2022-03-09 11:35:58 +0100 | [diff] [blame] | 33 | VolthaNbiEndpoint string |
| 34 | TlsEnabled bool |
| 35 | TlsVerify bool |
| 36 | OnosRestEndpoint string |
| 37 | OnosUser string |
| 38 | OnosPassword string |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 39 | SchemaMountFilePath string |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame] | 40 | KafkaClusterAddress string |
Elia Battiston | aa7a048 | 2022-08-17 12:24:02 +0000 | [diff] [blame^] | 41 | KvStoreType string |
| 42 | KvStoreAddress string |
| 43 | KvStoreTimeout time.Duration |
| 44 | KvStorePrefix string |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // LoadConfig loads the BBF adapter configuration through |
| 48 | // default values and CLI arguments |
| 49 | func LoadConfig(ctx context.Context) *BBFAdapterConfig { |
| 50 | conf := getDefaultConfig() |
| 51 | |
| 52 | flag.StringVar(&conf.LogLevel, "log_level", conf.LogLevel, "Log level (DEBUG, INFO, WARN, ERROR)") |
| 53 | flag.BoolVar(&conf.PrintVersion, "version", conf.PrintVersion, "Print the version and exit") |
| 54 | flag.BoolVar(&conf.PrintBanner, "banner", conf.PrintBanner, "Print the banner at startup") |
| 55 | flag.StringVar(&conf.ProbeAddress, "probe_address", conf.ProbeAddress, "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
| 56 | flag.BoolVar(&conf.TraceEnabled, "trace_enabled", conf.TraceEnabled, "Whether to send logs to tracing agent") |
| 57 | flag.StringVar(&conf.TraceAgentAddress, "trace_agent_address", conf.TraceAgentAddress, "The address of tracing agent to which span info should be sent") |
| 58 | flag.BoolVar(&conf.LogCorrelationEnabled, "log_correlation_enabled", conf.LogCorrelationEnabled, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation") |
Elia Battiston | be9edc1 | 2022-03-09 11:35:58 +0100 | [diff] [blame] | 59 | flag.StringVar(&conf.VolthaNbiEndpoint, "voltha_nbi_endpoint", conf.VolthaNbiEndpoint, "Endpoint of the VOLTHA northbound interface") |
| 60 | flag.BoolVar(&conf.TlsEnabled, "tls_enabled", conf.TlsEnabled, "Whether to use TLS when connecting to VOLTHA's northbound grpc server") |
| 61 | flag.BoolVar(&conf.TlsVerify, "tls_verify", conf.TlsVerify, "Whether to verify the server's certificate when connecting to VOLTHA's northbound grpc server. To be used with 'tls_enabled'.") |
| 62 | flag.StringVar(&conf.OnosRestEndpoint, "onos_rest_endpoint", conf.OnosRestEndpoint, "Endpoint of ONOS REST APIs") |
| 63 | flag.StringVar(&conf.OnosUser, "onos_user", conf.OnosUser, "Username for ONOS REST APIs") |
| 64 | flag.StringVar(&conf.OnosPassword, "onos_pass", conf.OnosPassword, "Password for ONOS REST APIs") |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 65 | flag.StringVar(&conf.SchemaMountFilePath, "schema_mount_path", conf.SchemaMountFilePath, "Path to the XML file that defines schema-mounts for libyang") |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame] | 66 | flag.StringVar(&conf.KafkaClusterAddress, "kafka_cluster_address", conf.KafkaClusterAddress, "Kafka cluster messaging address") |
Elia Battiston | aa7a048 | 2022-08-17 12:24:02 +0000 | [diff] [blame^] | 67 | flag.StringVar(&conf.KvStoreType, "kv_store_type", conf.KvStoreType, "KV store type (etcd, redis)") |
| 68 | flag.StringVar(&conf.KvStoreAddress, "kv_store_address", conf.KvStoreAddress, "KV store address") |
| 69 | flag.DurationVar(&conf.KvStoreTimeout, "kv_store_request_timeout", conf.KvStoreTimeout, "The default timeout when making a KV store request") |
| 70 | flag.StringVar(&conf.KvStorePrefix, "kv_store_prefix", conf.KvStorePrefix, "Prefix used in KV store paths") |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 71 | |
| 72 | flag.Parse() |
| 73 | |
| 74 | return conf |
| 75 | } |
| 76 | |
| 77 | // getDefaultConfig returns a BBF Adapter configuration with default values |
| 78 | func getDefaultConfig() *BBFAdapterConfig { |
| 79 | return &BBFAdapterConfig{ |
| 80 | LogLevel: "ERROR", |
| 81 | PrintVersion: false, |
| 82 | PrintBanner: false, |
| 83 | ProbeAddress: ":8080", |
| 84 | TraceEnabled: false, |
| 85 | TraceAgentAddress: "127.0.0.1:6831", |
| 86 | LogCorrelationEnabled: true, |
Elia Battiston | be9edc1 | 2022-03-09 11:35:58 +0100 | [diff] [blame] | 87 | VolthaNbiEndpoint: "voltha-voltha-api.voltha.svc:55555", |
| 88 | TlsEnabled: false, |
| 89 | TlsVerify: false, |
| 90 | OnosRestEndpoint: "voltha-infra-onos-classic-hs.infra.svc:8181", |
| 91 | OnosUser: "onos", |
| 92 | OnosPassword: "rocks", |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 93 | SchemaMountFilePath: "/schema-mount.xml", |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame] | 94 | KafkaClusterAddress: "127.0.0.1:9092", |
Elia Battiston | aa7a048 | 2022-08-17 12:24:02 +0000 | [diff] [blame^] | 95 | KvStoreType: "etcd", |
| 96 | KvStoreAddress: "etcd:2379", |
| 97 | KvStoreTimeout: time.Second * 5, |
| 98 | KvStorePrefix: "service/voltha_voltha", |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 99 | } |
| 100 | } |