♻️ Replace nil context with context.Background in authkit

This commit is contained in:
LittleSheep 2024-11-02 12:48:17 +08:00
parent d1f1183beb
commit b4da8ce78b
5 changed files with 29 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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