Documentation ¶
Overview ¶
Package knowledge implements the IndyKite Identity Knowledge API Client.
Index ¶
- Constants
- func ParseSingleNodeFromNodes(nodes []*knowledgeobjects.Node) (*knowledgeobjects.Node, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) GetIdentityByID(ctx context.Context, id string, opts ...grpc.CallOption) (*knowledgeobjects.Node, error)
- func (c *Client) GetIdentityByIdentifier(ctx context.Context, identifier *Identifier, opts ...grpc.CallOption) (*knowledgeobjects.Node, error)
- func (c *Client) GetNodeByID(ctx context.Context, id string, isIdentity bool, opts ...grpc.CallOption) (*knowledgeobjects.Node, error)
- func (c *Client) GetNodeByIdentifier(ctx context.Context, identifier *Identifier, isIdentity bool, ...) (*knowledgeobjects.Node, error)
- func (c *Client) IdentityKnowledgeRead(ctx context.Context, query string, inputParams map[string]*objects.Value, ...) (*knowledgepb.IdentityKnowledgeReadResponse, error)
- func (c *Client) ListIdentities(ctx context.Context, opts ...grpc.CallOption) ([]*knowledgeobjects.Node, error)
- func (c *Client) ListIdentitiesByProperty(ctx context.Context, property *knowledgeobjects.Property, ...) ([]*knowledgeobjects.Node, error)
- func (c *Client) ListNodes(ctx context.Context, nodeType string, opts ...grpc.CallOption) ([]*knowledgeobjects.Node, error)
- func (c *Client) ListNodesByProperty(ctx context.Context, property *knowledgeobjects.Property, isIdentity bool, ...) ([]*knowledgeobjects.Node, error)
- type Identifier
Examples ¶
Constants ¶
const ( ExternalID = "external_id" Type = "type" ID = "id" )
Variables ¶
This section is empty.
Functions ¶
func ParseSingleNodeFromNodes ¶ added in v0.22.0
func ParseSingleNodeFromNodes(nodes []*knowledgeobjects.Node) (*knowledgeobjects.Node, error)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient creates a new Identity Knowledge API gRPC Client.
Example (Default) ¶
This example demonstrates how to create a new Identity Knowledge Client.
package main import ( "context" "log" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } _ = client.Close() }
Output:
Example (Options) ¶
This example demonstrates how to create a new Identity Knowledge Client.
package main import ( "context" "log" api "github.com/indykite/indykite-sdk-go/grpc" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background(), api.WithCredentialsJSON([]byte(`{}`))) if err != nil { log.Fatalf("failed to create client %v", err) } _ = client.Close() }
Output:
func NewTestClient ¶
func NewTestClient(client knowledgepb.IdentityKnowledgeAPIClient) (*Client, error)
NewTestClient creates a new Identity Knowledge gRPC Client.
func (*Client) Close ¶
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) GetIdentityByID ¶ added in v0.22.0
func (c *Client) GetIdentityByID( ctx context.Context, id string, opts ...grpc.CallOption, ) (*knowledgeobjects.Node, error)
GetIdentityByID is a helper function that queries for a Identity node by its id.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to get an Identity by its id.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.GetIdentityByID(context.Background(), "gid:AAAAAmluZHlraURlgAABDwAAAAA") if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) GetIdentityByIdentifier ¶ added in v0.22.0
func (c *Client) GetIdentityByIdentifier( ctx context.Context, identifier *Identifier, opts ...grpc.CallOption, ) (*knowledgeobjects.Node, error)
GetIdentityByIdentifier is a helper function that queries for a Identity node by its externalID + type combination.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to get an Identity by its externalID + type combination.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.GetIdentityByIdentifier(context.Background(), &knowledge.Identifier{ ExternalID: "1234", Type: "Person", }, ) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) GetNodeByID ¶ added in v0.22.0
func (c *Client) GetNodeByID( ctx context.Context, id string, isIdentity bool, opts ...grpc.CallOption, ) (*knowledgeobjects.Node, error)
func (*Client) GetNodeByIdentifier ¶ added in v0.22.0
func (c *Client) GetNodeByIdentifier(ctx context.Context, identifier *Identifier, isIdentity bool, opts ...grpc.CallOption, ) (*knowledgeobjects.Node, error)
func (*Client) IdentityKnowledgeRead ¶ added in v0.22.0
func (c *Client) IdentityKnowledgeRead( ctx context.Context, query string, inputParams map[string]*objects.Value, returns []*knowledgepb.Return, opts ...grpc.CallOption, ) (*knowledgepb.IdentityKnowledgeReadResponse, error)
IdentityKnowledgeRead sends a READ operation to the Identity Knowledge API, with the desired query, inputParams and returns.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to do an IdentityKnowledgeRead query.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta2" objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta2" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() query := "MATCH (n:Person)-[:HAS]->(s:Store) WHERE n.external_id = $external_id" params := map[string]*objects.Value{ "external_id": { Type: &objects.Value_StringValue{StringValue: "1234"}, }, } returns := []*knowledgepb.Return{ { Variable: "n", }, } response, err := client.IdentityKnowledgeRead(context.Background(), query, params, returns) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } fmt.Println(json.Format(response)) }
Output:
func (*Client) ListIdentities ¶ added in v0.22.0
func (c *Client) ListIdentities( ctx context.Context, opts ...grpc.CallOption) ([]*knowledgeobjects.Node, error)
ListIdentities is a helper function that lists all Identity nodes.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all Identities.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListIdentities(context.Background()) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListIdentitiesByProperty ¶ added in v0.22.0
func (c *Client) ListIdentitiesByProperty( ctx context.Context, property *knowledgeobjects.Property, opts ...grpc.CallOption) ([]*knowledgeobjects.Node, error)
ListIdentitiesByProperty is a helper function that lists all Identity nodes that have the specified property.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all Identities that have a certain property.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgeobjects "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/objects/v1beta1" objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta2" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListIdentitiesByProperty(context.Background(), &knowledgeobjects.Property{ Type: "email", Value: &objects.Value{ Type: &objects.Value_StringValue{ StringValue: "test@test.com", }, }, }, ) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListNodes ¶
func (c *Client) ListNodes( ctx context.Context, nodeType string, opts ...grpc.CallOption, ) ([]*knowledgeobjects.Node, error)
ListNodes is a helper function that lists all nodes by given node type, regardless of whether they are Identities or not.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all nodes.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListNodes(context.Background(), "Resource") if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
func (*Client) ListNodesByProperty ¶
func (c *Client) ListNodesByProperty( ctx context.Context, property *knowledgeobjects.Property, isIdentity bool, opts ...grpc.CallOption, ) ([]*knowledgeobjects.Node, error)
ListNodesByProperty is a helper function that lists all nodes that have the specified type and property.
Example ¶
This example demonstrates how to use the Identity Knowledge Client to list all nodes with a certain type and property.
package main import ( "context" "fmt" "log" "google.golang.org/protobuf/encoding/protojson" knowledgeobjects "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/objects/v1beta1" objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta2" "github.com/indykite/indykite-sdk-go/knowledge" ) func main() { client, err := knowledge.NewClient(context.Background()) if err != nil { log.Fatalf("failed to create client %v", err) } defer func() { _ = client.Close() }() response, err := client.ListNodesByProperty( context.Background(), &knowledgeobjects.Property{ Type: "email", Value: &objects.Value{ Type: &objects.Value_StringValue{ StringValue: "test@test.com", }, }, }, false) if err != nil { log.Fatalf("failed to invoke operation on IndyKite Client %v", err) } json := protojson.MarshalOptions{ Multiline: true, } for _, n := range response { fmt.Println(json.Format(n)) } }
Output:
type Identifier ¶
Identifier is the combination of ExternalID and Type which uniquely identifies a node in the Identity Knowledge Graph.