Commit 3567a1ca authored by Ajit Jagtap's avatar Ajit Jagtap
Browse files

Merge branch 'ab_Add_ServiceCaller' into 'devbranch'

Add: Service caller

See merge request !72
parents 4e4e7947 23e4a451
Branches
Tags
1 merge request!72Add: Service caller
Showing with 34 additions and 0 deletions
......@@ -4,6 +4,7 @@ import (
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/servicebuildermdl"
version "github.com/hashicorp/go-version"
......@@ -119,3 +120,36 @@ func SetAppVersion(appVersion, minSupportedVersion string) error {
isAppVersionEnabled = true
return nil
}
// CallService - calls service with provided configuration, returns result and error from executed service
func CallService(name string, rs *gjson.Result, isRestricted bool, isRoleBased bool, p servicebuildermdl.Principal) (interface{}, error) {
var found bool
var service interface{}
if isRestricted {
if isRoleBased {
service, found = roleBasedServices.Get(name)
} else {
service, found = restrictedServices.Get(name)
}
} else {
service, found = openServices.Get(name)
}
if !found {
loggermdl.LogError("Service Not Found: " + name)
return nil, errormdl.Wrap("Service Not Found: " + name)
}
tmpSvcCache, ok := service.(ServiceCache)
if !ok {
loggermdl.LogError("Unable to cast service object for ", name)
return nil, errormdl.Wrap("Service execution failed for " + name)
}
serviceCache := tmpSvcCache
res, _, err := serviceCache.Service(rs, p)
if err != nil {
loggermdl.LogError("Service execution failed for ", name)
return nil, errormdl.Wrap("Service execution failed for " + name)
}
return res, nil
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment