Skip to content

Commit

Permalink
feat: implement knowledge and objects v1beta2
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ENG-2778
  • Loading branch information
cowan-macady committed Feb 7, 2024
1 parent ea3b16a commit a5bf26e
Show file tree
Hide file tree
Showing 68 changed files with 13,053 additions and 5,820 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ default_stages: [commit, push]
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-case-conflict
Expand Down Expand Up @@ -56,7 +56,7 @@ repos:
# exclude: ^(CHANGELOG|responsible_disclosure).md$

- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.5.0
rev: v9.11.0
hooks:
- id: commitlint
stages: [commit-msg]
Expand Down
93 changes: 0 additions & 93 deletions config/config_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,53 +466,6 @@ var _ = Describe("ConfigNode", func() {
Expect(resp).To(test.EqualProto(beResp))
})

It("CreateKnowledgeGraphSchema", func() {
schemaInput := `
type Person implements DigitalTwin {
externalId: String!
digitalTwinId: String!
tenantId: String!
kind: DigitalTwinKind!
tags: [String!]!
}
`
configuration := &configpb.KnowledgeGraphSchemaConfig{
Schema: schemaInput,
}

configNodeRequest, err := config.NewCreate("like-real-config-node-name")
Ω(err).To(Succeed())
configNodeRequest.ForLocation("gid:like-real-customer-id")
configNodeRequest.WithDisplayName("Like real ConfigNode Name")
configNodeRequest.WithKnowledgeGraphSchemaConfig(configuration)

beResp := &configpb.CreateConfigNodeResponse{
Id: "gid:like-real-config-node-id",
Etag: "123qwe",
CreatedBy: "creator",
CreateTime: timestamppb.Now(),
Bookmark: "something-like-bookmark-which-is-long-enough",
}

mockClient.EXPECT().CreateConfigNode(
gomock.Any(),
test.WrapMatcher(PointTo(MatchFields(IgnoreExtras, Fields{
"Name": Equal("like-real-config-node-name"),
"Location": Equal("gid:like-real-customer-id"),
"Config": PointTo(MatchFields(IgnoreExtras, Fields{
"KnowledgeGraphSchemaConfig": PointTo(MatchFields(IgnoreExtras, Fields{
"Schema": Equal(schemaInput),
})),
})),
}))),
gomock.Any(),
).Return(beResp, nil)

resp, err := configClient.CreateConfigNode(ctx, configNodeRequest)
Expect(err).To(Succeed())
Expect(resp).To(test.EqualProto(beResp))
})

It("CreateNonValid", func() {
configuration := &configpb.OAuth2ClientConfig{
ProviderType: configpb.ProviderType_PROVIDER_TYPE_GOOGLE_COM,
Expand Down Expand Up @@ -839,52 +792,6 @@ var _ = Describe("ConfigNode", func() {
Expect(resp).To(test.EqualProto(beResp))
})

It("UpdateKnowledgeGraphSchema", func() {
schemaInput := `
type Person implements DigitalTwin {
externalId: String!
digitalTwinId: String!
tenantId: String!
kind: DigitalTwinKind!
tags: [String!]!
}
`
configuration := &configpb.KnowledgeGraphSchemaConfig{
Schema: schemaInput,
}

configNodeRequest, err := config.NewUpdate("gid:like-real-config-node-id")
Ω(err).To(Succeed())
configNodeRequest.EmptyDisplayName()
configNodeRequest.WithDisplayName("Like real ConfigNode Name Update")
configNodeRequest.WithKnowledgeGraphSchemaConfig(configuration)

beResp := &configpb.UpdateConfigNodeResponse{
Id: "gid:like-real-config-node-id",
Etag: "123qwert",
UpdatedBy: "creator",
UpdateTime: timestamppb.Now(),
Bookmark: "something-like-bookmark-which-is-long-enough",
}

mockClient.EXPECT().UpdateConfigNode(
gomock.Any(),
test.WrapMatcher(PointTo(MatchFields(IgnoreExtras, Fields{
"Id": Equal("gid:like-real-config-node-id"),
"Config": PointTo(MatchFields(IgnoreExtras, Fields{
"KnowledgeGraphSchemaConfig": PointTo(MatchFields(IgnoreExtras, Fields{
"Schema": Equal(schemaInput),
})),
})),
}))),
gomock.Any(),
).Return(beResp, nil)

resp, err := configClient.UpdateConfigNode(ctx, configNodeRequest)
Expect(err).To(Succeed())
Expect(resp).To(test.EqualProto(beResp))
})

It("UpdateNonValid", func() {
configNodeRequest, err := config.NewUpdate("12345")
Ω(err).To(Succeed())
Expand Down
20 changes: 0 additions & 20 deletions config/config_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,6 @@ func (x *NodeRequest) WithAuthorizationPolicyConfig(v *configpb.AuthorizationPol
return x
}

func (x *NodeRequest) WithKnowledgeGraphSchemaConfig(v *configpb.KnowledgeGraphSchemaConfig) *NodeRequest {
switch {
case x.create != nil:
x.create.Config = nil
if v != nil {
x.create.Config = &configpb.CreateConfigNodeRequest_KnowledgeGraphSchemaConfig{
KnowledgeGraphSchemaConfig: v,
}
}
case x.update != nil:
x.update.Config = nil
if v != nil {
x.update.Config = &configpb.UpdateConfigNodeRequest_KnowledgeGraphSchemaConfig{
KnowledgeGraphSchemaConfig: v,
}
}
}
return x
}

func (x *NodeRequest) WithWebauthnProviderConfig(v *configpb.WebAuthnProviderConfig) *NodeRequest {
switch {
case x.create != nil:
Expand Down
3 changes: 2 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//go:generate mockgen -copyright_file ./doc/LICENSE -package config -destination ./test/config/v1beta1/config_management_api_mock.go github.com/indykite/indykite-sdk-go/gen/indykite/config/v1beta1 ConfigManagementAPIClient,ConfigManagementAPI_ListApplicationSpacesClient,ConfigManagementAPI_ListApplicationsClient,ConfigManagementAPI_ListTenantsClient,ConfigManagementAPI_ListApplicationAgentsClient
//go:generate mockgen -copyright_file ./doc/LICENSE -package ingest -destination ./test/ingest/v1beta2/ingest_api_mock.go github.com/indykite/indykite-sdk-go/gen/indykite/ingest/v1beta2 IngestAPIClient,IngestAPI_StreamRecordsClient
//go:generate mockgen -copyright_file ./doc/LICENSE -package authorization -destination ./test/authorization/v1beta1/authorization_api_mock.go github.com/indykite/indykite-sdk-go/gen/indykite/authorization/v1beta1 AuthorizationAPIClient
//go:generate mockgen -copyright_file ./doc/LICENSE -package knowledge -destination ./test/knowledge/v1beta1/identity_knowledge_api_mock.go github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta1 IdentityKnowledgeAPIClient
//go:generate mockgen -copyright_file ./doc/LICENSE -package knowledge -destination ./test/knowledge/v1beta2/identity_knowledge_api_mock.go github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta2 IdentityKnowledgeAPIClient
//go:generate mockgen -copyright_file ./doc/LICENSE -package ingest -destination ./test/ingest/v1beta3/ingest_api_mock.go github.com/indykite/indykite-sdk-go/gen/indykite/ingest/v1beta3 IngestAPIClient,IngestAPI_StreamRecordsClient

/*
Package indykite is the root of the packages used to access IndyKite Platform.
Expand Down
4 changes: 2 additions & 2 deletions examples/helpers/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ var deleteCmd = &cobra.Command{
Long: `Delete nodes in the IndyKite Knowledge API`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
responses, err := client.DeleteNodesWithTypeNode(context.Background(), "DigitalTwin")
responses, err := client.DeleteNodes(context.Background(), "DigitalTwin")
if err != nil {
fmt.Println("DigitalTwin: " + err.Error())
}
responses2, err := client.DeleteNodesWithTypeNode(context.Background(), "Resource")
responses2, err := client.DeleteNodes(context.Background(), "Resource")
if err != nil {
fmt.Println("Resource: " + err.Error())
}
Expand Down
54 changes: 54 additions & 0 deletions examples/knowledge/cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2023 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/spf13/cobra"

knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta2"
objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta2"
)

// listCmd represents the command for making a listNodes query with the Identity Knowledge API
var listCmd = &cobra.Command{
Use: "listNodes",
Short: "Make a list query to the IndyKite Identity Knowledge API",
Long: `Make a list query to the IndyKite Identity Knowledge API`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {

query := "MATCH (n:Resource)"
params := map[string]*objects.Value{}
returns := []*knowledgepb.Return{
{
Variable: "n",
},
}

resp, err := client.IdentityKnowledgeRead(context.Background(), query, params, returns)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
fmt.Println(jsonp.Format(resp))
},
}

func init() {
rootCmd.AddCommand(listCmd)
}
90 changes: 90 additions & 0 deletions examples/knowledge/cmd/property.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) 2023 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/spf13/cobra"

knowledgeobjects "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/objects/v1beta1"
knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta2"
objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta2"
)

// propertyCmd represents the command for making a listNodesByProperty query with the Identity Knowledge API
var propertyCmd = &cobra.Command{
Use: "property",
Short: "Make a list query to the IndyKite Identity Knowledge API",
Long: `Make a list query to the IndyKite Identity Knowledge API`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {

query := "MATCH (n:Resource)-[:HAS]->(p:Property) WHERE p.type=$type and p.value=$value"
params := map[string]*objects.Value{
"type": {
Type: &objects.Value_StringValue{StringValue: "last_name"},
},
"value": {
Type: &objects.Value_StringValue{StringValue: "mushu"},
},
}
returns := []*knowledgepb.Return{
{
Variable: "n",
},
}

resp, err := client.IdentityKnowledgeRead(context.Background(), query, params, returns)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
fmt.Println(jsonp.Format(resp))
},
}

// listPropertyCmd represents the command for making a listNodesByProperty query with the Identity Knowledge API
var listPropertyCmd = &cobra.Command{
Use: "listproperty",
Short: "Make a list query to the IndyKite Identity Knowledge API",
Long: `Make a list query to the IndyKite Identity Knowledge API`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {

resp, err := client.ListNodesByProperty(
context.Background(),
&knowledgeobjects.Property{
Type: "last_name",
Value: &objects.Value{
Type: &objects.Value_StringValue{
StringValue: "mushu",
},
},
},
true,
)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
fmt.Println(resp)
},
}

func init() {
rootCmd.AddCommand(propertyCmd)
rootCmd.AddCommand(listPropertyCmd)
}
20 changes: 14 additions & 6 deletions examples/knowledge/cmd/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (

"github.com/spf13/cobra"

knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta1"
knowledgepb "github.com/indykite/indykite-sdk-go/gen/indykite/knowledge/v1beta2"
objects "github.com/indykite/indykite-sdk-go/gen/indykite/objects/v1beta2"
)

// readCmd represents the command for making a read query with the Identity Knowledge API
Expand All @@ -32,15 +33,22 @@ var readCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {

path := "(n:Person)-[:OWNS]->(s:Store)"
conditions := "WHERE n.external_id = $external_id"
params := map[string]*knowledgepb.InputParam{
query := "MATCH (n:Person)-[r:CAN_SEE]->(a:Asset) WHERE n.external_id=$external_id AND n.type=$type"
params := map[string]*objects.Value{
"external_id": {
Value: &knowledgepb.InputParam_StringValue{StringValue: "1234"},
Type: &objects.Value_StringValue{StringValue: "1234"},
},
"type": {
Type: &objects.Value_StringValue{StringValue: "store"},
},
}
returns := []*knowledgepb.Return{
{
Variable: "n",
},
}

resp, err := client.Read(context.Background(), path, conditions, params)
resp, err := client.IdentityKnowledgeRead(context.Background(), query, params, returns)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion gen/indykite/auditsink/v1beta1/authorization.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5bf26e

Please sign in to comment.