Compare commits

..

No commits in common. "40a040352174a6adc4a0cb04e87ae6e092d1e328" and "d1f1183beb36dc418d524abf4344a3308188b69b" have entirely different histories.

6 changed files with 22 additions and 55 deletions

22
.idea/workspace.xml generated
View File

@ -4,13 +4,13 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix grpc namespace conflict">
<change afterPath="$PROJECT_DIR$/pkg/authkit/auth.go" afterDir="false" />
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Realm operations now available in authkit">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/authkit/audit.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/audit.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/authkit/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/notify.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/authkit/realm.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/realm.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/authkit/relative.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/relative.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/notify.pb.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/proto/notify.pb.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/notify.proto" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/proto/notify.proto" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/notify_grpc.pb.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/proto/notify_grpc.pb.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -33,10 +33,10 @@
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="KubernetesApiPersistence">{}</component>
<component name="KubernetesApiProvider">{
&quot;isMigrated&quot;: true
}</component>
<component name="KubernetesApiPersistence"><![CDATA[{}]]></component>
<component name="KubernetesApiProvider"><![CDATA[{
"isMigrated": true
}]]></component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="ProjectErrors" />
</component>
@ -162,6 +162,7 @@
</component>
<component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value=":bug: Bug fixes on settings auth preferences" />
<MESSAGE value=":sparkles: Implement event recorder grpc" />
<MESSAGE value=":sparkles: More event logs point" />
<MESSAGE value=":sparkles: New login alert" />
@ -186,8 +187,7 @@
<MESSAGE value=":technologist: Improve DX by extending authkit" />
<MESSAGE value=":sparkles: Add list relative method into authkit" />
<MESSAGE value=":sparkles: Realm operations now available in authkit" />
<MESSAGE value=":bug: Fix grpc namespace conflict" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix grpc namespace conflict" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Realm operations now available in authkit" />
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
</component>
<component name="VgoProject">

View File

@ -1,7 +1,6 @@
package authkit
import (
"context"
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
@ -14,7 +13,7 @@ func AddEvent(nx *nex.Conn, userId uint, action, target, ip, ua string) error {
if err != nil {
return fmt.Errorf("failed to get auth service client: %v", err)
}
_, err = proto.NewAuditServiceClient(conn).RecordEvent(context.Background(), &proto.RecordEventRequest{
_, err = proto.NewAuditServiceClient(conn).RecordEvent(nil, &proto.RecordEventRequest{
UserId: uint64(userId),
Action: action,
Target: target,
@ -34,7 +33,7 @@ func AddEventExt(nx *nex.Conn, action, target string, c *fiber.Ctx) error {
if err != nil {
return fmt.Errorf("failed to get auth service client: %v", err)
}
_, err = proto.NewAuditServiceClient(conn).RecordEvent(context.Background(), &proto.RecordEventRequest{
_, err = proto.NewAuditServiceClient(conn).RecordEvent(nil, &proto.RecordEventRequest{
UserId: uint64(user.ID),
Action: action,
Target: target,

View File

@ -1,26 +0,0 @@
package authkit
import (
"context"
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/samber/lo"
)
func EnsureUserPermGranted(nx *nex.Conn, userId, otherId uint, key string, val any) error {
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
if err != nil {
return fmt.Errorf("failed to get auth service client: %v", err)
}
resp, err := proto.NewAuthServiceClient(conn).EnsureUserPermGranted(context.Background(), &proto.CheckUserPermRequest{
UserId: uint64(userId),
OtherId: uint64(otherId),
Key: key,
Value: nex.EncodeMap(val),
})
if err != nil {
return err
}
return lo.Ternary(resp.GetIsValid(), nil, fmt.Errorf("missing permission: %v", key))
}

View File

@ -1,7 +1,6 @@
package authkit
import (
"context"
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/passport/pkg/proto"
@ -18,7 +17,7 @@ func NotifyUser(nx *nex.Conn, userId uint64, notify pushkit.Notification, unsave
if len(unsaved) == 0 {
unsaved = append(unsaved, false)
}
_, err = proto.NewNotifyServiceClient(conn).NotifyUser(context.Background(), &proto.NotifyUserRequest{
_, err = proto.NewNotifyServiceClient(conn).NotifyUser(nil, &proto.NotifyUserRequest{
UserId: userId,
Notify: &proto.NotifyInfoPayload{
Unsaved: unsaved[0],
@ -37,7 +36,7 @@ func NotifyUserBatch(nx *nex.Conn, userId []uint64, notify pushkit.Notification,
if len(unsaved) == 0 {
unsaved = append(unsaved, false)
}
_, err = proto.NewNotifyServiceClient(conn).NotifyUserBatch(context.Background(), &proto.NotifyUserBatchRequest{
_, err = proto.NewNotifyServiceClient(conn).NotifyUserBatch(nil, &proto.NotifyUserBatchRequest{
UserId: userId,
Notify: &proto.NotifyInfoPayload{
Unsaved: unsaved[0],

View File

@ -1,7 +1,6 @@
package authkit
import (
"context"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/proto"
@ -14,7 +13,7 @@ func GetRealm(nx *nex.Conn, id uint) (models.Realm, error) {
if err != nil {
return realm, err
}
resp, err := proto.NewRealmServiceClient(conn).GetRealm(context.Background(), &proto.LookupRealmRequest{
resp, err := proto.NewRealmServiceClient(conn).GetRealm(nil, &proto.LookupRealmRequest{
Id: lo.ToPtr(uint64(id)),
})
if err != nil {
@ -29,7 +28,7 @@ func GetRealmByAlias(nx *nex.Conn, alias string) (models.Realm, error) {
if err != nil {
return realm, err
}
resp, err := proto.NewRealmServiceClient(conn).GetRealm(context.Background(), &proto.LookupRealmRequest{
resp, err := proto.NewRealmServiceClient(conn).GetRealm(nil, &proto.LookupRealmRequest{
Alias: &alias,
})
if err != nil {
@ -44,7 +43,7 @@ func ListRealm(nx *nex.Conn, id []uint) ([]models.Realm, error) {
if err != nil {
return realms, err
}
resp, err := proto.NewRealmServiceClient(conn).ListRealm(context.Background(), &proto.ListRealmRequest{
resp, err := proto.NewRealmServiceClient(conn).ListRealm(nil, &proto.ListRealmRequest{
Id: lo.Map(id, func(item uint, _ int) uint64 {
return uint64(item)
}),
@ -64,7 +63,7 @@ func GetRealmMember(nx *nex.Conn, realmID, userID uint) (models.RealmMember, err
if err != nil {
return member, err
}
resp, err := proto.NewRealmServiceClient(conn).GetRealmMember(context.Background(), &proto.RealmMemberLookupRequest{
resp, err := proto.NewRealmServiceClient(conn).GetRealmMember(nil, &proto.RealmMemberLookupRequest{
RealmId: lo.ToPtr(uint64(realmID)),
UserId: lo.ToPtr(uint64(userID)),
})
@ -80,7 +79,7 @@ func ListRealmMember(nx *nex.Conn, realmID uint) ([]models.RealmMember, error) {
if err != nil {
return members, err
}
resp, err := proto.NewRealmServiceClient(conn).ListRealmMember(context.Background(), &proto.RealmMemberLookupRequest{
resp, err := proto.NewRealmServiceClient(conn).ListRealmMember(nil, &proto.RealmMemberLookupRequest{
RealmId: lo.ToPtr(uint64(realmID)),
})
if err != nil {
@ -97,7 +96,7 @@ func CheckRealmMemberPerm(nx *nex.Conn, realmID uint, userID, power int) bool {
if err != nil {
return false
}
resp, err := proto.NewRealmServiceClient(conn).CheckRealmMemberPerm(context.Background(), &proto.CheckRealmPermRequest{
resp, err := proto.NewRealmServiceClient(conn).CheckRealmMemberPerm(nil, &proto.CheckRealmPermRequest{
RealmId: uint64(realmID),
UserId: uint64(userID),
PowerLevel: int32(power),

View File

@ -1,7 +1,6 @@
package authkit
import (
"context"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
)
@ -11,13 +10,10 @@ func ListRelative(nx *nex.Conn, userId uint, status int32, isRelated bool) ([]*p
if err != nil {
return nil, err
}
resp, err := proto.NewUserServiceClient(conn).ListUserRelative(context.Background(), &proto.ListUserRelativeRequest{
resp, err := proto.NewUserServiceClient(conn).ListUserRelative(nil, &proto.ListUserRelativeRequest{
UserId: uint64(userId),
Status: status,
IsRelated: isRelated,
})
if err != nil {
return nil, err
}
return resp.GetData(), err
}