Code Review
/
nonrtric
/
plt
/
sme.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add get all published services
[nonrtric/plt/sme.git]
/
capifcore
/
internal
/
invokermanagement
/
invokermanagement.go
diff --git
a/capifcore/internal/invokermanagement/invokermanagement.go
b/capifcore/internal/invokermanagement/invokermanagement.go
index
1d8582d
..
69d7149
100644
(file)
--- a/
capifcore/internal/invokermanagement/invokermanagement.go
+++ b/
capifcore/internal/invokermanagement/invokermanagement.go
@@
-39,21
+39,29
@@
import (
//go:generate mockery --name InvokerRegister
type InvokerRegister interface {
//go:generate mockery --name InvokerRegister
type InvokerRegister interface {
+ // Checks if the invoker is registered.
+ // Returns true of the provided invoker is registered, false otherwise.
IsInvokerRegistered(invokerId string) bool
IsInvokerRegistered(invokerId string) bool
+ // Verifies that the provided secret is the invoker's registered secret.
+ // Returns true if the provided secret is the registered invoker's secret, false otherwise.
VerifyInvokerSecret(invokerId, secret string) bool
VerifyInvokerSecret(invokerId, secret string) bool
+ // Gets the provided invoker's registered APIs.
+ // Returns a list of all the invoker's registered APIs.
+ GetInvokerApiList(invokerId string) *invokerapi.APIList
}
type InvokerManager struct {
onboardedInvokers map[string]invokerapi.APIInvokerEnrolmentDetails
}
type InvokerManager struct {
onboardedInvokers map[string]invokerapi.APIInvokerEnrolmentDetails
-
apiRegister publishservice.API
Register
+
publishRegister publishservice.Publish
Register
nextId int64
lock sync.Mutex
}
nextId int64
lock sync.Mutex
}
-func NewInvokerManager(apiRegister publishservice.APIRegister) *InvokerManager {
+// Creates a manager that implements both the InvokerRegister and the invokermanagementapi.ServerInterface interfaces.
+func NewInvokerManager(publishRegister publishservice.PublishRegister) *InvokerManager {
return &InvokerManager{
onboardedInvokers: make(map[string]invokerapi.APIInvokerEnrolmentDetails),
return &InvokerManager{
onboardedInvokers: make(map[string]invokerapi.APIInvokerEnrolmentDetails),
-
apiRegister: api
Register,
+
publishRegister: publish
Register,
nextId: 1000,
}
}
nextId: 1000,
}
}
@@
-77,6
+85,15
@@
func (im *InvokerManager) VerifyInvokerSecret(invokerId, secret string) bool {
return verified
}
return verified
}
+func (im *InvokerManager) GetInvokerApiList(invokerId string) *invokerapi.APIList {
+ invoker, ok := im.onboardedInvokers[invokerId]
+ if ok {
+ return invoker.ApiList
+ }
+ return nil
+}
+
+// Creates a new individual API Invoker profile.
func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error {
var newInvoker invokerapi.APIInvokerEnrolmentDetails
err := ctx.Bind(&newInvoker)
func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error {
var newInvoker invokerapi.APIInvokerEnrolmentDetails
err := ctx.Bind(&newInvoker)
@@
-101,6
+118,9
@@
func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error {
}
newInvoker.OnboardingInformation.OnboardingSecret = &onboardingSecret
}
newInvoker.OnboardingInformation.OnboardingSecret = &onboardingSecret
+ var apiList invokerapi.APIList = im.publishRegister.GetAllPublishedServices()
+ newInvoker.ApiList = &apiList
+
im.onboardedInvokers[*newInvoker.ApiInvokerId] = newInvoker
uri := ctx.Request().Host + ctx.Request().URL.String()
im.onboardedInvokers[*newInvoker.ApiInvokerId] = newInvoker
uri := ctx.Request().Host + ctx.Request().URL.String()
@@
-114,6
+134,7
@@
func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error {
return nil
}
return nil
}
+// Deletes an individual API Invoker.
func (im *InvokerManager) DeleteOnboardedInvokersOnboardingId(ctx echo.Context, onboardingId string) error {
im.lock.Lock()
defer im.lock.Unlock()
func (im *InvokerManager) DeleteOnboardedInvokersOnboardingId(ctx echo.Context, onboardingId string) error {
im.lock.Lock()
defer im.lock.Unlock()
@@
-123,6
+144,7
@@
func (im *InvokerManager) DeleteOnboardedInvokersOnboardingId(ctx echo.Context,
return ctx.NoContent(http.StatusNoContent)
}
return ctx.NoContent(http.StatusNoContent)
}
+// Updates an individual API invoker details.
func (im *InvokerManager) PutOnboardedInvokersOnboardingId(ctx echo.Context, onboardingId string) error {
var invoker invokerapi.APIInvokerEnrolmentDetails
err := ctx.Bind(&invoker)
func (im *InvokerManager) PutOnboardedInvokersOnboardingId(ctx echo.Context, onboardingId string) error {
var invoker invokerapi.APIInvokerEnrolmentDetails
err := ctx.Bind(&invoker)
@@
-170,18
+192,18
@@
func (im *InvokerManager) validateInvoker(invoker invokerapi.APIInvokerEnrolment
return true, sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required OnboardingInformation.ApiInvokerPublicKey")
}
return true, sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required OnboardingInformation.ApiInvokerPublicKey")
}
- if !im.areAPIs
Register
ed(invoker.ApiList) {
+ if !im.areAPIs
Publish
ed(invoker.ApiList) {
return true, sendCoreError(ctx, http.StatusBadRequest, "Some APIs needed by invoker are not registered")
}
return false, nil
}
return true, sendCoreError(ctx, http.StatusBadRequest, "Some APIs needed by invoker are not registered")
}
return false, nil
}
-func (im *InvokerManager) areAPIs
Register
ed(apis *invokerapi.APIList) bool {
+func (im *InvokerManager) areAPIs
Publish
ed(apis *invokerapi.APIList) bool {
if apis == nil {
return true
}
if apis == nil {
return true
}
- return im.
apiRegister.AreAPIsRegister
ed((*[]publishapi.ServiceAPIDescription)(apis))
+ return im.
publishRegister.AreAPIsPublish
ed((*[]publishapi.ServiceAPIDescription)(apis))
}
func (im *InvokerManager) getId(invokerInfo *string) *string {
}
func (im *InvokerManager) getId(invokerInfo *string) *string {