Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
corteza
corteza-server
Commits
bb7dc471
Commit
bb7dc471
authored
5 years ago
by
Denis Arh
Browse files
Options
Download
Email Patches
Plain Diff
Add script-runner configuration capabilities
parent
4bbc85e1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
23 deletions
+50
-23
compose/compose.go
compose/compose.go
+2
-1
compose/internal/service/record.go
compose/internal/service/record.go
+5
-1
compose/internal/service/script_runner.go
compose/internal/service/script_runner.go
+26
-12
compose/internal/service/service.go
compose/internal/service/service.go
+4
-4
pkg/cli/options/script_runner.go
pkg/cli/options/script_runner.go
+11
-5
pkg/cli/runner.go
pkg/cli/runner.go
+2
-0
No files found.
compose/compose.go
View file @
bb7dc471
...
...
@@ -36,7 +36,8 @@ func Configure() *cli.Config {
servicesInitialized
=
true
cli
.
HandleError
(
service
.
Init
(
ctx
,
c
.
Log
,
service
.
Config
{
Storage
:
*
c
.
StorageOpt
,
Storage
:
*
c
.
StorageOpt
,
ScriptRunner
:
*
c
.
ScriptRunner
,
}))
},
...
...
This diff is collapsed.
Click to expand it.
compose/internal/service/record.go
View file @
bb7dc471
...
...
@@ -22,7 +22,7 @@ type (
logger
*
zap
.
Logger
ac
recordAccessController
sr
*
s
criptRunner
sr
RecordS
criptRunner
recordRepo
repository
.
RecordRepository
moduleRepo
repository
.
ModuleRepository
...
...
@@ -41,6 +41,10 @@ type (
CanUpdateRecordValue
(
context
.
Context
,
*
types
.
ModuleField
)
bool
}
RecordScriptRunner
interface
{
Record
(
context
.
Context
,
Runnable
,
*
types
.
Namespace
,
*
types
.
Module
,
*
types
.
Record
)
(
*
types
.
Record
,
error
)
}
RecordService
interface
{
With
(
ctx
context
.
Context
)
RecordService
...
...
This diff is collapsed.
Click to expand it.
compose/internal/service/script_runner.go
View file @
bb7dc471
...
...
@@ -13,6 +13,7 @@ import (
"github.com/cortezaproject/corteza-server/compose/proto"
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/internal/auth"
"github.com/cortezaproject/corteza-server/pkg/cli/options"
)
// Script runner provides an interface to corteza-corredor (Spanish for runner) service
...
...
@@ -25,7 +26,7 @@ import (
type
(
scriptRunner
struct
{
addr
string
c
options
.
ScriptRunnerOpt
logger
*
zap
.
Logger
conn
*
grpc
.
ClientConn
client
proto
.
ScriptRunnerClient
...
...
@@ -38,27 +39,40 @@ type (
IsCritical
()
bool
GetRunnerID
()
uint64
}
ScriptRunnerService
interface
{
Close
()
error
Namespace
(
context
.
Context
,
Runnable
,
*
types
.
Namespace
)
(
*
types
.
Namespace
,
error
)
Module
(
context
.
Context
,
Runnable
,
*
types
.
Namespace
,
*
types
.
Module
)
(
*
types
.
Module
,
error
)
Record
(
context
.
Context
,
Runnable
,
*
types
.
Namespace
,
*
types
.
Module
,
*
types
.
Record
)
(
*
types
.
Record
,
error
)
}
)
func
ScriptRunner
(
addr
string
)
*
scriptRunner
{
return
&
scriptRunner
{
addr
:
addr
,
// @todo move to opt so all services can use it
func
ScriptRunner
(
c
options
.
ScriptRunnerOpt
)
(
*
scriptRunner
,
error
)
{
var
svc
=
&
scriptRunner
{
c
:
c
,
logger
:
DefaultLogger
.
Named
(
"script-runner"
),
jwtEncoder
:
auth
.
DefaultJwtHandler
,
}
}
func
(
svc
*
scriptRunner
)
Connect
()
(
err
error
)
{
if
svc
.
conn
!=
nil
{
return
nil
}
return
svc
,
svc
.
connect
()
}
func
(
svc
*
scriptRunner
)
connect
()
(
err
error
)
{
// @todo wire grpc logger with zap logger
grpclog
.
SetLoggerV2
(
grpclog
.
NewLoggerV2WithVerbosity
(
os
.
Stdout
,
os
.
Stdout
,
os
.
Stdout
,
0
))
svc
.
conn
,
err
=
grpc
.
Dial
(
svc
.
addr
,
var
dopts
=
[]
grpc
.
Dial
Option
{
// @todo insecure?
grpc
.
WithInsecure
(),
grpc
.
WithBackoffMaxDelay
(
time
.
Second
))
}
if
svc
.
c
.
MaxBackoffDelay
>
0
{
dopts
=
append
(
dopts
,
grpc
.
WithBackoffMaxDelay
(
svc
.
c
.
MaxBackoffDelay
))
}
svc
.
conn
,
err
=
grpc
.
Dial
(
svc
.
c
.
Addr
,
dopts
...
)
if
err
!=
nil
{
return
...
...
This diff is collapsed.
Click to expand it.
compose/internal/service/service.go
View file @
bb7dc471
...
...
@@ -19,7 +19,8 @@ type (
}
Config
struct
{
Storage
options
.
StorageOpt
Storage
options
.
StorageOpt
ScriptRunner
options
.
ScriptRunnerOpt
}
)
...
...
@@ -39,7 +40,7 @@ var (
DefaultAttachment
AttachmentService
DefaultNamespace
NamespaceService
DefaultScriptRunner
*
s
criptRunner
// @todo interfa
ce
DefaultScriptRunner
S
criptRunner
Servi
ce
)
func
Init
(
ctx
context
.
Context
,
log
*
zap
.
Logger
,
c
Config
)
(
err
error
)
{
...
...
@@ -58,8 +59,7 @@ func Init(ctx context.Context, log *zap.Logger, c Config) (err error) {
DefaultAccessControl
=
AccessControl
(
DefaultPermissions
)
DefaultScriptRunner
=
ScriptRunner
(
"localhost:50051"
)
err
=
DefaultScriptRunner
.
Connect
()
DefaultScriptRunner
,
err
=
ScriptRunner
(
c
.
ScriptRunner
)
if
err
!=
nil
{
return
}
...
...
This diff is collapsed.
Click to expand it.
pkg/cli/options/script_runner.go
View file @
bb7dc471
package
options
import
(
"time"
)
type
(
StorageOpt
struct
{
Path
string
`env:"STORAGE_PATH"`
ScriptRunnerOpt
struct
{
Addr
string
`env:"SCRIPT_RUNNER_ADDR"`
MaxBackoffDelay
time
.
Duration
`env:"SCRIPT_RUNNER_MAX_BACKOFF_DELAY"`
}
)
func
Storage
(
pfix
string
)
(
o
*
StorageOpt
)
{
o
=
&
StorageOpt
{
Path
:
"var/store"
,
func
ScriptRunner
(
pfix
string
)
(
o
*
ScriptRunnerOpt
)
{
o
=
&
ScriptRunnerOpt
{
Addr
:
"corredor:80"
,
MaxBackoffDelay
:
time
.
Minute
,
}
fill
(
o
,
pfix
)
...
...
This diff is collapsed.
Click to expand it.
pkg/cli/runner.go
View file @
bb7dc471
...
...
@@ -50,6 +50,7 @@ type (
ProvisionOpt
*
options
.
ProvisionOpt
SentryOpt
*
options
.
SentryOpt
StorageOpt
*
options
.
StorageOpt
ScriptRunner
*
options
.
ScriptRunnerOpt
// DB Connection name, defaults to ServiceName
DatabaseName
string
...
...
@@ -188,6 +189,7 @@ func (c *Config) Init() {
c
.
ProvisionOpt
=
options
.
Provision
(
c
.
ServiceName
)
c
.
SentryOpt
=
options
.
Sentry
(
c
.
EnvPrefix
)
c
.
StorageOpt
=
options
.
Storage
(
c
.
EnvPrefix
)
c
.
ScriptRunner
=
options
.
ScriptRunner
(
c
.
EnvPrefix
)
if
c
.
RootCommandDBSetup
==
nil
{
c
.
RootCommandDBSetup
=
Runners
{
func
(
ctx
context
.
Context
,
cmd
*
cobra
.
Command
,
c
*
Config
)
(
err
error
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment