Skip to content
Open
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
23 changes: 21 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,27 @@ jobs:
# run specialized role based tests
make test-authorization ARGS="--grip_config_file_path test/pebble-auth.yml"



pygripTest:
needs: build
name: PyGrip UnitTest
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Python Dependencies for Conformance
run: pip install requests numpy PyYAML pytest jsonpath-ng
- name: install gripql
run: |
cd gripql/python
python setup.py install --user
- name: install pygrip
run: |
python setup.py install --user
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python setup.py install --user produces:

...
Installed /Users/walsbr/.local/lib/python3.9/site-packages/pygrip-0.8.0-py3.9-macosx-12.4-arm64.egg
Processing dependencies for pygrip==0.8.0
Searching for pygrip==0.8.0
Reading https://pypi.org/simple/pygrip/
No local packages or working download links found for pygrip==0.8.0
error: Could not find suitable distribution for Requirement.parse('pygrip==0.8.0')```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 3.12, works now

Using /Users/walsbr/bmeg/grip/venv/lib/python3.12/site-packages
Finished processing dependencies for pygrip==0.8.0```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, it doesn't look like it installed?

$ pip freeze | grep pygrip
>>>  (no hits)
python -c "import pygrip"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/walsbr/bmeg/grip/pygrip/__init__.py", line 9, in <module>
    from gripql.query import QueryBuilder
ModuleNotFoundError: No module named 'gripql.query'```

$ pytest test/pygrip_test/test_pygrip.py
========================================================================================== test session starts ==========================================================================================
platform darwin -- Python 3.12.1, pytest-8.1.1, pluggy-1.4.0
rootdir: /Users/walsbr/bmeg/grip
collected 0 items / 1 error

================================================================================================ ERRORS =================================================================================================
___________________________________________________________________________ ERROR collecting test/pygrip_test/test_pygrip.py ____________________________________________________________________________
ImportError while importing test module '/Users/walsbr/bmeg/grip/test/pygrip_test/test_pygrip.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.12.1/lib/python3.12/importlib/init.py:90: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test/pygrip_test/test_pygrip.py:2: in
import pygrip
E ModuleNotFoundError: No module named 'pygrip'
======================================================================================== short test summary info ========================================================================================
ERROR test/pygrip_test/test_pygrip.py```

- name: unit tests
run: |
cd test
python -m unittest discover -s ./pygrip_test

gridsTest:
needs: build
name: GRIDs Conformance
Expand Down
6 changes: 4 additions & 2 deletions accounts/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/base64"
"fmt"
"strings"

"github.com/bmeg/grip/log"
)

// BasicCredential describes a username and password for use with Funnel's basic auth.
Expand All @@ -18,7 +20,7 @@ func (ba BasicAuth) Validate(md MetaData) (string, error) {
var auth []string
var ok bool

fmt.Printf("Running BasicAuth: %#v\n", md)
log.Infof("Running BasicAuth: %#v\n", md)

if auth, ok = md["Authorization"]; !ok {
if auth, ok = md["authorization"]; !ok {
Expand All @@ -28,7 +30,7 @@ func (ba BasicAuth) Validate(md MetaData) (string, error) {

if len(auth) > 0 {
user, password, ok := parseBasicAuth(auth[0])
fmt.Printf("User: %s Password: %s OK: %s\n", user, password, ok)
log.Debugf("User: %s Password: %s OK: %#v\n", user, password, ok)
for _, c := range ba {
if c.User == user && c.Password == password {
return user, nil
Expand Down
9 changes: 5 additions & 4 deletions accounts/casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package accounts
import (
"fmt"

"github.com/bmeg/grip/log"
"github.com/casbin/casbin/v2"
)

Expand All @@ -17,19 +18,19 @@ func (ce *CasbinAccess) init() {
if e, err := casbin.NewEnforcer(ce.Model, ce.Policy); err == nil {
ce.encforcer = e
} else {
fmt.Printf("Casbin Error: %s", err)
log.Errorf("Casbin Error: %s", err)
}
}
}

func (ce *CasbinAccess) Enforce(user string, graph string, operation Operation) error {
ce.init()
fmt.Printf("Casbin request '%s' '%s' '%s'\n", user, graph, operation)
log.Infof("Casbin request '%s' '%s' '%s'\n", user, graph, operation)
if res, err := ce.encforcer.Enforce(user, graph, string(operation)); res {
return nil
} else if err != nil {
fmt.Printf("casbin error: %s\n", err)
log.Errorf("casbin error: %s\n", err)
}
fmt.Printf("Not allowed: '%s' '%s' '%s'\n", user, graph, operation)
log.Errorf("Not allowed: '%s' '%s' '%s'\n", user, graph, operation)
return fmt.Errorf("action restricted")
}
10 changes: 5 additions & 5 deletions accounts/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (c *Config) StreamInterceptor() grpc.StreamServerInterceptor {
// using a password stored in the config.
func unaryAuthInterceptor(auth Authenticate, access Access) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
//fmt.Printf("AuthInt: %#v\n", ctx)
//log.Infof("AuthInt: %#v\n", ctx)
md, _ := metadata.FromIncomingContext(ctx)
//fmt.Printf("Metadata: %#v\n", md)
//log.Infof("Metadata: %#v\n", md)
//omd, _ := metadata.FromOutgoingContext(ctx)
//fmt.Printf("Raw: %#v\n", omd)
//log.Infof("Raw: %#v\n", omd)

metaData := MetaData{}
for i := range md {
Expand Down Expand Up @@ -89,10 +89,10 @@ func unaryAuthInterceptor(auth Authenticate, access Access) grpc.UnaryServerInte
// using a password stored in the config.
func streamAuthInterceptor(auth Authenticate, access Access) grpc.StreamServerInterceptor {
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
//fmt.Printf("Streaming query: %#v\n", info)
//log.Infof("Streaming query: %#v\n", info)
md, _ := metadata.FromIncomingContext(ss.Context())

//fmt.Printf("Metadata: %#v\n", md)
//log.Infof("Metadata: %#v\n", md)
metaData := MetaData{}
for i := range md {
metaData[i] = md[i]
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/bmeg/grip/cmd/delete"
"github.com/bmeg/grip/cmd/drop"
"github.com/bmeg/grip/cmd/dump"
"github.com/bmeg/grip/cmd/embedded"
"github.com/bmeg/grip/cmd/erclient"
"github.com/bmeg/grip/cmd/info"
"github.com/bmeg/grip/cmd/job"
Expand Down Expand Up @@ -73,6 +74,7 @@ func init() {
RootCmd.AddCommand(version.Cmd)
RootCmd.AddCommand(kvload.Cmd)
RootCmd.AddCommand(delete.Cmd)
RootCmd.AddCommand(embedded.Cmd)

}

Expand Down
8 changes: 0 additions & 8 deletions engine/core/util.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package core

import (
"github.com/kr/pretty"
)

func debug(i ...interface{}) {
pretty.Println(i...)
}

func dedupStringSlice(s []string) []string {
seen := make(map[string]struct{}, len(s))
j := 0
Expand Down
5 changes: 3 additions & 2 deletions grids/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/bmeg/benchtop/bsontable"
"github.com/bmeg/grip/gripql"
"github.com/bmeg/grip/log"
"github.com/bmeg/grip/timestamp"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func (kgraph *GDB) AddGraph(graph string) error {
}
func newGraph(baseDir, name string) (*Graph, error) {
dbPath := filepath.Join(baseDir, name)
fmt.Printf("Creating new GRIDS graph %s\n", name)
log.Infof("Creating new GRIDS graph %s\n", name)

// Create directory if it doesn't exist
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
Expand Down Expand Up @@ -78,7 +79,7 @@ func newGraph(baseDir, name string) (*Graph, error) {

func getGraph(baseDir, name string) (*Graph, error) {
dbPath := filepath.Join(baseDir, name)
fmt.Printf("fetching GRIDS graph %s\n", name)
log.Infof("fetching GRIDS graph %s\n", name)

versionPath := filepath.Join(dbPath, "VERSION")
file, err := os.Open(versionPath)
Expand Down
8 changes: 4 additions & 4 deletions gripper/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package gripper
import (
"context"
"fmt"
"log"
"net"

"github.com/bmeg/grip/log"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/structpb"
)
Expand Down Expand Up @@ -36,13 +36,13 @@ func NewSimpleTableServer(dr map[string]Driver) *SimpleTableServicer {
func StartServer(port int, serv GRIPSourceServer) {
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
log.Errorf("failed to listen: %v", err)
}
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)

RegisterGRIPSourceServer(grpcServer, serv)
fmt.Printf("Starting: %d\n", port)
log.Infof("Starting: %d\n", port)
grpcServer.Serve(lis)
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (st *SimpleTableServicer) GetRowsByID(srv GRIPSource_GetRowsByIDServer) err
if err != nil {
break
}
log.Printf("Request: %s %s", err, req)
log.Debugf("Request: %s %s", err, req)
if dr, ok := st.drivers[req.Collection]; ok {
if row, err := dr.FetchRow(req.Id); err == nil {
data, _ := structpb.NewStruct(row.Value)
Expand Down
4 changes: 2 additions & 2 deletions gripql/marshal_flattened.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package gripql

import (
"encoding/json"
"fmt"

"github.com/bmeg/grip/log"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -80,7 +80,7 @@ func (mflat *MarshalFlatten) Unmarshal(data []byte, v interface{}) error {
}
s, err := structpb.NewStruct(data)
if err != nil {
fmt.Printf("NewStruct error: %s", err)
log.Errorf("NewStruct error: %s", err)
}
if err == nil {
y.Data = s
Expand Down
2 changes: 1 addition & 1 deletion gripql/python/gripql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
count
]

__version__ = "0.7.1"
__version__ = "0.8.0"
6 changes: 6 additions & 0 deletions gripql/python/gripql/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ def query(self):
"""
return Query(self.base_url, self.graph, self.user, self.password, self.token, self.credential_file)

def V(self, *args):
"""
Create a vertex query handle.
"""
return Query(self.base_url, self.graph, self.user, self.password, self.token, self.credential_file).V(*args)

def resume(self, job_id):
"""
Create a query handle.
Expand Down
24 changes: 17 additions & 7 deletions gripql/python/gripql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ def _wrap_dict_value(value):
return _wrap_value(value, dict)


class Query(BaseConnection):
def __init__(self, url, graph, user=None, password=None, token=None, credential_file=None, resume=None):
super(Query, self).__init__(url, user, password, token, credential_file)
self.url = self.base_url + "/v1/graph/" + graph + "/query"
self.graph = graph
class QueryBuilder:
def __init__(self):
self.query = []
self.resume = resume

def __append(self, part):
q = self.__class__(self.base_url, self.graph, self.user, self.password, self.token, self.credential_file, self.resume)
q = self._builder()
q.query = self.query[:]
q.query.append(part)
return q
Expand Down Expand Up @@ -360,6 +356,20 @@ def to_dict(self):
"""
return {"query": self.query}



class Query(BaseConnection, QueryBuilder):
def __init__(self, url, graph, user=None, password=None, token=None, credential_file=None, resume=None):
super(Query, self).__init__(url, user, password, token, credential_file)
super(QueryBuilder, self).__init__()
self.url = self.base_url + "/v1/graph/" + graph + "/query"
self.graph = graph
self.query = []
self.resume = resume

def _builder(self):
return self.__class__(self.base_url, self.graph, self.user, self.password, self.token, self.credential_file, self.resume)

def __iter__(self):
return self.__stream()

Expand Down
Loading