Skip to content

Commit

Permalink
feat: implement ikg query api
Browse files Browse the repository at this point in the history
  • Loading branch information
maaland committed Sep 20, 2023
1 parent 6c2d69e commit 4f9dbb5
Show file tree
Hide file tree
Showing 28 changed files with 3,291 additions and 183 deletions.
1 change: 1 addition & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ jobs:
identity/doc.go
ingest/doc.go
authorization/doc.go
knowledge/doc.go
token: ${{ secrets.INDYKITE_PAT }}
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//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

/*
Package indykite is the root of the packages used to access IndyKite Platform.
Expand Down
2 changes: 1 addition & 1 deletion errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewWithCause(code codes.Code, err error, msg string, args ...interface{}) e
}
}
return &ClientError{
code: codes.InvalidArgument,
code: code,
msg: msg,
cause: err,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ingest/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ingest Client

## Enviroment
## Environment

`INDYKITE_APPLICATION_CREDENTIALS_FILE`

Expand Down
9 changes: 9 additions & 0 deletions examples/knowledge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Identity Knowledge API Client

## Environment

`INDYKITE_APPLICATION_CREDENTIALS_FILE`

Populate the environment variable above with the path to your application credential `.json` file.
This will be used to authenticate with the IndyKite platform and populate the ingested data into the correct
application space and tenant.
23 changes: 23 additions & 0 deletions examples/knowledge/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 main

import (
"github.com/indykite/indykite-sdk-go/examples/knowledge/cmd"
)

func main() {
cmd.Execute()
}
53 changes: 53 additions & 0 deletions examples/knowledge/cmd/read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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/v1beta1"
)

// readCmd represents the command for making a read query with the Identity Knowledge API
var readCmd = &cobra.Command{
Use: "read",
Short: "Make a read query to the IndyKite Identity Knowledge API",
Long: `Make a read query to the IndyKite Identity Knowledge API`,
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{
"external_id": {
Value: &knowledgepb.InputParam_StringValue{StringValue: "1234"},
},
}

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

func init() {
rootCmd.AddCommand(readCmd)
}
109 changes: 109 additions & 0 deletions examples/knowledge/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// 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 implements the CLI commands.
package cmd

import (
"context"
"fmt"
"os"

"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/protobuf/encoding/protojson"

"github.com/indykite/indykite-sdk-go/grpc"
apicfg "github.com/indykite/indykite-sdk-go/grpc/config"
"github.com/indykite/indykite-sdk-go/knowledge"
)

var (
cfgFile string
client *knowledge.Client
jsonp = protojson.MarshalOptions{
Multiline: true,
EmitUnpopulated: true,
}
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "cmd",
Short: "Identity Knowledge API examples",
Long: `Examples of using the Identity Knowledge API to interact with data in the IndyKite Identity Knowledge Graph`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer func() {
if client != nil {
_ = client.Close()
}
}()
}

func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile,
"config", "", "config file (default is $HOME/.indykite.yaml)")
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Search config in home directory with name ".indykite" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".indykite")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
err := viper.ReadInConfig()
if err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())

}

client, err = knowledge.NewClient(context.Background(),
grpc.WithCredentialsLoader(apicfg.DefaultEnvironmentLoader),
grpc.WithRetryOptions(retry.Disable()),
)
if err != nil {
er(fmt.Sprintf("failed to create IndyKite Identity Knowledge Client: %v", err))
}
}

func er(msg interface{}) {
_, _ = fmt.Fprintf(os.Stderr, "Error: %v\n", msg)
os.Exit(1)
}
Loading

0 comments on commit 4f9dbb5

Please sign in to comment.