diff --git a/.github/workflows/go-lint-check.yaml b/.github/workflows/go-lint-check.yaml index 3db17350..94eba792 100644 --- a/.github/workflows/go-lint-check.yaml +++ b/.github/workflows/go-lint-check.yaml @@ -27,7 +27,7 @@ jobs: # working-directory: ./... # Optional: golangci-lint command line arguments. - args: --timeout 2m00s + args: --timeout 3m00s # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true diff --git a/examples/identity/cmd/change_password.go b/examples/identity/cmd/change_password.go deleted file mode 100644 index af19eb9f..00000000 --- a/examples/identity/cmd/change_password.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2022 IndyKite -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cmd - -import ( - "context" - "fmt" - "log" - - "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry" - "github.com/spf13/cobra" - - identitypb "github.com/indykite/indykite-sdk-go/gen/indykite/identity/v1beta2" -) - -// changePwdCmd represents the plan command -var changeDtPwdTokenCmd = &cobra.Command{ - Use: "change_password_with_token", - Short: "Change the password of DigitalTwin", - Long: `Change the Password of DigitalTwin by token. - - Valid token of the user whos password to change is required.`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Print("Enter access_token: ") - var accessToken, newPassword string - fmt.Scanln(&accessToken) - fmt.Print("Enter new password: ") - fmt.Scanln(&newPassword) - - err := client.ChangeMyPassword(context.Background(), accessToken, newPassword, retry.WithMax(2)) - if err != nil { - log.Fatalf("failed to invoke operation on IndyKite Client %v", err) - } - }, -} - -// changePwdIDCmd represents the plan command -var changeDtPwdCmd = &cobra.Command{ - Use: "change_password", - Short: "Change the password of DigitalTwin", - Long: `Change the Password of DigitalTwin.`, - Run: func(cmd *cobra.Command, args []string) { - var digitalTwinID, tenantID, newPassword string - fmt.Print("Enter digital_twin_id: ") - fmt.Scanln(&digitalTwinID) - fmt.Print("Enter tenant_id: ") - fmt.Scanln(&tenantID) - fmt.Print("Enter new password: ") - fmt.Scanln(&newPassword) - - resp, err := client.ChangePasswordOfDigitalTwin( - context.Background(), - &identitypb.DigitalTwin{ - Id: digitalTwinID, - TenantId: tenantID, - }, - newPassword, - retry.WithMax(2), - ) - if err != nil { - log.Fatalf("failed to invoke operation on IndyKite Client %v", err) - } - fmt.Println(jsonp.Format(resp)) - }, -} - -func init() { - dtCmd.AddCommand(changeDtPwdTokenCmd) - dtCmd.AddCommand(changeDtPwdCmd) -} diff --git a/examples/identity/cmd/verify_email.go b/examples/identity/cmd/verify_email.go deleted file mode 100644 index 2b5d0b8b..00000000 --- a/examples/identity/cmd/verify_email.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2022 IndyKite -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cmd - -import ( - "context" - "fmt" - "log" - - "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry" - "github.com/spf13/cobra" - - identitypb "github.com/indykite/indykite-sdk-go/gen/indykite/identity/v1beta2" - objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta1" -) - -// emailVerCmd represents the plan command -var emailVerCmd = &cobra.Command{ - Use: "verify_email_start", - Short: "Starts Email Verification", - Long: `General commands for DigitalTwin - - This is a sample only.`, - Run: func(cmd *cobra.Command, args []string) { - var digitalTwinID, tenantID, email string - fmt.Print("Enter digital_twin_id: ") - fmt.Scanln(&digitalTwinID) - fmt.Print("Enter tenant_id: ") - fmt.Scanln(&tenantID) - fmt.Print("Enter email address: ") - fmt.Scanln(&email) - - // anyPb, _ := anypb.New(wrapperspb.String("test")) - // anyObject, _ := objects.Any(anyPb) - - err := client.StartEmailVerification(context.Background(), - &identitypb.DigitalTwin{ - TenantId: tenantID, - Id: digitalTwinID, - }, email, - &objects.MapValue{ - Fields: map[string]*objects.Value{ - "name": objects.String("Grandpa"), - // "String": objects.String("String"), - // "Int64": objects.Int64(-64), - // "UInt64": {Value: &objects.Value_UnsignedIntegerValue{UnsignedIntegerValue: 64}}, - // "Bool": objects.Bool(true), - // "Float64": objects.Float64(6.4), - // "Time": {Value: &objects.Value_ValueTime{ValueTime: timestamppb.Now()}}, - // "Duration": {Value: &objects.Value_DurationValue{DurationValue: durationpb.New(time.Duration(1) * time.Hour + time.Duration(33) * time.Minute + time.Duration(10) * time.Second + time.Duration(250) * time.Millisecond)}}, - // "Identifier": {Value: &objects.Value_IdentifierValue{IdentifierValue: objects.FromUUID(test.WillyWonkaCredentialID.UUID())}}, - // "Bytes": {Value: &objects.Value_BytesValue{BytesValue: []byte("somefunnyjokeaboutdinosaurs")}}, - // "GeoPointValue": {Value: &objects.Value_GeoPointValue{GeoPointValue: &latlng.LatLng{Latitude: 64, Longitude: 64.09}}}, - // "Array": {Value: &objects.Value_ArrayValue{ArrayValue: &objects.ArrayValue{Values: []*objects.Value{ - // objects.String("item1"), - // objects.Int64(2), - // objects.Null(), - // nil, - // }}}}, - // "ValueNull": objects.Null(), - // "ObjectNull": nil, - // "ToMapValue": {Value: &objects.Value_MapValue{MapValue: &objects.MapValue{Fields: map[string]*objects.Value{ - // "String": objects.String("item1"), - // "Int64": objects.Int64(2), - // "ValueNull": objects.Null(), - // "ObjectNull": nil, - // }}}}, - // "Any1":anyObject, - }, - }, - ) - if err != nil { - er(err) - } - }, -} - -// emailVerCompleteCmd represents the plan command -var emailVerCompleteCmd = &cobra.Command{ - Use: "verify_email_complete", - Short: "Completes Email Verification", - Long: `General commands for DigitalTwin - - This is a sample only.`, - Run: func(cmd *cobra.Command, args []string) { - for { - fmt.Print("Enter referenceId: ") - var input string - fmt.Scanln(&input) - resp, err := client.VerifyDigitalTwinEmail(context.Background(), input, retry.WithMax(2)) - if err != nil { - log.Printf("failed to invoke operation on IndyKite Client %v\n", err) - continue - } - fmt.Printf("Email confirmed for: %s\n", jsonp.Format(resp)) - } - }, -} - -func init() { - dtCmd.AddCommand(emailVerCmd) - dtCmd.AddCommand(emailVerCompleteCmd) -} diff --git a/identity/digital_twin.go b/identity/digital_twin.go index a62a906f..d32d6625 100644 --- a/identity/digital_twin.go +++ b/identity/digital_twin.go @@ -22,53 +22,8 @@ import ( "github.com/indykite/indykite-sdk-go/errors" identitypb "github.com/indykite/indykite-sdk-go/gen/indykite/identity/v1beta2" - objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta1" ) -// StartEmailVerification function initiates the flow where Indykite systems sends a -// notification to DigitalTwin with a link to verify the control over -// the notification channel (email only for now). -// -// This is a protected operation and it can be accessed only with valid agent credentials! -func (c *Client) StartEmailVerification(ctx context.Context, digitalTwin *identitypb.DigitalTwin, email string, - attributes *objects.MapValue, opts ...grpc.CallOption) error { - req := &identitypb.StartDigitalTwinEmailVerificationRequest{ - DigitalTwin: digitalTwin, - Email: email, - Attributes: attributes, - } - if err := req.Validate(); err != nil { - return errors.NewInvalidArgumentErrorWithCause(err, "unable to call StartEmailVerification") - } - - ctx = insertMetadata(ctx, c.xMetadata) - _, err := c.client.StartDigitalTwinEmailVerification(ctx, req, opts...) - - return errors.FromError(err) -} - -// VerifyDigitalTwinEmail function confirms to IndyKite system that the message from -// StartDigitalTwinEmailVerification function was sent and user visited the link. -// -// This is a protected operation and it can be accessed only with valid agent credentials! -func (c *Client) VerifyDigitalTwinEmail(ctx context.Context, - token string, opts ...grpc.CallOption) (*identitypb.DigitalTwin, error) { - req := &identitypb.VerifyDigitalTwinEmailRequest{ - Token: token, - } - if err := req.Validate(); err != nil { - return nil, errors.NewInvalidArgumentErrorWithCause(err, "unable to call VerifyDigitalTwinEmail") - } - - ctx = insertMetadata(ctx, c.xMetadata) - resp, err := c.client.VerifyDigitalTwinEmail(ctx, req, opts...) - - if s := errors.FromError(err); s != nil { - return nil, s - } - return resp.GetDigitalTwin(), nil -} - // IntrospectToken function validates the token and returns information about it. // // This is a protected operation and it can be accessed only with valid agent credentials! @@ -92,56 +47,6 @@ func (c *Client) IntrospectToken(ctx context.Context, } } -// ChangeMyPassword change password of DigitalTwin from bearer token. -func (c *Client) ChangeMyPassword(ctx context.Context, - token string, - newPassword string, - opts ...grpc.CallOption, -) error { - if err := verifyTokenFormat(token); err != nil { - return err - } - if len(newPassword) <= 4 { - return errors.NewInvalidArgumentError("password is too short") - } - - ctx = insertMetadata(ctx, c.xMetadata) - resp, err := c.client.ChangePassword(ctx, &identitypb.ChangePasswordRequest{ - Uid: &identitypb.ChangePasswordRequest_Token{Token: token}, - Password: newPassword, - }, opts...) - - if s := errors.FromError(err); s != nil { - return s - } - if resp.Error != nil { - return errors.NewInvalidArgumentError(resp.Error.Code) - } - return nil -} - -// ChangePasswordOfDigitalTwin change password of passed DigitalTwin. -func (c *Client) ChangePasswordOfDigitalTwin(ctx context.Context, - digitalTwin *identitypb.DigitalTwin, - newPassword string, - opts ...grpc.CallOption, -) (*identitypb.ChangePasswordResponse, error) { - if len(newPassword) <= 4 { - return nil, errors.NewInvalidArgumentError("password is too short") - } - - ctx = insertMetadata(ctx, c.xMetadata) - resp, err := c.client.ChangePassword(ctx, &identitypb.ChangePasswordRequest{ - Uid: &identitypb.ChangePasswordRequest_DigitalTwin{DigitalTwin: digitalTwin}, - Password: newPassword, - }, opts...) - - if s := errors.FromError(err); s != nil { - return nil, s - } - return resp, nil -} - func (c *Client) getDigitalTwinWithProperties(ctx context.Context, identifier *identitypb.DigitalTwinIdentifier, properties []*identitypb.PropertyMask,