✨ Third client query toolkit
This commit is contained in:
38
pkg/authkit/third_client.go
Normal file
38
pkg/authkit/third_client.go
Normal file
@ -0,0 +1,38 @@
|
||||
package authkit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/proto"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func GetThirdClient(nx *nex.Conn, id uint, secret *string) (*models.ThirdClient, error) {
|
||||
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get auth service client: %v", err)
|
||||
}
|
||||
resp, err := proto.NewThirdClientServiceClient(conn).
|
||||
GetThirdClient(context.Background(), &proto.GetThirdClientRequest{
|
||||
ClientId: uint64(id),
|
||||
Secret: secret,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &models.ThirdClient{
|
||||
Alias: resp.GetInfo().GetAlias(),
|
||||
Name: resp.GetInfo().GetName(),
|
||||
Description: resp.GetInfo().GetDescription(),
|
||||
IsDraft: resp.GetInfo().GetIsDraft(),
|
||||
AccountID: lo.TernaryF(resp.GetInfo().AccountId != nil, func() *uint {
|
||||
return lo.ToPtr(uint(resp.GetInfo().GetAccountId()))
|
||||
}, func() *uint {
|
||||
return nil
|
||||
}),
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user