influxdb/http/org_service.go

810 lines
21 KiB
Go
Raw Normal View History

package http
import (
"bytes"
"context"
"encoding/json"
"fmt"
platform "github.com/influxdata/influxdb"
"github.com/julienschmidt/httprouter"
"go.uber.org/zap"
2019-02-01 03:10:05 +00:00
"net/http"
"path"
)
// OrgBackend is all services and associated parameters required to construct
// the OrgHandler.
type OrgBackend struct {
Logger *zap.Logger
OrganizationService platform.OrganizationService
OrganizationOperationLogService platform.OrganizationOperationLogService
UserResourceMappingService platform.UserResourceMappingService
SecretService platform.SecretService
LabelService platform.LabelService
UserService platform.UserService
}
func NewOrgBackend(b *APIBackend) *OrgBackend {
return &OrgBackend{
Logger: b.Logger.With(zap.String("handler", "org")),
OrganizationService: b.OrganizationService,
OrganizationOperationLogService: b.OrganizationOperationLogService,
UserResourceMappingService: b.UserResourceMappingService,
SecretService: b.SecretService,
LabelService: b.LabelService,
UserService: b.UserService,
}
}
// OrgHandler represents an HTTP API handler for orgs.
type OrgHandler struct {
*httprouter.Router
Logger *zap.Logger
OrganizationService platform.OrganizationService
OrganizationOperationLogService platform.OrganizationOperationLogService
UserResourceMappingService platform.UserResourceMappingService
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
SecretService platform.SecretService
LabelService platform.LabelService
UserService platform.UserService
}
const (
organizationsPath = "/api/v2/orgs"
organizationsIDPath = "/api/v2/orgs/:id"
organizationsIDLogPath = "/api/v2/orgs/:id/log"
organizationsIDMembersPath = "/api/v2/orgs/:id/members"
2018-11-14 10:54:06 +00:00
organizationsIDMembersIDPath = "/api/v2/orgs/:id/members/:userID"
organizationsIDOwnersPath = "/api/v2/orgs/:id/owners"
2018-11-14 10:54:06 +00:00
organizationsIDOwnersIDPath = "/api/v2/orgs/:id/owners/:userID"
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
organizationsIDSecretsPath = "/api/v2/orgs/:id/secrets"
// TODO(desa): need a way to specify which secrets to delete. this should work for now
organizationsIDSecretsDeletePath = "/api/v2/orgs/:id/secrets/delete"
organizationsIDLabelsPath = "/api/v2/orgs/:id/labels"
organizationsIDLabelsIDPath = "/api/v2/orgs/:id/labels/:lid"
)
// NewOrgHandler returns a new instance of OrgHandler.
func NewOrgHandler(b *OrgBackend) *OrgHandler {
h := &OrgHandler{
Router: NewRouter(),
Logger: zap.NewNop(),
OrganizationService: b.OrganizationService,
OrganizationOperationLogService: b.OrganizationOperationLogService,
UserResourceMappingService: b.UserResourceMappingService,
SecretService: b.SecretService,
LabelService: b.LabelService,
UserService: b.UserService,
}
h.HandlerFunc("POST", organizationsPath, h.handlePostOrg)
h.HandlerFunc("GET", organizationsPath, h.handleGetOrgs)
h.HandlerFunc("GET", organizationsIDPath, h.handleGetOrg)
h.HandlerFunc("GET", organizationsIDLogPath, h.handleGetOrgLog)
h.HandlerFunc("PATCH", organizationsIDPath, h.handlePatchOrg)
h.HandlerFunc("DELETE", organizationsIDPath, h.handleDeleteOrg)
h.HandlerFunc("POST", organizationsIDMembersPath, newPostMemberHandler(h.UserResourceMappingService, h.UserService, platform.OrgsResourceType, platform.Member))
h.HandlerFunc("GET", organizationsIDMembersPath, newGetMembersHandler(h.UserResourceMappingService, h.UserService, platform.OrgsResourceType, platform.Member))
h.HandlerFunc("DELETE", organizationsIDMembersIDPath, newDeleteMemberHandler(h.UserResourceMappingService, platform.Member))
h.HandlerFunc("POST", organizationsIDOwnersPath, newPostMemberHandler(h.UserResourceMappingService, h.UserService, platform.OrgsResourceType, platform.Owner))
h.HandlerFunc("GET", organizationsIDOwnersPath, newGetMembersHandler(h.UserResourceMappingService, h.UserService, platform.OrgsResourceType, platform.Owner))
h.HandlerFunc("DELETE", organizationsIDOwnersIDPath, newDeleteMemberHandler(h.UserResourceMappingService, platform.Owner))
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
h.HandlerFunc("GET", organizationsIDSecretsPath, h.handleGetSecrets)
h.HandlerFunc("PATCH", organizationsIDSecretsPath, h.handlePatchSecrets)
// TODO(desa): need a way to specify which secrets to delete. this should work for now
h.HandlerFunc("POST", organizationsIDSecretsDeletePath, h.handleDeleteSecrets)
h.HandlerFunc("GET", organizationsIDLabelsPath, newGetLabelsHandler(h.LabelService))
h.HandlerFunc("POST", organizationsIDLabelsPath, newPostLabelHandler(h.LabelService))
h.HandlerFunc("DELETE", organizationsIDLabelsIDPath, newDeleteLabelHandler(h.LabelService))
return h
}
type orgsResponse struct {
Links map[string]string `json:"links"`
Organizations []*orgResponse `json:"orgs"`
}
func (o orgsResponse) ToPlatform() []*platform.Organization {
orgs := make([]*platform.Organization, len(o.Organizations))
for i := range o.Organizations {
orgs[i] = &o.Organizations[i].Organization
}
return orgs
}
func newOrgsResponse(orgs []*platform.Organization) *orgsResponse {
res := orgsResponse{
Links: map[string]string{
"self": "/api/v2/orgs",
},
Organizations: []*orgResponse{},
}
for _, org := range orgs {
res.Organizations = append(res.Organizations, newOrgResponse(org))
}
return &res
}
type orgResponse struct {
Links map[string]string `json:"links"`
platform.Organization
}
func newOrgResponse(o *platform.Organization) *orgResponse {
return &orgResponse{
Links: map[string]string{
"self": fmt.Sprintf("/api/v2/orgs/%s", o.ID),
"log": fmt.Sprintf("/api/v2/orgs/%s/log", o.ID),
"members": fmt.Sprintf("/api/v2/orgs/%s/members", o.ID),
"secrets": fmt.Sprintf("/api/v2/orgs/%s/secrets", o.ID),
"labels": fmt.Sprintf("/api/v2/orgs/%s/labels", o.ID),
"buckets": fmt.Sprintf("/api/v2/buckets?org=%s", o.Name),
"tasks": fmt.Sprintf("/api/v2/tasks?org=%s", o.Name),
"dashboards": fmt.Sprintf("/api/v2/dashboards?org=%s", o.Name),
},
Organization: *o,
}
}
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
type secretsResponse struct {
Links map[string]string `json:"links"`
Secrets []string `json:"secrets"`
}
func newSecretsResponse(orgID platform.ID, ks []string) *secretsResponse {
return &secretsResponse{
Links: map[string]string{
"org": fmt.Sprintf("/api/v2/orgs/%s", orgID),
"secrets": fmt.Sprintf("/api/v2/orgs/%s/secrets", orgID),
},
Secrets: ks,
}
}
// handlePostOrg is the HTTP handler for the POST /api/v2/orgs route.
func (h *OrgHandler) handlePostOrg(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodePostOrgRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := h.OrganizationService.CreateOrganization(ctx, req.Org); err != nil {
EncodeError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusCreated, newOrgResponse(req.Org)); err != nil {
logEncodingError(h.Logger, r, err)
return
}
}
type postOrgRequest struct {
Org *platform.Organization
}
func decodePostOrgRequest(ctx context.Context, r *http.Request) (*postOrgRequest, error) {
o := &platform.Organization{}
if err := json.NewDecoder(r.Body).Decode(o); err != nil {
return nil, err
}
return &postOrgRequest{
Org: o,
}, nil
}
// handleGetOrg is the HTTP handler for the GET /api/v2/orgs/:id route.
func (h *OrgHandler) handleGetOrg(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeGetOrgRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
b, err := h.OrganizationService.FindOrganizationByID(ctx, req.OrgID)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusOK, newOrgResponse(b)); err != nil {
logEncodingError(h.Logger, r, err)
return
}
}
type getOrgRequest struct {
OrgID platform.ID
}
func decodeGetOrgRequest(ctx context.Context, r *http.Request) (*getOrgRequest, error) {
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
}
var i platform.ID
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
req := &getOrgRequest{
OrgID: i,
}
return req, nil
}
// handleGetOrgs is the HTTP handler for the GET /api/v2/orgs route.
func (h *OrgHandler) handleGetOrgs(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeGetOrgsRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
orgs, _, err := h.OrganizationService.FindOrganizations(ctx, req.filter)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusOK, newOrgsResponse(orgs)); err != nil {
logEncodingError(h.Logger, r, err)
return
}
}
type getOrgsRequest struct {
filter platform.OrganizationFilter
}
func decodeGetOrgsRequest(ctx context.Context, r *http.Request) (*getOrgsRequest, error) {
qp := r.URL.Query()
req := &getOrgsRequest{}
if orgID := qp.Get("id"); orgID != "" {
id, err := platform.IDFromString(orgID)
if err != nil {
return nil, err
}
req.filter.ID = id
}
if name := qp.Get("name"); name != "" {
req.filter.Name = &name
}
return req, nil
}
// handleDeleteOrganization is the HTTP handler for the DELETE /api/v2/orgs/:id route.
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
func (h *OrgHandler) handleDeleteOrg(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeDeleteOrganizationRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
return
}
if err := h.OrganizationService.DeleteOrganization(ctx, req.OrganizationID); err != nil {
EncodeError(ctx, err, w)
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
return
}
2018-10-29 19:10:33 +00:00
w.WriteHeader(http.StatusNoContent)
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
}
type deleteOrganizationRequest struct {
OrganizationID platform.ID
}
func decodeDeleteOrganizationRequest(ctx context.Context, r *http.Request) (*deleteOrganizationRequest, error) {
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
}
var i platform.ID
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
req := &deleteOrganizationRequest{
OrganizationID: i,
}
return req, nil
}
// handlePatchOrg is the HTTP handler for the PATH /api/v2/orgs route.
func (h *OrgHandler) handlePatchOrg(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodePatchOrgRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
o, err := h.OrganizationService.UpdateOrganization(ctx, req.OrgID, req.Update)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusOK, newOrgResponse(o)); err != nil {
logEncodingError(h.Logger, r, err)
return
}
}
type patchOrgRequest struct {
Update platform.OrganizationUpdate
OrgID platform.ID
}
func decodePatchOrgRequest(ctx context.Context, r *http.Request) (*patchOrgRequest, error) {
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
}
var i platform.ID
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
var upd platform.OrganizationUpdate
if err := json.NewDecoder(r.Body).Decode(&upd); err != nil {
return nil, err
}
return &patchOrgRequest{
Update: upd,
OrgID: i,
}, nil
}
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
// handleGetSecrets is the HTTP handler for the GET /api/v2/orgs/:id/secrets route.
func (h *OrgHandler) handleGetSecrets(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeGetSecretsRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
ks, err := h.SecretService.GetSecretKeys(ctx, req.orgID)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusOK, newSecretsResponse(req.orgID, ks)); err != nil {
logEncodingError(h.Logger, r, err)
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
return
}
}
type getSecretsRequest struct {
orgID platform.ID
}
func decodeGetSecretsRequest(ctx context.Context, r *http.Request) (*getSecretsRequest, error) {
req := &getSecretsRequest{}
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
}
var i platform.ID
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
req.orgID = i
return req, nil
}
// handleGetPatchSecrets is the HTTP handler for the PATCH /api/v2/orgs/:id/secrets route.
func (h *OrgHandler) handlePatchSecrets(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodePatchSecretsRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := h.SecretService.PatchSecrets(ctx, req.orgID, req.secrets); err != nil {
EncodeError(ctx, err, w)
return
}
w.WriteHeader(http.StatusNoContent)
}
type patchSecretsRequest struct {
orgID platform.ID
secrets map[string]string
}
func decodePatchSecretsRequest(ctx context.Context, r *http.Request) (*patchSecretsRequest, error) {
req := &patchSecretsRequest{}
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
}
var i platform.ID
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
req.orgID = i
req.secrets = map[string]string{}
if err := json.NewDecoder(r.Body).Decode(&req.secrets); err != nil {
return nil, err
}
return req, nil
}
// handleDeleteSecrets is the HTTP handler for the DELETE /api/v2/orgs/:id/secrets route.
func (h *OrgHandler) handleDeleteSecrets(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeDeleteSecretsRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := h.SecretService.DeleteSecret(ctx, req.orgID, req.secrets...); err != nil {
EncodeError(ctx, err, w)
return
}
w.WriteHeader(http.StatusNoContent)
}
type deleteSecretsRequest struct {
orgID platform.ID
secrets []string
}
func decodeDeleteSecretsRequest(ctx context.Context, r *http.Request) (*deleteSecretsRequest, error) {
req := &deleteSecretsRequest{}
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
}
var i platform.ID
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
req.orgID = i
req.secrets = []string{}
if err := json.NewDecoder(r.Body).Decode(&req.secrets); err != nil {
return nil, err
}
return req, nil
}
const (
organizationPath = "/api/v2/orgs"
)
// OrganizationService connects to Influx via HTTP using tokens to manage organizations.
type OrganizationService struct {
Addr string
Token string
InsecureSkipVerify bool
2018-12-05 14:57:26 +00:00
// OpPrefix is for not found errors.
OpPrefix string
}
// FindOrganizationByID gets a single organization with a given id using HTTP.
func (s *OrganizationService) FindOrganizationByID(ctx context.Context, id platform.ID) (*platform.Organization, error) {
filter := platform.OrganizationFilter{ID: &id}
2018-12-05 14:57:26 +00:00
o, err := s.FindOrganization(ctx, filter)
if err != nil {
return nil, &platform.Error{
Err: err,
Op: s.OpPrefix + platform.OpFindOrganizationByID,
}
}
return o, nil
}
// FindOrganization gets a single organization matching the filter using HTTP.
func (s *OrganizationService) FindOrganization(ctx context.Context, filter platform.OrganizationFilter) (*platform.Organization, error) {
os, n, err := s.FindOrganizations(ctx, filter)
if err != nil {
2018-12-05 14:57:26 +00:00
return nil, &platform.Error{
Err: err,
Op: s.OpPrefix + platform.OpFindOrganization,
}
}
if n == 0 {
2018-12-05 14:57:26 +00:00
return nil, &platform.Error{
Code: platform.ENotFound,
Op: s.OpPrefix + platform.OpFindOrganization,
Msg: "organization not found",
}
}
return os[0], nil
}
// FindOrganizations returns all organizations that match the filter via HTTP.
func (s *OrganizationService) FindOrganizations(ctx context.Context, filter platform.OrganizationFilter, opt ...platform.FindOptions) ([]*platform.Organization, int, error) {
url, err := newURL(s.Addr, organizationPath)
if err != nil {
return nil, 0, err
}
qp := url.Query()
if filter.Name != nil {
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
qp.Add("name", *filter.Name)
}
if filter.ID != nil {
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
qp.Add("id", filter.ID.String())
}
url.RawQuery = qp.Encode()
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, 0, err
}
SetToken(s.Token, req)
hc := newClient(url.Scheme, s.InsecureSkipVerify)
resp, err := hc.Do(req)
if err != nil {
return nil, 0, err
}
defer resp.Body.Close()
2019-01-24 01:02:37 +00:00
if err := CheckError(resp); err != nil {
return nil, 0, err
}
var os orgsResponse
if err := json.NewDecoder(resp.Body).Decode(&os); err != nil {
return nil, 0, err
}
orgs := os.ToPlatform()
return orgs, len(orgs), nil
}
// CreateOrganization creates an organization.
func (s *OrganizationService) CreateOrganization(ctx context.Context, o *platform.Organization) error {
if o.Name == "" {
return &platform.Error{
Code: platform.EInvalid,
Msg: "organization name is required",
}
}
url, err := newURL(s.Addr, organizationPath)
if err != nil {
return err
}
octets, err := json.Marshal(o)
if err != nil {
return err
}
req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
SetToken(s.Token, req)
hc := newClient(url.Scheme, s.InsecureSkipVerify)
resp, err := hc.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
// TODO(jsternberg): Should this check for a 201 explicitly?
2019-01-24 01:02:37 +00:00
if err := CheckError(resp); err != nil {
return err
}
if err := json.NewDecoder(resp.Body).Decode(o); err != nil {
return err
}
return nil
}
// UpdateOrganization updates the organization over HTTP.
func (s *OrganizationService) UpdateOrganization(ctx context.Context, id platform.ID, upd platform.OrganizationUpdate) (*platform.Organization, error) {
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
u, err := newURL(s.Addr, organizationIDPath(id))
if err != nil {
return nil, err
}
octets, err := json.Marshal(upd)
if err != nil {
return nil, err
}
req, err := http.NewRequest("PATCH", u.String(), bytes.NewReader(octets))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
SetToken(s.Token, req)
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
hc := newClient(u.Scheme, s.InsecureSkipVerify)
resp, err := hc.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
2019-01-24 01:02:37 +00:00
if err := CheckError(resp); err != nil {
return nil, err
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
}
var o platform.Organization
if err := json.NewDecoder(resp.Body).Decode(&o); err != nil {
return nil, err
}
return &o, nil
}
// DeleteOrganization removes organization id over HTTP.
func (s *OrganizationService) DeleteOrganization(ctx context.Context, id platform.ID) error {
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
u, err := newURL(s.Addr, organizationIDPath(id))
if err != nil {
return err
}
req, err := http.NewRequest("DELETE", u.String(), nil)
if err != nil {
return err
}
SetToken(s.Token, req)
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
hc := newClient(u.Scheme, s.InsecureSkipVerify)
resp, err := hc.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
2018-10-29 19:10:33 +00:00
2019-01-24 01:02:37 +00:00
return CheckErrorStatus(http.StatusNoContent, resp)
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
}
func organizationIDPath(id platform.ID) string {
return path.Join(organizationPath, id.String())
}
// hanldeGetOrganizationLog retrieves a organization log by the organizations ID.
func (h *OrgHandler) handleGetOrgLog(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodeGetOrganizationLogRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
log, _, err := h.OrganizationOperationLogService.GetOrganizationOperationLog(ctx, req.OrganizationID, req.opts)
if err != nil {
EncodeError(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusOK, newOrganizationLogResponse(req.OrganizationID, log)); err != nil {
logEncodingError(h.Logger, r, err)
return
}
}
type getOrganizationLogRequest struct {
OrganizationID platform.ID
opts platform.FindOptions
}
func decodeGetOrganizationLogRequest(ctx context.Context, r *http.Request) (*getOrganizationLogRequest, error) {
params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id")
if id == "" {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "url missing id",
}
}
var i platform.ID
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
2019-02-01 03:10:05 +00:00
opts, err := decodeFindOptions(ctx, r)
if err != nil {
return nil, err
}
return &getOrganizationLogRequest{
OrganizationID: i,
2019-02-01 03:10:05 +00:00
opts: *opts,
}, nil
}
func newOrganizationLogResponse(id platform.ID, es []*platform.OperationLogEntry) *operationLogResponse {
log := make([]*operationLogEntryResponse, 0, len(es))
for _, e := range es {
log = append(log, newOperationLogEntryResponse(e))
}
return &operationLogResponse{
Links: map[string]string{
"self": fmt.Sprintf("/api/v2/organizations/%s/log", id),
},
Log: log,
}
}