Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data refs tests #290

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,984 changes: 583 additions & 1,401 deletions authorization/authorization_integration_test.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions examples/authorization/cmd/is_authorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ var withDigitalTwinCmd = &cobra.Command{

resources := []*authorizationpb.IsAuthorizedRequest_Resource{
{
ExternalId: "resourceID",
Type: "Type",
Actions: []string{"ACTION"},
ExternalId: "Truck1",
Type: "Truck",
Actions: []string{"SUBSCRIBES_TO"},
},
}
inputParams := map[string]*authorizationpb.InputParam{}
Expand Down Expand Up @@ -117,9 +117,9 @@ var withPropertyCmd = &cobra.Command{

resources := []*authorizationpb.IsAuthorizedRequest_Resource{
{
ExternalId: "resourceID",
Type: "Type",
Actions: []string{"ACTION"},
ExternalId: "Truck2",
Type: "Truck",
Actions: []string{"SUBSCRIBES_TO"},
},
}
inputParams := map[string]*authorizationpb.InputParam{}
Expand Down Expand Up @@ -163,9 +163,9 @@ var withExternalIDCmd = &cobra.Command{

resources := []*authorizationpb.IsAuthorizedRequest_Resource{
{
ExternalId: "resourceID",
Type: "Type",
Actions: []string{"ACTION"},
ExternalId: "Truck4",
Type: "Truck",
Actions: []string{"SUBSCRIBES_TO"},
},
}
inputParams := map[string]*authorizationpb.InputParam{}
Expand Down
6 changes: 2 additions & 4 deletions examples/authorization/cmd/what_authorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ var whatWithDigitalTwinCmd = &cobra.Command{
}

resourceTypes := []*authorizationpb.WhatAuthorizedRequest_ResourceType{
{Type: "TypeA"},
{Type: "TypeB", Actions: []string{"ACTION"}},
{Type: "Truck", Actions: []string{"SUBSCRIBES_TO"}},
}
inputParams := map[string]*authorizationpb.InputParam{}
var policyTags []string
Expand Down Expand Up @@ -153,8 +152,7 @@ var whatWithExternalIDCmd = &cobra.Command{
fmt.Scanln(&(externalID.ExternalId))

resourceTypes := []*authorizationpb.WhatAuthorizedRequest_ResourceType{
{Type: "TypeA", Actions: []string{"ACTION1", "ACTION2"}},
{Type: "TypeB", Actions: []string{"ACTION"}},
{Type: "Truck", Actions: []string{"SUBSCRIBES_TO"}},
}

inputParams := map[string]*authorizationpb.InputParam{}
Expand Down
6 changes: 3 additions & 3 deletions examples/authorization/cmd/who_authorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var whoAuthorizedCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
resources := []*authorizationpb.WhoAuthorizedRequest_Resource{
{
ExternalId: "resourceID",
Type: "Type",
Actions: []string{"ACTION"},
ExternalId: "Truck1",
Type: "Truck",
Actions: []string{"SUBSCRIBES_TO", "OWNS"},
},
}
inputParams := map[string]*authorizationpb.InputParam{}
Expand Down
110 changes: 110 additions & 0 deletions examples/config/cmd/authorization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (c) 2024 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"

"github.com/indykite/indykite-sdk-go/config"
configpb "github.com/indykite/indykite-sdk-go/gen/indykite/config/v1beta1"
)

var authorizationPolicyConfigCmd = &cobra.Command{
Use: "authorizationPolicy",
Short: "AuthorizationPolicy config",
}

var createAuthorizationPolicyConfigCmd = &cobra.Command{
Use: "create",
Short: "Create AuthorizationPolicy config",
Run: func(cmd *cobra.Command, args []string) {
jsonInput := `{"meta":{"policyVersion":"1.0-indykite"},"subject":{"type":"Person"},"actions":["SUBSCRIBES_TO"],"resource":{"type":"Truck"},"condition":{"cypher":"MATCH (subject:Person)-[:BELONGS_TO]->(:Organization)-[:OWNS]->(resource:Truck)-[HAS]->(p:Property:External {type: 'echo', value: '2024'}) "}}`
configuration := &configpb.AuthorizationPolicyConfig{
Policy: jsonInput,
Status: configpb.AuthorizationPolicyConfig_STATUS_ACTIVE,
Tags: []string{},
}
createReq, _ := config.NewCreate("like-real-config-node-name")
createReq.ForLocation("gid:AAAAAguDnAAAAAAAAAAAAAAA")
createReq.WithDisplayName("Like real ConfigNode Name")
createReq.WithAuthorizationPolicyConfig(configuration)

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

readReq, _ := config.NewRead(resp.Id)
readResp, err := client.ReadConfigNode(context.Background(), readReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
fmt.Println(jsonp.Format(readResp))
},
}

var updateAuthorizationPolicyConfigCmd = &cobra.Command{
Use: "update",
Short: "Update AuthorizationPolicy config",
Run: func(cmd *cobra.Command, args []string) {
jsonInput := `{"meta":{"policyVersion":"1.0-indykite"},"subject":{"type":"Person"},"actions":["SUBSCRIBES_TO"],"resource":{"type":"Asset"},"condition":{"cypher":"MATCH (subject:Person)-[:BELONGS_TO]->(:Organization)-[:OWNS]->(resource:Truck)-[HAS]->(Truck:Property:External {type: echo, value: '2024'}) "}}`
configuration := &configpb.AuthorizationPolicyConfig{
Policy: jsonInput,
Status: configpb.AuthorizationPolicyConfig_STATUS_ACTIVE,
Tags: []string{"TagA", "TagB"},
}
updateReq, _ := config.NewUpdate("gid:AAAAFo7ukfFQHkBjtiQQZiE2zb8")
updateReq.WithAuthorizationPolicyConfig(configuration)
updateReq.WithDescription("Desc1")

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

readReq, _ := config.NewRead(resp.Id)
readResp, err := client.ReadConfigNode(context.Background(), readReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
fmt.Println(jsonp.Format(readResp))
},
}

var deleteAuthorizationPolicyConfigCmd = &cobra.Command{
Use: "delete",
Short: "Delete AuthorizationPolicy configuration",
Run: func(cmd *cobra.Command, args []string) {
deleteReq, _ := config.NewDelete("gid:AAAAFvTeAqwrRUinglaK7B891aI")
resp, err := client.DeleteConfigNode(context.Background(), deleteReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
}
fmt.Println(jsonp.Format(resp))
},
}

func init() {
rootCmd.AddCommand(authorizationPolicyConfigCmd)
authorizationPolicyConfigCmd.AddCommand(createAuthorizationPolicyConfigCmd)
authorizationPolicyConfigCmd.AddCommand(updateAuthorizationPolicyConfigCmd)
authorizationPolicyConfigCmd.AddCommand(deleteAuthorizationPolicyConfigCmd)
}
33 changes: 14 additions & 19 deletions examples/config/cmd/external_data_resolver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ var createExternalDataResolverConfigCmd = &cobra.Command{
Short: "Create ExternalDataResolver config",
Run: func(cmd *cobra.Command, args []string) {
configuration := &configpb.ExternalDataResolverConfig{
Url: "https://example.com/source2",
Method: "GET",
Headers: map[string]*configpb.ExternalDataResolverConfig_Header{
"Authorization": {Values: []string{"Bearer edolkUTY"}},
"Content-Type": {Values: []string{"application/json"}},
},
Url: "http://super-octo-waffle.indykite.com/magic?data=2024",
Method: "GET",
Headers: map[string]*configpb.ExternalDataResolverConfig_Header{},
RequestType: configpb.ExternalDataResolverConfig_CONTENT_TYPE_JSON,
RequestPayload: []byte(`{"key": "value"}`),
RequestPayload: []byte(``),
ResponseType: configpb.ExternalDataResolverConfig_CONTENT_TYPE_JSON,
ResponseSelector: ".",
ResponseSelector: ".echo",
}
createReq, _ := config.NewCreate("like-real-config-node-name2")
createReq.ForLocation("gid:AAAAABBBBB_uiuiu144KNUI1245")
createReq.ForLocation("gid:AAAAAguAAAAAAAAAAAAAAAAAAAA")
createReq.WithDisplayName("Like real ConfigNode Name2")
createReq.WithExternalDataResolverConfig(configuration)

Expand All @@ -71,18 +68,16 @@ var updateExternalDataResolverConfigCmd = &cobra.Command{
Short: "Update ExternalDataResolver config",
Run: func(cmd *cobra.Command, args []string) {
configuration := &configpb.ExternalDataResolverConfig{
Url: "https://example.com/source",
Method: "GET",
Headers: map[string]*configpb.ExternalDataResolverConfig_Header{
"Authorization": {Values: []string{"Bearer edyUTY"}},
"Content-Type": {Values: []string{"application/json"}},
},
Url: "http://super-octo-waffle.indykite.com/magic?data=2024",
Method: "GET",
Headers: map[string]*configpb.ExternalDataResolverConfig_Header{},
RequestType: configpb.ExternalDataResolverConfig_CONTENT_TYPE_JSON,
RequestPayload: []byte(`{"key": "value"}`),
RequestPayload: []byte(``),
ResponseType: configpb.ExternalDataResolverConfig_CONTENT_TYPE_JSON,
ResponseSelector: ".",
ResponseSelector: ".echo",
}
updateReq, _ := config.NewUpdate("gid:id-of-existing-config")
updateReq, _ := config.NewUpdate("gid:AAAAIZISzhPyS0i-hT-OnuiGkKE")
updateReq.WithDescription("Desc2")
updateReq.WithExternalDataResolverConfig(configuration)

resp, err := client.UpdateConfigNode(context.Background(), updateReq)
Expand All @@ -104,7 +99,7 @@ var deleteExternalDataResolverConfigCmd = &cobra.Command{
Use: "delete",
Short: "Delete ExternalDataResolver configuration",
Run: func(cmd *cobra.Command, args []string) {
deleteReq, _ := config.NewDelete("gid:id-of-existing-config")
deleteReq, _ := config.NewDelete("gid:AAAAIWWRI5nLaEkjhFBa4v8Gi-4")
resp, err := client.DeleteConfigNode(context.Background(), deleteReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
Expand Down
11 changes: 3 additions & 8 deletions examples/ingest/cmd/batch_delete_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ var batchDeleteNodesCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

nodeMatch1 := &ingestpb.NodeMatch{
ExternalId: "0000",
Type: "Employee",
}

nodeMatch2 := &ingestpb.NodeMatch{
ExternalId: "0001",
Type: "Truck",
ExternalId: "tyUjk78Hnm",
Type: "Asset",
}

nodes := []*ingestpb.NodeMatch{
nodeMatch1, nodeMatch2,
nodeMatch1,
}
resp, err := client.BatchDeleteNodes(context.Background(), nodes)
if err != nil {
Expand Down
25 changes: 4 additions & 21 deletions examples/ingest/cmd/batch_upsert_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ var batchUpsertNodesCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

node1 := &knowledgeobjects.Node{
ExternalId: "741258",
ExternalId: "barnabebe",
Type: "Person",
IsIdentity: true,
Properties: []*knowledgeobjects.Property{
{
Type: "email",
Value: &objects.Value{
Type: &objects.Value_StringValue{
StringValue: "elias@yahoo.com",
StringValue: "banabebe@yahoo.com",
},
},
Metadata: &knowledgeobjects.Metadata{
Expand All @@ -69,24 +69,7 @@ var batchUpsertNodesCmd = &cobra.Command{
Type: "first_name",
Value: &objects.Value{
Type: &objects.Value_StringValue{
StringValue: "colias",
},
},
},
},
Tags: []string{"Sitea", "Siteb"},
}

node2 := &knowledgeobjects.Node{
ExternalId: "789456",
Type: "Car",
IsIdentity: false,
Properties: []*knowledgeobjects.Property{
{
Type: "plateNumber",
Value: &objects.Value{
Type: &objects.Value_StringValue{
StringValue: "NO8521",
StringValue: "barnabebe",
},
},
},
Expand All @@ -95,7 +78,7 @@ var batchUpsertNodesCmd = &cobra.Command{
}

nodes := []*knowledgeobjects.Node{
node1, node2,
node1,
}
resp, err := client.BatchUpsertNodes(context.Background(), nodes)
if err != nil {
Expand Down
55 changes: 5 additions & 50 deletions examples/ingest/cmd/batch_upsert_relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ import (
"log"

"github.com/spf13/cobra"
"google.golang.org/protobuf/types/known/timestamppb"

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

// batch upsert relationships represents the command for ingesting up to 250 relationships
Expand All @@ -37,60 +34,18 @@ var batchUpsertRelationshipsCmd = &cobra.Command{

relationship1 := &ingestpb.Relationship{
Source: &ingestpb.NodeMatch{
ExternalId: "741258",
ExternalId: "barnabebe",
Type: "Person",
},
Target: &ingestpb.NodeMatch{
ExternalId: "963258",
Type: "Car",
},
Type: "OWNS",
Properties: []*knowledgeobjects.Property{
{
Type: "linked",
Value: &objects.Value{
Type: &objects.Value_StringValue{
StringValue: "12345",
},
},
Metadata: &knowledgeobjects.Metadata{
AssuranceLevel: 1,
VerificationTime: timestamppb.Now(),
Source: "Myself",
CustomMetadata: map[string]*objects.Value{
"customdata": {
Type: &objects.Value_StringValue{StringValue: "SomeCustomData"},
},
},
},
},
},
}

relationship2 := &ingestpb.Relationship{
Source: &ingestpb.NodeMatch{
ExternalId: "0002",
Type: "Employee",
},
Target: &ingestpb.NodeMatch{
ExternalId: "0003",
Type: "Truck",
},
Type: "SERVICES",
Properties: []*knowledgeobjects.Property{
{
Type: "linked",
Value: &objects.Value{
Type: &objects.Value_StringValue{
StringValue: "678910",
},
},
},
ExternalId: "tRVeocDOOzNfTIN",
Type: "Organization",
},
Type: "BELONGS_TO",
}

relationships := []*ingestpb.Relationship{
relationship1, relationship2,
relationship1,
}
resp, err := client.BatchUpsertRelationships(context.Background(), relationships)
if err != nil {
Expand Down
Loading
Loading