Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add patch identity method #11

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,33 @@ func (a auth) GetTokens(ctx context.Context) ([]Provider, error) {
return providers, nil

}

// PatchIdentity record some field of identity
func (a auth) PatchIdentity(ctx context.Context, id string, jsonPatch []client.JsonPatch) (*client.Identity, error) {
log := logx.WithName(ctx, "PatchIdentity")
cfg := client.NewConfiguration()

u, err := a.getKratosAdminAddress()
if err != nil {
log.Error(err, "fail to get admin kratos address")
return nil, errorx.NewHTTP(err, http.StatusInternalServerError, "fail to get kratos address")
}
cfg.Scheme = u.Scheme
cfg.Host = u.Host
cfg.Servers = []client.ServerConfiguration{
{
URL: u.String(),
},
}

api := client.NewAPIClient(cfg)
r := api.IdentityApi.PatchIdentity(ctx, id)
r.JsonPatch(jsonPatch)

i, _, err := r.Execute()
if err != nil {
log.Error(err, "patching failed")
return nil, errorx.NewHTTP(err, http.StatusInternalServerError, "http patch failed")
}
return i, nil
}
2 changes: 2 additions & 0 deletions kratox.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Helper interface {
// DeleteIdentity is used to delete the identity who correspond to the user id on kratos service
// if kratos is unreachable or an other issues, return nil session with statusCode of the call and error-go
DeleteIdentity(context.Context, string) error

PatchIdentity(context.Context, string, []client.JsonPatch) (*client.Identity, error)
}

type Provider struct {
Expand Down
Loading