-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
3,291 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,5 @@ jobs: | |
identity/doc.go | ||
ingest/doc.go | ||
authorization/doc.go | ||
knowledge/doc.go | ||
token: ${{ secrets.INDYKITE_PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Ingest Client | ||
|
||
## Enviroment | ||
## Environment | ||
|
||
`INDYKITE_APPLICATION_CREDENTIALS_FILE` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.