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
Issue boards
Milestones
Wiki
Code
Merge requests
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
03e1ed50
Commit
03e1ed50
authored
5 years ago
by
Alisa Dinaburg
Browse files
Options
Downloads
Patches
Plain Diff
rest gateway fixes
parent
79557b64
No related branches found
No related tags found
2 merge requests
!53
Localbuild
,
!49
326 http gateway in front each golang microservice
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config.yaml.sample
+2
-0
2 additions, 0 deletions
config.yaml.sample
config/configs.go
+3
-0
3 additions, 0 deletions
config/configs.go
main.go
+2
-1
2 additions, 1 deletion
main.go
server/server.go
+25
-4
25 additions, 4 deletions
server/server.go
with
32 additions
and
5 deletions
config.yaml.sample
+
2
−
0
View file @
03e1ed50
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
dataStorageUrl: localhost:7777
dataStorageUrl: localhost:7777
grpcListenAddress: localhost:7877
grpcListenAddress: localhost:7877
restListenAddress: localhost:7878
restListenAddress: localhost:7878
# This one using by rest-gateway. Must contain the same domain name with issued certificate
grpcURL: key-storage-agent:7877
# VIAM Variables
# VIAM Variables
viamUUID: viam-system
viamUUID: viam-system
...
...
This diff is collapsed.
Click to expand it.
config/configs.go
+
3
−
0
View file @
03e1ed50
...
@@ -29,6 +29,7 @@ var MaxMessageSize int
...
@@ -29,6 +29,7 @@ var MaxMessageSize int
var
GrpcListenAddress
string
var
GrpcListenAddress
string
var
RestListenAddress
string
var
RestListenAddress
string
var
GrpcURL
string
var
DataStorageUrl
string
var
DataStorageUrl
string
var
EntitiesManagerUrl
string
var
EntitiesManagerUrl
string
var
CertDir
string
var
CertDir
string
...
@@ -41,6 +42,7 @@ func SetConfigValues(configFile, etcdURL string) {
...
@@ -41,6 +42,7 @@ func SetConfigValues(configFile, etcdURL string) {
viper
.
SetDefault
(
"restListenAddress"
,
"localhost:7878"
)
viper
.
SetDefault
(
"restListenAddress"
,
"localhost:7878"
)
viper
.
SetDefault
(
"dataStorageUrl"
,
"localhost:7777"
)
viper
.
SetDefault
(
"dataStorageUrl"
,
"localhost:7777"
)
viper
.
SetDefault
(
"entitiesManagerUrl"
,
"localhost:7779"
)
viper
.
SetDefault
(
"entitiesManagerUrl"
,
"localhost:7779"
)
viper
.
SetDefault
(
"grpcURL"
,
"key-storage-agent:7877"
)
viper
.
SetDefault
(
"viamUUID"
,
"viam-system"
)
viper
.
SetDefault
(
"viamUUID"
,
"viam-system"
)
viper
.
SetDefault
(
"viamSession"
,
"viam-session"
)
viper
.
SetDefault
(
"viamSession"
,
"viam-session"
)
...
@@ -122,6 +124,7 @@ func SetConfigValues(configFile, etcdURL string) {
...
@@ -122,6 +124,7 @@ func SetConfigValues(configFile, etcdURL string) {
}
}
GrpcListenAddress
=
viper
.
GetString
(
"grpcListenAddress"
)
GrpcListenAddress
=
viper
.
GetString
(
"grpcListenAddress"
)
GrpcURL
=
viper
.
GetString
(
"grpcURL"
)
RestListenAddress
=
viper
.
GetString
(
"restListenAddress"
)
RestListenAddress
=
viper
.
GetString
(
"restListenAddress"
)
DataStorageUrl
=
viper
.
GetString
(
"dataStorageUrl"
)
DataStorageUrl
=
viper
.
GetString
(
"dataStorageUrl"
)
...
...
This diff is collapsed.
Click to expand it.
main.go
+
2
−
1
View file @
03e1ed50
...
@@ -42,6 +42,7 @@ func main() {
...
@@ -42,6 +42,7 @@ func main() {
grpcAddress
:=
config
.
GrpcListenAddress
grpcAddress
:=
config
.
GrpcListenAddress
restAddress
:=
config
.
RestListenAddress
restAddress
:=
config
.
RestListenAddress
grpcURL
:=
config
.
GrpcURL
dataStorageAddress
:=
config
.
DataStorageUrl
dataStorageAddress
:=
config
.
DataStorageUrl
certPem
:=
config
.
CertificatePEM
certPem
:=
config
.
CertificatePEM
keyPem
:=
config
.
PrivateKeyPEM
keyPem
:=
config
.
PrivateKeyPEM
...
@@ -62,7 +63,7 @@ func main() {
...
@@ -62,7 +63,7 @@ func main() {
// fire the REST server in a goroutine
// fire the REST server in a goroutine
go
func
()
{
go
func
()
{
err
:=
server
.
StartRESTServer
(
restAddress
,
grpc
Address
,
cert
Pem
)
err
:=
server
.
StartRESTServer
(
restAddress
,
grpc
URL
,
certPem
,
key
Pem
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"failed to start gRPC server: %s"
,
err
)
log
.
Fatalf
(
"failed to start gRPC server: %s"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
25
−
4
View file @
03e1ed50
...
@@ -54,6 +54,9 @@ func credMatcher(headerName string) (mdName string, ok bool) {
...
@@ -54,6 +54,9 @@ func credMatcher(headerName string) (mdName string, ok bool) {
if
headerName
==
"Session"
{
if
headerName
==
"Session"
{
return
headerName
,
true
return
headerName
,
true
}
}
if
headerName
==
"Uuid"
{
return
headerName
,
true
}
return
""
,
false
return
""
,
false
}
}
...
@@ -177,7 +180,8 @@ func StartGRPCServer(address string, certPEM, privateKeyPEM, caCertPEM, vereignC
...
@@ -177,7 +180,8 @@ func StartGRPCServer(address string, certPEM, privateKeyPEM, caCertPEM, vereignC
return
nil
return
nil
}
}
func
StartRESTServer
(
address
,
grpcAddress
string
,
certPEM
[]
byte
)
error
{
func
StartRESTServer
(
address
,
grpcURL
string
,
certPEM
,
keyPEM
[]
byte
)
error
{
log
.
Println
(
"grpcAddress: "
,
grpcURL
)
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
defer
cancel
()
...
@@ -200,14 +204,31 @@ func StartRESTServer(address, grpcAddress string, certPEM []byte) error {
...
@@ -200,14 +204,31 @@ func StartRESTServer(address, grpcAddress string, certPEM []byte) error {
opts
:=
[]
grpc
.
DialOption
{
grpc
.
WithTransportCredentials
(
creds
)}
opts
:=
[]
grpc
.
DialOption
{
grpc
.
WithTransportCredentials
(
creds
)}
// Register RedisStorageServer
// Register RedisStorageServer
err
=
api
.
RegisterKeyStorageHandlerFromEndpoint
(
ctx
,
mux
,
grpc
Address
,
opts
)
err
=
api
.
RegisterKeyStorageHandlerFromEndpoint
(
ctx
,
mux
,
grpc
URL
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Error: %v"
,
err
)
log
.
Printf
(
"Error: %v"
,
err
)
return
fmt
.
Errorf
(
"could not register service RedisStorageServer: %s"
,
err
)
return
fmt
.
Errorf
(
"could not register service RedisStorageServer: %s"
,
err
)
}
}
log
.
Printf
(
"starting HTTP/1.1 REST server on %s"
,
address
)
// server certificate
http
.
ListenAndServe
(
address
,
mux
)
certificate
,
err
:=
tls
.
X509KeyPair
(
certPEM
,
keyPEM
)
if
err
!=
nil
{
log
.
Printf
(
"Error: %v"
,
err
)
return
fmt
.
Errorf
(
"could not load server key pair: %s"
,
err
)
}
serverTLSConfig
:=
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
certificate
},
}
tlsServer
:=
&
http
.
Server
{
Addr
:
address
,
Handler
:
mux
,
TLSConfig
:
serverTLSConfig
,
}
log
.
Printf
(
"starting HTTP/1.1 REST server on %s"
,
address
)
tlsServer
.
ListenAndServeTLS
(
""
,
""
)
return
nil
return
nil
}
}
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