Skip to content
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 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Documentation
* [Vault](docs/plugins/vault.md): Binary storage with secure option
* [Guard](docs/plugins/guard.md): Authentification
* [Security](docs/plugins/security.md): CORS
* [Search](docs/plugins/search.md): Search filters
* [Contributing](docs/contributing.md)
2 changes: 2 additions & 0 deletions commands/server/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/rande/gonode/core/config"
"github.com/rande/gonode/plugins/api"
"github.com/rande/gonode/plugins/guard"
"github.com/rande/gonode/plugins/search"
"github.com/rande/gonode/plugins/security"
"github.com/rande/gonode/plugins/setup"
"github.com/zenazn/goji/bind"
Expand Down Expand Up @@ -60,6 +61,7 @@ func (c *ServerCommand) Run(args []string) int {
// add plugins
setup.ConfigureServer(l, conf)
security.ConfigureServer(l, conf)
search.ConfigureServer(l, conf)
api.ConfigureServer(l, conf)
guard.ConfigureServer(l, conf)

Expand Down
8 changes: 8 additions & 0 deletions core/config/config_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

package config

type ServerSearch struct {
MaxResult uint64 `toml:"max_result"`
}

type ServerGuard struct {
Key string `toml:"key"`
Jwt struct {
Expand Down Expand Up @@ -56,12 +60,16 @@ type ServerConfig struct {
Bind string `toml:"bind"`
Guard *ServerGuard `toml:"guard"`
Security *ServerSecurity `toml:"security"`
Search *ServerSearch `toml:"search"`
}

func NewServerConfig() *ServerConfig {
return &ServerConfig{
Databases: make(map[string]*ServerDatabase),
Bind: ":2408",
Test: false,
Search: &ServerSearch{
MaxResult: 128,
},
}
}
10 changes: 10 additions & 0 deletions core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ key = "ZeSecretKey0oo"
allowed_methods = ["GET", "PUT", "POST"]
allowed_headers = ["Origin", "Accept", "Content-Type", "Authorization"]

[search]
max_result = 256

`, config)

// test general configuration
assert.Equal(t, config.Name, "GoNode - Codeship")
assert.Equal(t, config.Databases["master"].Type, "master")
assert.Equal(t, config.Databases["master"].DSN, "postgres://foo:bar@localhost:5434/test")
Expand All @@ -66,13 +70,19 @@ key = "ZeSecretKey0oo"
assert.Equal(t, config.Filesystem.Type, "") // not used for now
assert.Equal(t, config.Filesystem.Path, "/tmp/gnode")

// test guard
assert.Equal(t, config.Guard.Jwt.Login.Path, "/login")
assert.Equal(t, config.Guard.Jwt.Token.Path, `^\/nodes\/(.*)$`)

// test security
assert.False(t, config.Security.Cors.AllowCredentials)
assert.Equal(t, config.Security.Cors.AllowedHeaders, []string{"Origin", "Accept", "Content-Type", "Authorization"})
assert.Equal(t, config.Security.Cors.AllowedMethods, []string{"GET", "PUT", "POST"})

// test search
assert.Equal(t, uint64(256), config.Search.MaxResult)

// debug
config.Guard.Jwt.Login.Path = `^\/nodes\/(.*)$`

w := bytes.NewBufferString("")
Expand Down
7 changes: 4 additions & 3 deletions core/manager_pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (m *PgNodeManager) NewNode(t string) *Node {
func (m *PgNodeManager) FindBy(query sq.SelectBuilder, offset uint64, limit uint64) *list.List {
query = query.Limit(limit).Offset(offset)

rawSql, _, _ := query.ToSql()

rows, err := query.
RunWith(m.Db).
Query()
Expand All @@ -69,11 +71,10 @@ func (m *PgNodeManager) FindBy(query sq.SelectBuilder, offset uint64, limit uint

if err != nil {
if m.Logger != nil {
rawSql, _, _ := query.ToSql()
m.Logger.Printf("[PgNode] Error while runing the request %s, %s ", rawSql, err)
m.Logger.Printf("[PgNode] Error while runing the request: `%s`, %s ", rawSql, err)
}

return list
PanicOnError(err)
}

for rows.Next() {
Expand Down
57 changes: 57 additions & 0 deletions docs/plugins/search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Search
======

Introduction
------------

The ``search`` plugin provided a set of form to lookup node inside the datastore. The plugin is used to by the ``api``
plugin to filter results.


Configuration
-------------

```toml
[search]
max_result = 128


- ``max_result`` set the limit of returned results in one query.


Search filters
--------------

- `page`: current page
- `per_page`: number of result per page
- `order_by`: field to order
- `uuid`: array of uuid
- `type`: array of type
- `name`: name to filter
- `slug`: slug to filter
- `data.key`: array of value
- `meta.key`: array of value
- `status`: array of status
- `weight`: array of weight
- `revision`: revision number
- `enabled`: boolean (f/0/false or t/1/true)
- `deleted`: boolean (f/0/false or t/1/true)
- `current`: boolean (f/0/false or t/1/true)
- `updated_by`: array of uuid
- `created_by`: array of uuid
- `parent_uuid`: array of uuid
- `set_uuid`: array of uuid
- `source`: array of uuid

core.index node
---------------

This type can be used to configure an entry point with a pre-filtered index. As an example:

```yaml
type: core.index
name: Blog archives
data:
type: core.post

The data field accept all search filters.
34 changes: 0 additions & 34 deletions plugins/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,6 @@ const (
OPERATION_KO = "KO"
)

type SearchForm struct {
Page int64 `schema:"page"`
PerPage int64 `schema:"per_page"`
OrderBy []string `schema:"order_by"`
Uuid string `schema:"uuid"`
Type []string `schema:"type"`
Name string `schema:"name"`
Slug string `schema:"slug"`
Data map[string][]string `schema:"data"`
Meta map[string][]string `schema:"meta"`
Status []string `schema:"status"`
Weight []string `schema:"weight"`
Revision string `schema:"revision"`
// CreatedAt time.Time `schema:"created_at"`
// UpdatedAt time.Time `schema:"updated_at"`
Enabled string `schema:"enabled"`
Deleted string `schema:"deleted"`
Current string `schema:"current"`
// Parents []Reference `schema:"parents"`
UpdatedBy []string `schema:"updated_by"`
CreatedBy []string `schema:"created_by"`
ParentUuid []string `schema:"parent_uuid"`
SetUuid []string `schema:"set_uuid"`
Source []string `schema:"source"`
}

func GetSearchForm() *SearchForm {
return &SearchForm{
Data: make(map[string][]string),
Meta: make(map[string][]string),
OrderBy: []string{"updated_at,ASC"},
}
}

type ApiPager struct {
Elements []interface{} `json:"elements"`
Page uint64 `json:"page"`
Expand Down
108 changes: 0 additions & 108 deletions plugins/api/api_helper.go

This file was deleted.

Loading