Skip to content

Commit

Permalink
feat: upgrade identity api to v1beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
hankadev committed Jan 12, 2023
1 parent 0b09909 commit 8a8b328
Show file tree
Hide file tree
Showing 50 changed files with 2,236 additions and 331 deletions.
54 changes: 32 additions & 22 deletions authorization/is_authorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ func (c *Client) IsAuthorized(
opts ...grpc.CallOption,
) (*authorizationpb.IsAuthorizedResponse, error) {
return c.IsAuthorizedWithRawRequest(ctx, &authorizationpb.IsAuthorizedRequest{
Subject: &identitypb.DigitalTwinIdentifier{Filter: &identitypb.DigitalTwinIdentifier_DigitalTwin{
DigitalTwin: digitalTwin,
}},
Subject: &authorizationpb.IsAuthorizedRequest_DigitalTwinIdentifier{
DigitalTwinIdentifier: &identitypb.DigitalTwinIdentifier{
Filter: &identitypb.DigitalTwinIdentifier_DigitalTwin{DigitalTwin: digitalTwin},
},
},
Actions: actions,
Resources: resources,
}, opts...)
Expand All @@ -59,9 +61,10 @@ func (c *Client) IsAuthorizedByToken(
opts ...grpc.CallOption,
) (*authorizationpb.IsAuthorizedResponse, error) {
return c.IsAuthorizedWithRawRequest(ctx, &authorizationpb.IsAuthorizedRequest{
Subject: &identitypb.DigitalTwinIdentifier{Filter: &identitypb.DigitalTwinIdentifier_AccessToken{
AccessToken: token,
}},
Subject: &authorizationpb.IsAuthorizedRequest_DigitalTwinIdentifier{
DigitalTwinIdentifier: &identitypb.DigitalTwinIdentifier{
Filter: &identitypb.DigitalTwinIdentifier_AccessToken{AccessToken: token},
}},
Actions: actions,
Resources: resources,
}, opts...)
Expand All @@ -77,12 +80,15 @@ func (c *Client) IsAuthorizedByStringExternalID(
opts ...grpc.CallOption,
) (*authorizationpb.IsAuthorizedResponse, error) {
return c.IsAuthorizedWithRawRequest(ctx, &authorizationpb.IsAuthorizedRequest{
Subject: &identitypb.DigitalTwinIdentifier{Filter: &identitypb.DigitalTwinIdentifier_PropertyFilter{
PropertyFilter: &identitypb.PropertyFilter{
Type: externalIDProperty,
Value: objects.String(externalID),
},
}},
Subject: &authorizationpb.IsAuthorizedRequest_DigitalTwinIdentifier{
DigitalTwinIdentifier: &identitypb.DigitalTwinIdentifier{
Filter: &identitypb.DigitalTwinIdentifier_PropertyFilter{
PropertyFilter: &identitypb.PropertyFilter{
Type: externalIDProperty,
Value: objects.String(externalID),
},
},
}},
Actions: actions,
Resources: resources,
}, opts...)
Expand All @@ -98,12 +104,15 @@ func (c *Client) IsAuthorizedByNumericExternalID(
opts ...grpc.CallOption,
) (*authorizationpb.IsAuthorizedResponse, error) {
return c.IsAuthorizedWithRawRequest(ctx, &authorizationpb.IsAuthorizedRequest{
Subject: &identitypb.DigitalTwinIdentifier{Filter: &identitypb.DigitalTwinIdentifier_PropertyFilter{
PropertyFilter: &identitypb.PropertyFilter{
Type: externalIDProperty,
Value: objects.Int64(externalID),
},
}},
Subject: &authorizationpb.IsAuthorizedRequest_DigitalTwinIdentifier{
DigitalTwinIdentifier: &identitypb.DigitalTwinIdentifier{
Filter: &identitypb.DigitalTwinIdentifier_PropertyFilter{
PropertyFilter: &identitypb.PropertyFilter{
Type: externalIDProperty,
Value: objects.Int64(externalID),
},
},
}},
Actions: actions,
Resources: resources,
}, opts...)
Expand All @@ -118,10 +127,11 @@ func (c *Client) IsAuthorizedWithRawRequest(
return nil, errors.NewInvalidArgumentErrorWithCause(err, "unable to call IsAuthorized client endpoint")
}

switch sub := req.Subject.Filter.(type) {
case *identitypb.DigitalTwinIdentifier_AccessToken:
if err := verifyTokenFormat(sub.AccessToken); err != nil {
return nil, err
if sub, ok := req.Subject.(*authorizationpb.IsAuthorizedRequest_DigitalTwinIdentifier); ok {
if filter, ok := sub.DigitalTwinIdentifier.Filter.(*identitypb.DigitalTwinIdentifier_AccessToken); ok {
if err := verifyTokenFormat(filter.AccessToken); err != nil {
return nil, err
}
}
}

Expand Down
16 changes: 3 additions & 13 deletions examples/identity/cmd/change_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
"github.com/indykite/jarvis-sdk-go/identity"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
)

// changePwdCmd represents the plan command
Expand Down Expand Up @@ -61,20 +60,11 @@ var changeDtPwdCmd = &cobra.Command{
fmt.Print("Enter new password: ")
fmt.Scanln(&newPassword)

digitalTwinUUID, err := identity.ParseUUID(digitalTwinID)
if err != nil {
log.Fatalf("failed to parse digitalTwinID: %v", err)
}
tenantUUID, err := identity.ParseUUID(tenantID)
if err != nil {
log.Fatalf("failed to parse tenantID: %v", err)
}

resp, err := client.ChangePasswordOfDigitalTwin(
context.Background(),
&identitypb.DigitalTwin{
Id: digitalTwinUUID,
TenantId: tenantUUID,
Id: digitalTwinID,
TenantId: tenantID,
},
newPassword,
retry.WithMax(2),
Expand Down
10 changes: 5 additions & 5 deletions examples/identity/cmd/consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
)

// planCmd represents the plan command
Expand All @@ -47,7 +47,7 @@ var checkConsentChallengeCmd = &cobra.Command{

resp, err := client.CheckConsentChallenge(
context.Background(),
&identitypb.CheckConsentChallengeRequest{Challenge: consentChallenge},
&identitypb.CheckOAuth2ConsentChallengeRequest{Challenge: consentChallenge},
retry.WithMax(2),
)
if err != nil {
Expand All @@ -67,7 +67,7 @@ var createConsentVerifier = &cobra.Command{
var consentChallenge string
fmt.Scanln(&consentChallenge)

req := &identitypb.CreateConsentVerifierRequest{Challenge: consentChallenge}
req := &identitypb.CreateOAuth2ConsentVerifierRequest{ConsentChallenge: consentChallenge}
fmt.Print("Enter 1 for Approval or 2 for Denial: ")
var result string
fmt.Scanln(&result)
Expand All @@ -85,7 +85,7 @@ var createConsentVerifier = &cobra.Command{

fmt.Println(jsonp.Format(denial))

req.Result = &identitypb.CreateConsentVerifierRequest_Denial{Denial: denial}
req.Result = &identitypb.CreateOAuth2ConsentVerifierRequest_Denial{Denial: denial}
default:
approval := &identitypb.ConsentApproval{}
for {
Expand All @@ -97,7 +97,7 @@ var createConsentVerifier = &cobra.Command{
}
approval.GrantScopes = append(approval.GrantScopes, scope)
}
req.Result = &identitypb.CreateConsentVerifierRequest_Approval{Approval: approval}
req.Result = &identitypb.CreateOAuth2ConsentVerifierRequest_Approval{Approval: approval}
}

resp, err := client.CreateConsentVerifier(context.Background(), req, retry.WithMax(2))
Expand Down
14 changes: 2 additions & 12 deletions examples/identity/cmd/delete_digital_twin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
"github.com/indykite/jarvis-sdk-go/identity"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
)

// deleteDtTokenCmd represents the delte DigitalTwin command.
Expand Down Expand Up @@ -66,18 +65,9 @@ var deleteDtCmd = &cobra.Command{
fmt.Print("Enter tenant_id: ")
fmt.Scanln(&tenantID)

digitalTwinUUID, err := identity.ParseUUID(digitalTwinID)
if err != nil {
log.Fatalf("failed to parse digitalTwinID: %v", err)
}
tenantUUID, err := identity.ParseUUID(tenantID)
if err != nil {
log.Fatalf("failed to parse tenantID: %v", err)
}

resp, err := client.DeleteDigitalTwin(
context.Background(),
&identitypb.DigitalTwin{Id: digitalTwinUUID, TenantId: tenantUUID},
&identitypb.DigitalTwin{Id: digitalTwinID, TenantId: tenantID},
retry.WithMax(2),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/identity/cmd/enrich_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
"google.golang.org/protobuf/types/known/structpb"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
)

// enrichTokenCmd represents the enrichToken command
Expand Down
14 changes: 2 additions & 12 deletions examples/identity/cmd/get_digital_twin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
"github.com/indykite/jarvis-sdk-go/identity"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
)

// planCmd represents the plan command
Expand Down Expand Up @@ -68,18 +67,9 @@ var getDtCmd = &cobra.Command{
fmt.Print("Enter tenant_id: ")
fmt.Scanln(&tenantID)

digitalTwinUUID, err := identity.ParseUUID(digitalTwinID)
if err != nil {
log.Fatalf("failed to parse digitalTwinID: %v", err)
}
tenantUUID, err := identity.ParseUUID(tenantID)
if err != nil {
log.Fatalf("failed to parse tenantID: %v", err)
}

resp, err := client.GetDigitalTwin(
context.Background(),
&identitypb.DigitalTwin{Id: digitalTwinUUID, TenantId: tenantUUID},
&identitypb.DigitalTwin{Id: digitalTwinID, TenantId: tenantID},
[]*identitypb.PropertyMask{
{Definition: &identitypb.PropertyDefinition{Property: "email"}},
{Definition: &identitypb.PropertyDefinition{Property: "mobile"}},
Expand Down
15 changes: 3 additions & 12 deletions examples/identity/cmd/is_authorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
"github.com/indykite/jarvis-sdk-go/identity"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
)

var isAuthorizedCmd = &cobra.Command{
Expand Down Expand Up @@ -75,17 +74,9 @@ var withDigitalTwinCmd = &cobra.Command{
fmt.Print("Enter tenant_id: ")
fmt.Scanln(&tenantID)

digitalTwinUUID, err := identity.ParseUUID(digitalTwinID)
if err != nil {
log.Fatalf("failed to parse digitalTwinID: %v", err)
}
tenantUUID, err := identity.ParseUUID(tenantID)
if err != nil {
log.Fatalf("failed to parse tenantID: %v", err)
}
digitalTwin := &identitypb.DigitalTwin{
Id: digitalTwinUUID,
TenantId: tenantUUID,
Id: digitalTwinID,
TenantId: tenantID,
}

actions := []string{"ACTION"}
Expand Down
14 changes: 2 additions & 12 deletions examples/identity/cmd/patch_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
objects "github.com/indykite/jarvis-sdk-go/gen/indykite/objects/v1beta1"
"github.com/indykite/jarvis-sdk-go/identity"
)

// patchPropDtTokenCmd represents the patch command
Expand Down Expand Up @@ -78,18 +77,9 @@ var patchPropDtCmd = &cobra.Command{
fmt.Print("Enter tenant_id: ")
fmt.Scanln(&tenantID)

digitalTwinUUID, err := identity.ParseUUID(digitalTwinID)
if err != nil {
log.Fatalf("failed to parse digitalTwinID: %v", err)
}
tenantUUID, err := identity.ParseUUID(tenantID)
if err != nil {
log.Fatalf("failed to parse tenantID: %v", err)
}

resp, err := client.PatchDigitalTwin(
context.Background(),
&identitypb.DigitalTwin{Id: digitalTwinUUID, TenantId: tenantUUID},
&identitypb.DigitalTwin{Id: digitalTwinID, TenantId: tenantID},
[]*identitypb.PropertyBatchOperation{
// {Operation: &identitypb.PropertyBatchOperation_Add{Add: &identitypb.Property{
// Definition: &identitypb.PropertyDefinition{Property: "email"},
Expand Down
18 changes: 4 additions & 14 deletions examples/identity/cmd/verify_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
"github.com/spf13/cobra"

identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta1"
identitypb "github.com/indykite/jarvis-sdk-go/gen/indykite/identity/v1beta2"
objects "github.com/indykite/jarvis-sdk-go/gen/indykite/objects/v1beta1"
"github.com/indykite/jarvis-sdk-go/identity"
)

// emailVerCmd represents the plan command
Expand All @@ -43,22 +42,13 @@ var emailVerCmd = &cobra.Command{
fmt.Print("Enter email address: ")
fmt.Scanln(&email)

digitalTwinUUID, err := identity.ParseUUID(digitalTwinID)
if err != nil {
log.Fatalf("failed to parse digitalTwinID: %v", err)
}
tenantUUID, err := identity.ParseUUID(tenantID)
if err != nil {
log.Fatalf("failed to parse tenantID: %v", err)
}

// anyPb, _ := anypb.New(wrapperspb.String("test"))
// anyObject, _ := objects.Any(anyPb)

err = client.StartEmailVerification(context.Background(),
err := client.StartEmailVerification(context.Background(),
&identitypb.DigitalTwin{
TenantId: tenantUUID,
Id: digitalTwinUUID,
TenantId: tenantID,
Id: digitalTwinID,
}, email,
&objects.MapValue{
Fields: map[string]*objects.Value{
Expand Down
Loading

0 comments on commit 8a8b328

Please sign in to comment.