Skip to content

Commit c335302

Browse files
committed
Merge branch 'dev' of github.com:appbaseio/arc into feat/size_limit
2 parents 78721a3 + 261727d commit c335302

15 files changed

Lines changed: 220 additions & 12 deletions

File tree

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
- make clean && make
3030

3131
before_deploy:
32-
- mkdir -p pkg/mod/github.com/appbaseio/
33-
- sudo mv $GOPATH/pkg/mod/github.com/appbaseio/* pkg/mod/github.com/appbaseio/
34-
- zip -r arc-linux.zip build pkg sample
32+
- mkdir -p go/pkg/mod/github.com/appbaseio/
33+
- sudo mv $GOPATH/pkg/mod/github.com/appbaseio/* go/pkg/mod/github.com/appbaseio/
34+
- zip -r arc-linux.zip build go sample
3535
- export TRAVIS_TAG="preview"
3636

3737
deploy:
@@ -40,5 +40,6 @@ jobs:
4040
skip_cleanup: true
4141
file: arc-linux.zip
4242
draft: true
43+
overwrite: true
4344
on:
4445
all_branches: true

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func main() {
192192
// ES v7 and v6 clients
193193
util.NewClient()
194194
// map of specific plugins
195-
sequencedPlugins := []string{"rules.so", "functions.so", "analytics.so"}
195+
sequencedPlugins := []string{"searchsettings.so", "rules.so", "functions.so", "analytics.so"}
196196
sequencedPluginsByPath := make(map[string]string)
197197

198198
var elasticSearchPath, reactiveSearchPath string

middleware/classify/indices.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package classify
22

33
import (
44
"net/http"
5+
"regexp"
6+
"strings"
57

68
"github.com/appbaseio/arc/middleware"
79
"github.com/appbaseio/arc/model/index"
@@ -16,7 +18,50 @@ func Indices() middleware.Middleware {
1618
func indices(h http.HandlerFunc) http.HandlerFunc {
1719
return func(w http.ResponseWriter, req *http.Request) {
1820
indices := util.IndicesFromRequest(req)
21+
currentCache := GetIndexAliasCache()
1922

23+
for _, index := range indices {
24+
// '*' in case of all indices put alias in context
25+
if index == "*" {
26+
for cachedItem := range currentCache {
27+
alias := GetIndexAlias(cachedItem)
28+
if alias != "" {
29+
indices = append(indices, alias)
30+
}
31+
}
32+
break
33+
} else if strings.Contains(index, "*") {
34+
// in case of regex check if string contains '*' in naming pattern, if contains and doesn't have '.*' and replace '*' with '.*' because golang regex can match in that pattern. Next match regex patters with existing index names in cache and add those alias to context.
35+
regex := index
36+
37+
if !strings.Contains(index, ".*") {
38+
regex = strings.Replace(regex, "*", ".*", -1)
39+
}
40+
r, _ := regexp.Compile(regex)
41+
cachedIndices := []string{}
42+
43+
for cachedItem := range currentCache {
44+
cachedIndices = append(cachedIndices, cachedItem)
45+
}
46+
for _, val := range cachedIndices {
47+
if r.MatchString(val) {
48+
alias := GetIndexAlias(val)
49+
if alias != "" {
50+
indices = append(indices, alias)
51+
}
52+
break
53+
}
54+
}
55+
56+
} else {
57+
// get alias for index and put in context
58+
alias := GetIndexAlias(index)
59+
if alias != "" {
60+
indices = append(indices, alias)
61+
}
62+
break
63+
}
64+
}
2065
ctx := index.NewContext(req.Context(), indices)
2166
req = req.WithContext(ctx)
2267

middleware/classify/util.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package classify
2+
3+
// IndexAliasCache cache to store index alias map
4+
var IndexAliasCache = make(map[string]string)
5+
6+
// GetIndexAliasCache get whole cache
7+
func GetIndexAliasCache() map[string]string {
8+
return IndexAliasCache
9+
}
10+
11+
// GetIndexAlias get alias for specific index
12+
func GetIndexAlias(index string) string {
13+
alias, ok := IndexAliasCache[index]
14+
15+
if !ok {
16+
return ""
17+
}
18+
return alias
19+
}
20+
21+
// SetIndexAlias set alias for specific index
22+
func SetIndexAlias(index, alias string) {
23+
IndexAliasCache[index] = alias
24+
}

model/category/category.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
Auth
3636
Functions
3737
ReactiveSearch
38+
SearchSettings
3839
)
3940

4041
// String is an implementation of Stringer interface that returns the string representation of category.Categories.
@@ -56,6 +57,7 @@ func (c Category) String() string {
5657
"auth",
5758
"functions",
5859
"reactivesearch",
60+
"searchsettings",
5961
}[c]
6062
}
6163

@@ -99,6 +101,8 @@ func (c *Category) UnmarshalJSON(bytes []byte) error {
99101
*c = Functions
100102
case ReactiveSearch.String():
101103
*c = ReactiveSearch
104+
case SearchSettings.String():
105+
*c = SearchSettings
102106
default:
103107
return fmt.Errorf("invalid category encountered: %v", category)
104108
}
@@ -141,6 +145,8 @@ func (c Category) MarshalJSON() ([]byte, error) {
141145
category = Functions.String()
142146
case ReactiveSearch:
143147
category = ReactiveSearch.String()
148+
case SearchSettings:
149+
category = SearchSettings.String()
144150
default:
145151
return nil, fmt.Errorf("invalid category encountered: %v" + c.String())
146152
}

model/permission/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var (
2929
category.Auth,
3030
category.Functions,
3131
category.ReactiveSearch,
32+
category.SearchSettings,
3233
}
3334

3435
defaultOps = []op.Operation{
@@ -59,6 +60,7 @@ var (
5960
AuthLimit: 10,
6061
FunctionsLimit: 10,
6162
ReactiveSearchLimit: 10,
63+
SearchSettingsLimit: 10,
6264
}
6365

6466
defaultAdminLimits = Limits{
@@ -79,5 +81,6 @@ var (
7981
AuthLimit: 30,
8082
FunctionsLimit: 30,
8183
ReactiveSearchLimit: 30,
84+
SearchSettingsLimit: 30,
8285
}
8386
)

model/permission/permission.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Limits struct {
7171
AuthLimit int64 `json:"auth_limit"`
7272
FunctionsLimit int64 `json:"functions_limit"`
7373
ReactiveSearchLimit int64 `json:"reactivesearch_limit"`
74+
SearchSettingsLimit int64 `json:"searchsettings_limit"`
7475
}
7576

7677
// Options is a function type used to define a permission's properties.
@@ -471,6 +472,8 @@ func (p *Permission) GetLimitFor(c category.Category) (int64, error) {
471472
return p.Limits.FunctionsLimit, nil
472473
case category.ReactiveSearch:
473474
return p.Limits.ReactiveSearchLimit, nil
475+
case category.SearchSettings:
476+
return p.Limits.SearchSettingsLimit, nil
474477
default:
475478
return -1, fmt.Errorf(`we do not rate limit "%s" category`, c)
476479
}
@@ -591,6 +594,10 @@ func (p *Permission) GetPatch(rolePatched bool) (map[string]interface{}, error)
591594
limits["reactivesearch_limit"] = p.Limits.ReactiveSearchLimit
592595
}
593596

597+
if p.Limits.SearchSettingsLimit != 0 {
598+
limits["searchsettings_limit"] = p.Limits.SearchSettingsLimit
599+
}
600+
594601
patch["limits"] = limits
595602
}
596603
if p.Description != "" {

model/user/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
category.Suggestions,
2929
category.Functions,
3030
category.ReactiveSearch,
31+
category.SearchSettings,
3132
category.Auth,
3233
}
3334

plugins/auth/e2e_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var adminCategories = []category.Category{
2828
category.Auth,
2929
category.Functions,
3030
category.ReactiveSearch,
31+
category.SearchSettings,
3132
}
3233

3334
var adminOps = []op.Operation{
@@ -54,6 +55,7 @@ var defaultAdminLimits = permission.Limits{
5455
AuthLimit: 30,
5556
FunctionsLimit: 30,
5657
ReactiveSearchLimit: 30,
58+
SearchSettingsLimit: 30,
5759
}
5860

5961
var createPermissionResponse = map[string]interface{}{

plugins/permissions/e2e_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var adminCategories = []category.Category{
2828
category.Suggestions,
2929
category.Functions,
3030
category.ReactiveSearch,
31+
category.SearchSettings,
3132
category.Auth,
3233
}
3334

@@ -55,6 +56,7 @@ var defaultAdminLimits = permission.Limits{
5556
AuthLimit: 30,
5657
FunctionsLimit: 30,
5758
ReactiveSearchLimit: 30,
59+
SearchSettingsLimit: 30,
5860
}
5961

6062
var createPermissionResponse = map[string]interface{}{

0 commit comments

Comments
 (0)