MSP-1068 move out invoker

This commit is contained in:
novikovmu committed 2022-10-06 17:14:09 +03:00
1 parent a720cef797
commit fcade81bf5
4 files changed
-142

No files matched your search

-56
View File
@@ -1,56 +0,0 @@
package invoker
import (
"encoding/json"
"time"
"github.com/integration-system/isp-lib/v2/config/schema"
log "github.com/integration-system/isp-log"
"github.com/integration-system/isp-lib/v2/backend"
"google.golang.org/grpc"
)
type (
ModuleInfo struct {
Id string `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
CreatedAt time.Time `json:"createdAt"`
LastConnectedAt time.Time `json:"lastConnectedAt"`
LastDisconnectedAt time.Time `json:"lastDisconnectedAt"`
ConfigSchema *schema.Schema `json:"configSchema"`
Status interface{} `json:"status"`
RequiredModules interface{} `json:"requiredModules"`
}
ConfigRequest struct {
ModuleId string `json:"moduleId"`
}
)
var (
ConfigClient = backend.NewRxGrpcClient(
backend.WithDialOptions(grpc.WithInsecure()),
)
)
func GetConfigsById(request ConfigRequest) json.RawMessage {
var response json.RawMessage
if err := ConfigClient.Invoke("config/config/get_configs_by_module_id", 0, request, &response); err != nil {
log.Errorf(77, "can't get response from grpc request : %v", err)
return nil
}
return response
}
func GetModulesInfo() []ModuleInfo {
var response []ModuleInfo
if err := ConfigClient.Invoke("config/module/get_modules_info", 0, nil, &response); err != nil {
log.Errorf(77, "can't get response from grpc request : %v", err)
return nil
}
return response
}
-50
View File
@@ -1,50 +0,0 @@
package invoker
import (
"encoding/base64"
"fmt"
"github.com/integration-system/isp-lib/v2/http"
"msp-admin-service/conf"
"msp-admin-service/invoker/sudir"
)
var Sudir = sudirCli{
cli: http.NewJsonRestClient(),
}
type sudirCli struct {
cli http.RestClient
}
func (c sudirCli) GetToken(cfg conf.SudirAuth, authCode string) (*sudir.TokenResponse, error) {
method := fmt.Sprintf("%s/blitz/oauth/te?grant_type=authorization_code&code=%s&redirect_uri=%s",
cfg.Host, authCode, cfg.RedirectURI,
)
basicAuth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", cfg.ClientId, cfg.ClientSecret)))
headers := map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": fmt.Sprintf("Basic %s", basicAuth),
}
response := new(sudir.TokenResponse)
err := c.cli.Invoke(http.POST, method, headers, nil, response)
if err != nil {
return nil, err
}
return response, nil
}
func (c sudirCli) GetUser(host, accessToken string) (*sudir.UserResponse, error) {
method := fmt.Sprintf("%s/blitz/oauth/me", host)
headers := map[string]string{
"Authorization": fmt.Sprintf("Bearer %s", accessToken),
}
response := new(sudir.UserResponse)
err := c.cli.Invoke(http.GET, method, headers, nil, response)
if err != nil {
return nil, err
}
return response, nil
}
-14
View File
@@ -1,14 +0,0 @@
package sudir
import (
"fmt"
)
type SudirAuthError struct {
ErrorName string `json:"error"`
ErrorDescription string `json:"error_description"`
}
func (s *SudirAuthError) Error() string {
return fmt.Sprintf("error: %s; description: %s", s.ErrorName, s.ErrorDescription)
}
-22
View File
@@ -1,22 +0,0 @@
package sudir
type UserResponse struct {
*SudirAuthError
Email string `json:"email"`
Groups []string `json:"groups"`
Sub string `json:"sub"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
}
type TokenResponse struct {
*SudirAuthError
IdToken string `json:"id_token"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
}