Third client query toolkit

This commit is contained in:
2025-02-02 21:13:55 +08:00
parent 7dbb552dd2
commit 17a99cce61
10 changed files with 322 additions and 444 deletions

View 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
}