Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
key-storage-agent
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
key-storage-agent
Commits
534f7f63
Commit
534f7f63
authored
4 years ago
by
Olgun Cengiz
Browse files
Options
Downloads
Patches
Plain Diff
fixed comments
parent
d927ad77
No related branches found
No related tags found
1 merge request
!64
config changes
Pipeline
#34123
passed with stages
in 5 minutes and 42 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/configs.go
+47
-62
47 additions, 62 deletions
config/configs.go
main.go
+2
-8
2 additions, 8 deletions
main.go
with
49 additions
and
70 deletions
config/configs.go
+
47
−
62
View file @
534f7f63
...
...
@@ -6,10 +6,10 @@ import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"code.vereign.com/code/viam-apis/clientutils"
"code.vereign.com/code/viam-apis/config"
"code.vereign.com/code/viam-apis/errors"
"code.vereign.com/code/viam-apis/log"
...
...
@@ -25,47 +25,60 @@ var SystemAuth = &authentication.Authentication{
Session
:
"undefined"
,
}
const
tagValidation
=
"validation"
type
Configuration
struct
{
ListenAddress
string
`
validation:"optional
" yaml:"listenAddress"`
GrpcListenAddress
string
`
validation:"optional
" yaml:"grpcListenAddress"`
ListenAddress
string
`
required:"false
" yaml:"listenAddress"`
GrpcListenAddress
string
`
required:"false
" yaml:"grpcListenAddress"`
SystemAuthentication
struct
{
UUID
string
`
validation:"optional
" yaml:"viamUUID"`
Session
string
`
validation:"optional
" yaml:"viamSession"`
}
`
validation:"optional
" yaml:"systemAuthentication"`
DataStorageAgentURL
string
`
validation:"optional
" yaml:"dataStorageAgentURL"`
EntitiesManagementAgentURL
string
`
validation:"optional
" yaml:"entitiesManagementAgentURL"`
MaxMessageSize
int
`
validation:"optional
" yaml:"maxMessageSize"`
UUID
string
`
required:"false
" yaml:"viamUUID"`
Session
string
`
required:"false
" yaml:"viamSession"`
}
`
required:"false
" yaml:"systemAuthentication"`
DataStorageAgentURL
string
`
required:"false
" yaml:"dataStorageAgentURL"`
EntitiesManagementAgentURL
string
`
required:"false
" yaml:"entitiesManagementAgentURL"`
MaxMessageSize
int
`
required:"false
" yaml:"maxMessageSize"`
Certification
struct
{
Path
string
`
validation:"
required" yaml:"path"`
CertificateFile
string
`
validation:"
required" yaml:"certificateFile"`
CertificatePEM
[]
byte
`
validation:"calculated" yaml:"certificatePEM
"`
PrivateKeyFile
string
`
validation:"
required" yaml:"privateKeyFile"`
PrivateKeyPEM
[]
byte
`
validation:"calculated" yaml:"privateKeyPEM
"`
CaCertificateFile
string
`
validation:"
required" yaml:"caCertificateFile"`
CaCertificatePEM
[]
byte
`
validation:"calculated" yaml:"caCertificatePEM
"`
EncryptionCertificateFile
string
`
validation:"
required" yaml:"encryptionCertificateFile"`
EncryptionCertificatePEM
[]
byte
`
validation:"calculated" yaml:"encryptionCertificatePEM
"`
EncryptionCertificate
[]
*
x509
.
Certificate
`
validation:"calculated" yaml:"encryptionCertificat
e"`
EncryptionPrivateKeyFile
string
`
validation:"
required" yaml:"encryptionPrivateKeyFile"`
EncryptionPrivateKeyPEM
[]
byte
`
validation:"calculated" yaml:"encryptionPrivateKeyPEM
"`
EncryptionPrivateKey
crypto
.
Signer
`
validation:"calculated" yaml:"encryptionPrivateKey
"`
VereignCertificateFile
string
`
validation:"
required" yaml:"vereignCertificateFile"`
VereignCertificatePEM
[]
byte
`
validation:"calculated" yaml:"vereignCertificatePEM
"`
}
`
validation:"
required" yaml:"certification"`
PrometeusListenAddress
string
`
validation:"optional
" yaml:"prometeusListenAddress"`
MetricEnvironmentPrefix
string
`
validation:"optional
" yaml:"metricEnvironmentPrefix"`
ReplaceKey
bool
`
validation:"optional
" yaml:"replaceKey"`
GlobalLogLevel
string
`
validation:"optional
" yaml:"globalLogLevel"`
Path
string
`required
:"true
" yaml:"path"`
CertificateFile
string
`required
:"true
" yaml:"certificateFile"`
CertificatePEM
[]
byte
`
required:"true
"`
PrivateKeyFile
string
`required
:"true
" yaml:"privateKeyFile"`
PrivateKeyPEM
[]
byte
`
required:"true
"`
CaCertificateFile
string
`required
:"true
" yaml:"caCertificateFile"`
CaCertificatePEM
[]
byte
`
required:"true
"`
EncryptionCertificateFile
string
`required
:"true
" yaml:"encryptionCertificateFile"`
EncryptionCertificatePEM
[]
byte
`
required:"true
"`
EncryptionCertificate
[]
*
x509
.
Certificate
`
required:"tru
e"`
EncryptionPrivateKeyFile
string
`required
:"true
" yaml:"encryptionPrivateKeyFile"`
EncryptionPrivateKeyPEM
[]
byte
`
required:"true
"`
EncryptionPrivateKey
crypto
.
Signer
`
required:"true
"`
VereignCertificateFile
string
`required
:"true
" yaml:"vereignCertificateFile"`
VereignCertificatePEM
[]
byte
`
required:"true
"`
}
`required
:"true
" yaml:"certification"`
PrometeusListenAddress
string
`
required:"false
" yaml:"prometeusListenAddress"`
MetricEnvironmentPrefix
string
`
required:"false
" yaml:"metricEnvironmentPrefix"`
ReplaceKey
bool
`
required:"false
" yaml:"replaceKey"`
GlobalLogLevel
string
`
required:"false
" yaml:"globalLogLevel"`
}
var
Config
Configuration
// LoadConfigValues loads config values from config file
func
LoadConfigValues
(
configFile
,
etcdURL
string
)
error
{
setConfigValues
(
configFile
,
etcdURL
)
calculateConfigValues
()
err
:=
config
.
CheckConfigValues
(
Config
)
if
err
!=
nil
{
log
.
Fatalf
(
"Exiting due to wrong configuration: %s"
,
err
)
return
err
}
return
nil
}
// SetConfigValues Sets Values For Config Variable
func
S
etConfigValues
(
configFile
,
etcdURL
string
)
{
func
s
etConfigValues
(
configFile
,
etcdURL
string
)
{
// Set default values for configuration variable
// NOTE: Only for '
validation:"optional
"' fields
// NOTE: Only for '
required:"false
"' fields
Config
.
ListenAddress
=
":7878"
Config
.
GrpcListenAddress
=
":7877"
Config
.
SystemAuthentication
.
UUID
=
"viam-system"
...
...
@@ -122,36 +135,8 @@ func SetConfigValues(configFile, etcdURL string) {
}
}
// CheckConfigValues checks if there is any missing required fields in configuration
func
CheckConfigValues
(
configs
interface
{})
error
{
structIterator
:=
reflect
.
ValueOf
(
configs
)
for
i
:=
0
;
i
<
structIterator
.
NumField
();
i
++
{
field
:=
structIterator
.
Type
()
.
Field
(
i
)
.
Name
val
:=
structIterator
.
Field
(
i
)
.
Interface
()
tR
:=
structIterator
.
Type
()
.
Field
(
i
)
.
Tag
.
Get
(
tagValidation
)
log
.
Printf
(
"%v: %v"
,
field
,
val
)
if
tR
==
"required"
{
if
structIterator
.
Field
(
i
)
.
Kind
()
==
reflect
.
Struct
{
if
err
:=
CheckConfigValues
(
structIterator
.
Field
(
i
)
.
Interface
());
err
!=
nil
{
return
err
}
}
if
reflect
.
DeepEqual
(
val
,
reflect
.
Zero
(
structIterator
.
Field
(
i
)
.
Type
())
.
Interface
())
{
// Check if the field is zero-valued, meaning it won't be updated
return
errors
.
NewFormat
(
"Empty value for required field: %v"
,
field
)
}
}
else
if
tR
!=
"optional"
&&
tR
!=
"calculated"
{
return
errors
.
NewFormat
(
"Wrong validation type for field: %v (Must be 'optional', 'required' or 'calculated')"
,
field
)
}
}
return
nil
}
// CalculateConfigValues calculates config values using provided configuraion
func
C
alculateConfigValues
()
{
func
c
alculateConfigValues
()
{
SystemAuth
.
Uuid
=
Config
.
SystemAuthentication
.
UUID
SystemAuth
.
Session
=
Config
.
SystemAuthentication
.
Session
...
...
This diff is collapsed.
Click to expand it.
main.go
+
2
−
8
View file @
534f7f63
...
...
@@ -39,18 +39,12 @@ func main() {
return
}
log
.
Printf
(
"Setting configuration values..."
)
config
.
SetConfigValues
(
*
configFile
,
*
etcdURL
)
log
.
Printf
(
"Checking configuration values..."
)
err
:=
config
.
CheckConfigValues
(
config
.
Config
)
log
.
Printf
(
"Loading configuration values..."
)
err
:=
config
.
LoadConfigValues
(
*
configFile
,
*
etcdURL
)
if
err
!=
nil
{
log
.
Fatalf
(
"Exiting due to wrong configuration: %s"
,
err
)
}
log
.
Printf
(
"Calculating configuration values..."
)
config
.
CalculateConfigValues
()
grpcAddress
:=
config
.
Config
.
GrpcListenAddress
restAddress
:=
config
.
Config
.
ListenAddress
dataStorageAddress
:=
config
.
Config
.
DataStorageAgentURL
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment