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" |
| 22 | ) |
| 23 | |
| 24 | type BBFAdapterConfig struct { |
| 25 | PrintVersion bool |
| 26 | PrintBanner bool |
| 27 | LogLevel string |
| 28 | ProbeAddress string |
| 29 | TraceEnabled bool |
| 30 | TraceAgentAddress string |
| 31 | LogCorrelationEnabled bool |
Elia Battiston | be9edc1 | 2022-03-09 11:35:58 +0100 | [diff] [blame] | 32 | VolthaNbiEndpoint string |
| 33 | TlsEnabled bool |
| 34 | TlsVerify bool |
| 35 | OnosRestEndpoint string |
| 36 | OnosUser string |
| 37 | OnosPassword string |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 38 | SchemaMountFilePath string |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // LoadConfig loads the BBF adapter configuration through |
| 42 | // default values and CLI arguments |
| 43 | func LoadConfig(ctx context.Context) *BBFAdapterConfig { |
| 44 | conf := getDefaultConfig() |
| 45 | |
| 46 | flag.StringVar(&conf.LogLevel, "log_level", conf.LogLevel, "Log level (DEBUG, INFO, WARN, ERROR)") |
| 47 | flag.BoolVar(&conf.PrintVersion, "version", conf.PrintVersion, "Print the version and exit") |
| 48 | flag.BoolVar(&conf.PrintBanner, "banner", conf.PrintBanner, "Print the banner at startup") |
| 49 | flag.StringVar(&conf.ProbeAddress, "probe_address", conf.ProbeAddress, "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
| 50 | flag.BoolVar(&conf.TraceEnabled, "trace_enabled", conf.TraceEnabled, "Whether to send logs to tracing agent") |
| 51 | flag.StringVar(&conf.TraceAgentAddress, "trace_agent_address", conf.TraceAgentAddress, "The address of tracing agent to which span info should be sent") |
| 52 | 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] | 53 | flag.StringVar(&conf.VolthaNbiEndpoint, "voltha_nbi_endpoint", conf.VolthaNbiEndpoint, "Endpoint of the VOLTHA northbound interface") |
| 54 | flag.BoolVar(&conf.TlsEnabled, "tls_enabled", conf.TlsEnabled, "Whether to use TLS when connecting to VOLTHA's northbound grpc server") |
| 55 | 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'.") |
| 56 | flag.StringVar(&conf.OnosRestEndpoint, "onos_rest_endpoint", conf.OnosRestEndpoint, "Endpoint of ONOS REST APIs") |
| 57 | flag.StringVar(&conf.OnosUser, "onos_user", conf.OnosUser, "Username for ONOS REST APIs") |
| 58 | 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] | 59 | flag.StringVar(&conf.SchemaMountFilePath, "schema_mount_path", conf.SchemaMountFilePath, "Path to the XML file that defines schema-mounts for libyang") |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 60 | |
| 61 | flag.Parse() |
| 62 | |
| 63 | return conf |
| 64 | } |
| 65 | |
| 66 | // getDefaultConfig returns a BBF Adapter configuration with default values |
| 67 | func getDefaultConfig() *BBFAdapterConfig { |
| 68 | return &BBFAdapterConfig{ |
| 69 | LogLevel: "ERROR", |
| 70 | PrintVersion: false, |
| 71 | PrintBanner: false, |
| 72 | ProbeAddress: ":8080", |
| 73 | TraceEnabled: false, |
| 74 | TraceAgentAddress: "127.0.0.1:6831", |
| 75 | LogCorrelationEnabled: true, |
Elia Battiston | be9edc1 | 2022-03-09 11:35:58 +0100 | [diff] [blame] | 76 | VolthaNbiEndpoint: "voltha-voltha-api.voltha.svc:55555", |
| 77 | TlsEnabled: false, |
| 78 | TlsVerify: false, |
| 79 | OnosRestEndpoint: "voltha-infra-onos-classic-hs.infra.svc:8181", |
| 80 | OnosUser: "onos", |
| 81 | OnosPassword: "rocks", |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 82 | SchemaMountFilePath: "/schema-mount.xml", |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 83 | } |
| 84 | } |