Exemple #1
0
// Inserts or updates a routes in etcd.
func (c *Client) Upsert(r *eskip.Route) error {
	if r.Id == "" {
		return missingRouteId
	}

	_, err := c.etcd.Set(c.routesRoot+"/"+r.Id, r.String(), 0)
	return err
}
Exemple #2
0
// generate weak random id for a route if
// it doesn't have one.
func ensureId(r *eskip.Route) error {
	if r.Id != "" {
		return nil
	}

	// using this to avoid adding a new dependency.
	id, err := flowid.NewFlowId(randomIdLength)
	if err != nil {
		return err
	}

	// replace characters that are not allowed
	// for eskip route ids.
	id = routeIdRx.ReplaceAllString(id, "x")
	r.Id = "route" + id
	return nil
}
Exemple #3
0
func (c *Client) etcdSet(r *eskip.Route) error {
	_, err := c.etcdRequest("PUT", c.routesRoot+"/"+r.Id, r.String())
	return err
}
Exemple #4
0
func routesDiffer(left, right *eskip.Route) bool {
	return left.String() != right.String()
}