Skip to content

Commit

Permalink
Merge pull request #83 from aserto-dev/get-relation-with-objects
Browse files Browse the repository at this point in the history
Forward compatible GetIdentityV2
  • Loading branch information
ronenh committed May 3, 2023
2 parents ae3ff83 + e775c50 commit ce6518b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion directory/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package directory
import (
"context"
"errors"
"fmt"

cerr "github.com/aserto-dev/errors"
"github.com/aserto-dev/go-authorizer/pkg/aerr"
Expand Down Expand Up @@ -36,5 +37,9 @@ func GetIdentityV2(client ds2.ReaderClient, ctx context.Context, identity string
return nil, aerr.ErrDirectoryObjectNotFound.Msg("no objects found in relation")
}

return relResp.Objects[*relResp.Results[0].Subject.Id], nil
subj := relResp.Results[0].Subject
if subj.Id == nil {
return relResp.Objects[fmt.Sprintf("%s:%s", *subj.Type, *subj.Key)], nil
}
return relResp.Objects[*subj.Id], nil
}

0 comments on commit ce6518b

Please sign in to comment.