Skip to content

Commit

Permalink
Get all adapters on the same config proto plan.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer authored and geeknoid committed Jan 11, 2017
1 parent b74ca35 commit 29f81e8
Showing 26 changed files with 142 additions and 231 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -26,3 +26,6 @@ lint: build

fmt:
@bin/fmt.sh

coverage:
@bin/codecov.sh
1 change: 0 additions & 1 deletion adapter/denyChecker/.gitignore

This file was deleted.

28 changes: 1 addition & 27 deletions adapter/denyChecker/BUILD
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ go_library(
"aspect.go",
],
deps = [
":config_proto",
"//adapter/denyChecker/config:go_default_library",
"//pkg/aspect:go_default_library",
"//pkg/aspect/denyChecker:go_default_library",
"//pkg/registry:go_default_library",
@@ -26,29 +26,3 @@ go_test(
library = ":go_default_library",
deps = ["//pkg/adaptertesting:go_default_library"],
)

load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library")

go_proto_library(
name = "config_proto",
importmap = {
"google/rpc/status.proto": "google.golang.org/genproto/googleapis/rpc/status",
},
imports = [
"external/com_github_google_protobuf/src",
"external/com_github_googleapis_googleapis",
],
inputs = [
"@com_github_google_protobuf//:well_known_protos",
"@com_github_googleapis_googleapis//:status_proto",
],
protos = [
"config.proto",
],
verbose = 0,
visibility = ["//visibility:public"],
deps = [
"@com_github_google_go_genproto//googleapis/rpc/status:go_default_library",
"@com_github_googleapis_googleapis//:go_status_proto",
],
)
2 changes: 1 addition & 1 deletion adapter/denyChecker/adapter.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import (

"google.golang.org/genproto/googleapis/rpc/status"

pb "istio.io/mixer/adapter/denyChecker/config_proto"
pb "istio.io/mixer/adapter/denyChecker/config"
)

// Register records the existence of this adapter
2 changes: 1 addition & 1 deletion adapter/denyChecker/adapter_test.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import (
"google.golang.org/genproto/googleapis/rpc/code"
"google.golang.org/genproto/googleapis/rpc/status"

pb "istio.io/mixer/adapter/denyChecker/config_proto"
pb "istio.io/mixer/adapter/denyChecker/config"
"istio.io/mixer/pkg/adaptertesting"
)

2 changes: 1 addition & 1 deletion adapter/denyChecker/aspect.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import (

"istio.io/mixer/pkg/aspect/denyChecker"

pb "istio.io/mixer/adapter/denyChecker/config_proto"
pb "istio.io/mixer/adapter/denyChecker/config"
)

type aspectState struct {
25 changes: 25 additions & 0 deletions adapter/denyChecker/config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library")

go_proto_library(
name = "go_default_library",
importmap = {
"google/rpc/status.proto": "google.golang.org/genproto/googleapis/rpc/status",
},
imports = [
"external/com_github_google_protobuf/src",
"external/com_github_googleapis_googleapis",
],
inputs = [
"@com_github_google_protobuf//:well_known_protos",
"@com_github_googleapis_googleapis//:status_proto",
],
protos = [
"config.proto",
],
verbose = 0,
visibility = ["//adapter/denyChecker:__pkg__"],
deps = [
"@com_github_google_go_genproto//googleapis/rpc/status:go_default_library",
"@com_github_googleapis_googleapis//:go_status_proto",
],
)
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

syntax = "proto3";

package denyChecker;
package adapter.denyChecker.config;

import "google/rpc/status.proto";

1 change: 0 additions & 1 deletion adapter/genericListChecker/.gitignore

This file was deleted.

13 changes: 1 addition & 12 deletions adapter/genericListChecker/BUILD
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ go_library(
srcs = [
"adapter.go",
"aspect.go",
"cfg.pb.go",
],
deps = [
"//adapter/genericListChecker/config:go_default_library",
"//pkg/aspect:go_default_library",
"//pkg/aspect/listChecker:go_default_library",
"//pkg/registry:go_default_library",
@@ -24,14 +24,3 @@ go_test(
library = ":go_default_library",
deps = ["//pkg/adaptertesting:go_default_library"],
)

load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library")

go_proto_library(
name = "genericListChecker",
protos = [
"cfg.proto",
],
verbose = 0,
visibility = ["//visibility:public"],
)
5 changes: 3 additions & 2 deletions adapter/genericListChecker/adapter.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ package genericListChecker
import (
"github.com/golang/protobuf/proto"

pb "istio.io/mixer/adapter/genericListChecker/config"
"istio.io/mixer/pkg/aspect"
"istio.io/mixer/pkg/aspect/listChecker"
"istio.io/mixer/pkg/registry"
@@ -35,8 +36,8 @@ func (a *adapterState) Name() string
func (a *adapterState) Description() string { return "Checks whether a string is present in a list." }
func (a *adapterState) Close() error { return nil }
func (a *adapterState) ValidateConfig(cfg proto.Message) (ce *aspect.ConfigErrors) { return }
func (a *adapterState) DefaultConfig() proto.Message { return &Config{} }
func (a *adapterState) DefaultConfig() proto.Message { return &pb.Config{} }

func (a *adapterState) NewAspect(env aspect.Env, cfg proto.Message) (listChecker.Aspect, error) {
return newAspect(cfg.(*Config))
return newAspect(cfg.(*pb.Config))
}
7 changes: 4 additions & 3 deletions adapter/genericListChecker/adapter_test.go
Original file line number Diff line number Diff line change
@@ -17,25 +17,26 @@ package genericListChecker
import (
"testing"

pb "istio.io/mixer/adapter/genericListChecker/config"
"istio.io/mixer/pkg/adaptertesting"
)

type testCase struct {
ac Config
ac pb.Config
matchValues []string
unmatchValues []string
}

func TestAll(t *testing.T) {
cases := []testCase{
{
Config{ListEntries: []string{"One", "Two", "Three"}},
pb.Config{ListEntries: []string{"One", "Two", "Three"}},
[]string{"One", "Two", "Three"},
[]string{"O", "OneOne", "ne", "ree"},
},

{
Config{},
pb.Config{},
[]string{},
[]string{"One", "Two", "Three"},
},
3 changes: 2 additions & 1 deletion adapter/genericListChecker/aspect.go
Original file line number Diff line number Diff line change
@@ -15,14 +15,15 @@
package genericListChecker

import (
pb "istio.io/mixer/adapter/genericListChecker/config"
"istio.io/mixer/pkg/aspect/listChecker"
)

type aspectState struct {
entries map[string]string
}

func newAspect(c *Config) (listChecker.Aspect, error) {
func newAspect(c *pb.Config) (listChecker.Aspect, error) {
entries := make(map[string]string, len(c.ListEntries))
for _, entry := range c.ListEntries {
entries[entry] = entry
63 changes: 0 additions & 63 deletions adapter/genericListChecker/cfg.pb.go

This file was deleted.

12 changes: 12 additions & 0 deletions adapter/genericListChecker/config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package(default_visibility = ["//visibility:public"])

load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library")

go_proto_library(
name = "go_default_library",
protos = [
"config.proto",
],
verbose = 0,
visibility = ["//adapter/genericListChecker:__pkg__"],
)
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

syntax = "proto3";

package genericListChecker;
package adapter.genericListChecker.config;

message Config {
// The set of entries in the list to check against
1 change: 0 additions & 1 deletion adapter/ipListChecker/.gitignore

This file was deleted.

13 changes: 1 addition & 12 deletions adapter/ipListChecker/BUILD
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ go_library(
srcs = [
"adapter.go",
"aspect.go",
"cfg.pb.go",
],
deps = [
"//adapter/ipListChecker/config:go_default_library",
"//pkg/aspect:go_default_library",
"//pkg/aspect/listChecker:go_default_library",
"//pkg/registry:go_default_library",
@@ -26,14 +26,3 @@ go_test(
library = ":go_default_library",
deps = ["//pkg/adaptertesting:go_default_library"],
)

load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library")

go_proto_library(
name = "ipListChecker",
protos = [
"cfg.proto",
],
verbose = 0,
visibility = ["//visibility:public"],
)
7 changes: 4 additions & 3 deletions adapter/ipListChecker/adapter.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import (

"github.com/golang/protobuf/proto"

pb "istio.io/mixer/adapter/ipListChecker/config"
"istio.io/mixer/pkg/aspect"
"istio.io/mixer/pkg/aspect/listChecker"
"istio.io/mixer/pkg/registry"
@@ -42,7 +43,7 @@ func (a *adapterState) Description() string {
func (a *adapterState) Close() error { return nil }

func (a *adapterState) ValidateConfig(cfg proto.Message) (ce *aspect.ConfigErrors) {
c := cfg.(*Config)
c := cfg.(*pb.Config)

u, err := url.Parse(c.ProviderUrl)
if err != nil {
@@ -57,13 +58,13 @@ func (a *adapterState) ValidateConfig(cfg proto.Message) (ce *aspect.ConfigError
}

func (a *adapterState) DefaultConfig() proto.Message {
return &Config{
return &pb.Config{
ProviderUrl: "http://localhost",
RefreshInterval: 60,
Ttl: 120,
}
}

func (a *adapterState) NewAspect(env aspect.Env, cfg proto.Message) (listChecker.Aspect, error) {
return newAspect(env, cfg.(*Config))
return newAspect(env, cfg.(*pb.Config))
}
Loading

0 comments on commit 29f81e8

Please sign in to comment.