Skip to content

Commit

Permalink
Update signature to match new core
Browse files Browse the repository at this point in the history
  • Loading branch information
MOmarMiraj committed Oct 7, 2024
1 parent 97cf886 commit 7b096c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
8 changes: 5 additions & 3 deletions client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ func WithIntegrationInfo(name string, version string) ClientOption {

func clientInvoke(ctx context.Context, innerClient internal.InnerClient, invocation string, params map[string]interface{}) (*string, error) {
invocationResponse, err := innerClient.Core.Invoke(ctx, internal.InvokeConfig{
ClientID: innerClient.ID,
Invocation: internal.Invocation{
MethodName: invocation,
SerializedParams: params,
ClientID: &innerClient.ID,
Parameters: internal.Parameters{
MethodName: invocation,
SerializedParams: params,
},
},
})
if err != nil {
Expand Down
22 changes: 15 additions & 7 deletions integration_tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,38 @@ func TestInvalidInvoke(t *testing.T) {

// invalid client id
invocation1 := internal.InvokeConfig{
ClientID: invalidClientID,
Invocation: internal.Invocation{
MethodName: validMethodName,
SerializedParams: validParams,
ClientID: &invalidClientID,
Parameters: internal.Parameters{
MethodName: validMethodName,
SerializedParams: validParams,
},
},
}
_, err1 := core.Invoke(context.Background(), invocation1)
assert.EqualError(t, err1, "an internal error occurred, please contact 1Password at support@1password.com or https://developer.1password.com/joinslack: invalid client id")

// invalid method name
invocation2 := internal.InvokeConfig{
ClientID: validClientID,
Invocation: internal.Invocation{
ClientID: &validClientID,
Parameters: internal.Parameters {
MethodName: invalidMethodName,
SerializedParams: invalidParams,
},
}}
_, err2 := core.Invoke(context.Background(), invocation2)
assert.NotNil(t, err2, "expected error when sending invocation that doesn't exist")

// invalid serialized params
invocation3 := internal.InvokeConfig{
ClientID: validClientID,
Invocation: internal.Invocation{
ClientID: &validClientID,
Parameters: internal.Parameters{
MethodName: validMethodName,
SerializedParams: invalidParams,
},
},
}
_, err3 := core.Invoke(context.Background(), invocation3)
assert.EqualError(t, err3, "error resolving secret reference: secret reference is not prefixed with \"op://\"")
Expand All @@ -127,13 +133,15 @@ func TestClientReleasedSuccessfully(t *testing.T) {

core, err := internal.GetSharedCore()
require.NoError(t, err)

clientID:= uint64(0)
invocation := internal.InvokeConfig{
ClientID: 0, // this client id should be invalid because the client has been cleaned up by GC
Invocation: internal.Invocation{
ClientID: &clientID, // this client id should be invalid because the client has been cleaned up by GC
Parameters: internal.Parameters{
MethodName: "SecretsResolve",
SerializedParams: map[string]interface{}{"secret_reference": "op://foo/bar/baz"},
},
},
}
_, err = core.Invoke(context.Background(), invocation)
assert.EqualError(t, err, "an internal error occurred, please contact 1Password at support@1password.com or https://developer.1password.com/joinslack: invalid client id")
Expand Down
6 changes: 5 additions & 1 deletion internal/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ func NewDefaultConfig() ClientConfig {

// InvokeConfig specifies over the FFI on which client the specified method should be invoked on.
type InvokeConfig struct {
ClientID uint64 `json:"clientId"`
Invocation Invocation `json:"invocation"`
}

// Invocation holds the information required for invoking SDK functionality.
type Invocation struct {
ClientID *uint64 `json:"clientId,omitempty"`
Parameters Parameters `json:"parameters"`
}

type Parameters struct{
MethodName string `json:"name"`
SerializedParams map[string]interface{} `json:"parameters"`
}
Expand Down

0 comments on commit 7b096c6

Please sign in to comment.