Beispiel #1
0
func NewServer(dataplaneUri string, sqlUrl string) (*PolicyServer, error) {
	log.Info.Println("Policy module starting")
	rtr := mux.NewRouter()

	g := &PolicyServer{
		HandleFunc: rtr,
		Dataplane:  NewDataplane(),
	}

	err := g.Dataplane.Init(dataplaneUri)

	if err != nil {
		return nil, err
	}

	g.Db, err = database.Init(sqlUrl)
	rtr.Methods("GET").Path("/info").HandlerFunc(makeHandler(g.handleInfoGet))

	pol := rtr.PathPrefix("/policies").Subrouter()
	pol.Methods("POST").Path("/").HandlerFunc(makeHandler(g.handlePolicyPost))
	pol.Methods("GET").Path("/").HandlerFunc(makeHandler(g.handlePolicyList))
	pol.Methods("GET").Path("/{policyId}").HandlerFunc(makeHandler(g.handlePolicyGet))
	pol.Methods("PUT").Path("/{policyId}").HandlerFunc(makeHandler(g.handlePolicyPut))
	pol.Methods("DELETE").Path("/{policyId}").HandlerFunc(makeHandler(g.handlePolicyDelete))
	end := rtr.PathPrefix("/endpoints").Subrouter()
	end.Methods("POST").Path("/").HandlerFunc(makeHandler(g.handleEndpointPost))
	end.Methods("GET").Path("/").HandlerFunc(makeHandler(g.handleEndpointList))
	end.Methods("GET").Path("/{endpointId}").HandlerFunc(makeHandler(g.handleEndpointGet))
	end.Methods("PUT").Path("/{endpointId}").HandlerFunc(makeHandler(g.handleEndpointPut))
	end.Methods("DELETE").Path("/{endpointId}").HandlerFunc(makeHandler(g.handleEndpointDelete))

	epg := rtr.PathPrefix("/epg").Subrouter()
	epg.Methods("POST").Path("/").HandlerFunc(makeHandler(g.HandleEndpointGroupPost))
	epg.Methods("GET").Path("/").HandlerFunc(makeHandler(g.HandleEndpointGroupList))
	epg.Methods("GET").Path("/{EpgId}").HandlerFunc(makeHandler(g.HandleEndpointGroupGet))
	epg.Methods("PUT").Path("/{EpgId}").HandlerFunc(makeHandler(g.HandleEndpointGroupPut))
	epg.Methods("DELETE").Path("/{EpgId}").HandlerFunc(makeHandler(g.HandleEndpointGroupDelete))
	// new routes go here

	return g, nil
}
Beispiel #2
0
package database_test

import (
	"github.com/iovisor/iomodules/policy/database"
	"github.com/iovisor/iomodules/policy/models"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Database", func() {
	var db database.Database
	BeforeEach(func() {
		var err error
		db, err = database.Init("test-db")
		Expect(err).NotTo(HaveOccurred())
	})
	Describe("Endpoints", func() {
		var endpoint = models.EndpointEntry{
			Id:    "some-uuid",
			Ip:    "some-ip",
			EpgId: "some-epg",
		}
		BeforeEach(func() {
			err := db.AddEndpoint(endpoint)
			Expect(err).NotTo(HaveOccurred())
		})
		It("Gets endpoints from the database", func() {
			eps, err := db.Endpoints()
			Expect(err).NotTo(HaveOccurred())
			Expect(eps[0]).To(Equal(endpoint))