Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
apex-master
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
crdc
apex
apex-master
Commits
6ff55def
Commit
6ff55def
authored
5 years ago
by
Jon Liu
Browse files
Options
Downloads
Patches
Plain Diff
feat: setModuleProperties mutation
parent
89ce0c1b
No related branches found
No related tags found
1 merge request
!6
feat: get and set property
Pipeline
#57135550
failed
5 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/schema/schema.graphql
+1
-1
1 addition, 1 deletion
api/schema/schema.graphql
pkg/resolver/module_mutation.go
+40
-0
40 additions, 0 deletions
pkg/resolver/module_mutation.go
pkg/service/broker_service.go
+36
-2
36 additions, 2 deletions
pkg/service/broker_service.go
with
77 additions
and
3 deletions
api/schema/schema.graphql
+
1
−
1
View file @
6ff55def
...
...
@@ -83,7 +83,7 @@ type Mutation {
# Set a module's property
setModuleProperty
(
serviceName
:
String
!,
moduleName
:
String
!,
property
:
PropertyInput
!):
Property
# Set a module's properties
#
setModuleProperties(moduleName: String!, properties: [PropertyInput]): [Property]
setModuleProperties
(
serviceName
:
String
!,
moduleName
:
String
!,
properties
:
[
PropertyInput
]):
[
Property
]
}
input
ConfigurationInput
{
...
...
This diff is collapsed.
Click to expand it.
pkg/resolver/module_mutation.go
+
40
−
0
View file @
6ff55def
...
...
@@ -3,6 +3,7 @@ package resolver
import
(
"errors"
"fmt"
"strings"
//"encoding/json"
//"log"
...
...
@@ -79,3 +80,42 @@ func (r *Resolver) SetModuleProperty(ctx context.Context, args struct {
return
&
propertyResolver
{
property
},
nil
}
func
(
r
*
Resolver
)
SetModuleProperties
(
ctx
context
.
Context
,
args
struct
{
ServiceName
string
ModuleName
string
Properties
*
[]
*
propertyInput
})
(
*
[]
*
propertyResolver
,
error
)
{
if
isAuthorized
:=
ctx
.
Value
(
"is_authorized"
)
.
(
bool
);
!
isAuthorized
{
return
nil
,
errors
.
New
(
gcontext
.
CredentialsError
)
}
// Convert the properties key and value into comma delimited strings
var
bufKey
strings
.
Builder
var
bufValue
strings
.
Builder
reqProperties
:=
*
(
args
.
Properties
)
for
i
:=
range
reqProperties
{
bufKey
.
WriteString
((
*
reqProperties
[
i
])
.
Key
)
bufKey
.
WriteByte
(
','
)
bufValue
.
WriteString
((
*
reqProperties
[
i
])
.
Value
)
bufValue
.
WriteByte
(
','
)
}
// Take the output and remove the last comma delimiter
reqKeys
:=
strings
.
TrimSuffix
(
bufKey
.
String
(),
","
)
reqValues
:=
strings
.
TrimSuffix
(
bufValue
.
String
(),
","
)
// Use the broker service
properties
,
err
:=
ctx
.
Value
(
"brokerService"
)
.
(
*
service
.
BrokerService
)
.
SetModuleProperties
(
args
.
ServiceName
,
args
.
ModuleName
,
reqKeys
,
reqValues
)
if
err
!=
nil
{
fmt
.
Errorf
(
"SetModuleProperties error: "
,
err
)
return
nil
,
err
}
// Create property resolvers for each property
var
_properties
[]
*
propertyResolver
for
_
,
property
:=
range
properties
{
_properties
=
append
(
_properties
,
&
propertyResolver
{
property
})
}
return
&
_properties
,
nil
}
This diff is collapsed.
Click to expand it.
pkg/service/broker_service.go
+
36
−
2
View file @
6ff55def
...
...
@@ -361,15 +361,16 @@ func (b *BrokerService) GetModuleProperty(serviceName string, moduleID string, p
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
// Create the property request
request
:=
&
pb
.
PropertyRequest
{
Id
:
moduleID
,
Key
:
propertyName
,
}
// Send the request to the specified service
response
,
err
:=
b
.
clients
[
serviceName
]
.
GetModuleProperty
(
ctx
,
request
)
if
err
!=
nil
{
return
nil
,
err
}
// Convert the protobuf property into a model property
_property
:=
&
model
.
Property
{
Key
:
response
.
GetProperty
()
.
GetKey
(),
...
...
@@ -416,16 +417,17 @@ func (b *BrokerService) SetModuleProperty(serviceName string, moduleID string, p
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
// Create the property request
request
:=
&
pb
.
PropertyRequest
{
Id
:
moduleID
,
Key
:
property
.
GetKey
(),
Value
:
property
.
GetValue
(),
}
// Send the request to the specified service
response
,
err
:=
b
.
clients
[
serviceName
]
.
SetModuleProperty
(
ctx
,
request
)
if
err
!=
nil
{
return
nil
,
err
}
// Convert the protobuf property into a model property
_property
:=
&
model
.
Property
{
Key
:
response
.
GetProperty
()
.
GetKey
(),
...
...
@@ -434,3 +436,35 @@ func (b *BrokerService) SetModuleProperty(serviceName string, moduleID string, p
return
_property
,
nil
}
// rpc SetModuleProperties(PropertiesRequest) returns (PropertiesResponse);
func
(
b
*
BrokerService
)
SetModuleProperties
(
serviceName
string
,
moduleID
string
,
propertyKeys
string
,
propertyValues
string
)
([]
*
model
.
Property
,
error
)
{
b
.
log
.
Debugf
(
"Sending gRPC request for SetModuleProperties to %s/%s for %s/%s"
,
serviceName
,
moduleID
,
propertyKeys
,
propertyValues
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
// Create the properties request
request
:=
&
pb
.
PropertiesRequest
{
Id
:
moduleID
,
Keys
:
propertyKeys
,
Values
:
propertyValues
,
}
// Send the request to the specified service
response
,
err
:=
b
.
clients
[
serviceName
]
.
SetModuleProperties
(
ctx
,
request
)
if
err
!=
nil
{
return
nil
,
err
}
// Convert the protobuf properties into an array of model property
var
convertedProperties
[]
*
model
.
Property
responseProperties
:=
response
.
GetProperties
()
for
_
,
property
:=
range
responseProperties
{
log
.
Print
(
*
property
)
tempProperty
:=
&
model
.
Property
{
Key
:
property
.
GetKey
(),
Value
:
property
.
GetValue
(),
}
convertedProperties
=
append
(
convertedProperties
,
tempProperty
)
}
return
convertedProperties
,
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