diff --git a/http/bucket_service.go b/http/bucket_service.go index e47c10f7c74..d0548bb8663 100644 --- a/http/bucket_service.go +++ b/http/bucket_service.go @@ -62,7 +62,6 @@ type BucketHandler struct { const ( prefixBuckets = "/api/v2/buckets" bucketsIDPath = "/api/v2/buckets/:id" - bucketsIDLogPath = "/api/v2/buckets/:id/logs" bucketsIDMembersPath = "/api/v2/buckets/:id/members" bucketsIDMembersIDPath = "/api/v2/buckets/:id/members/:userID" bucketsIDOwnersPath = "/api/v2/buckets/:id/owners" @@ -89,7 +88,6 @@ func NewBucketHandler(log *zap.Logger, b *BucketBackend) *BucketHandler { h.HandlerFunc("POST", prefixBuckets, h.handlePostBucket) h.HandlerFunc("GET", prefixBuckets, h.handleGetBuckets) h.HandlerFunc("GET", bucketsIDPath, h.handleGetBucket) - h.HandlerFunc("GET", bucketsIDLogPath, h.handleGetBucketLog) h.HandlerFunc("PATCH", bucketsIDPath, h.handlePatchBucket) h.HandlerFunc("DELETE", bucketsIDPath, h.handleDeleteBucket) @@ -420,44 +418,6 @@ func bucketIDPath(id influxdb.ID) string { return path.Join(prefixBuckets, id.String()) } -// handleGetBucketLog retrieves a bucket log by the buckets ID. -func (h *BucketHandler) handleGetBucketLog(w http.ResponseWriter, r *http.Request) { - id, err := decodeIDFromCtx(r.Context(), "id") - if err != nil { - h.api.Err(w, r, err) - return - } - - opts, err := influxdb.DecodeFindOptions(r) - if err != nil { - h.api.Err(w, r, err) - return - } - - log, _, err := h.BucketOperationLogService.GetBucketOperationLog(r.Context(), id, *opts) - if err != nil { - h.api.Err(w, r, err) - return - } - - h.log.Debug("Bucket log retrived", zap.String("bucket", fmt.Sprint(log))) - - h.api.Respond(w, r, http.StatusOK, newBucketLogResponse(id, log)) -} - -func newBucketLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse { - logs := make([]*operationLogEntryResponse, 0, len(es)) - for _, e := range es { - logs = append(logs, newOperationLogEntryResponse(e)) - } - return &operationLogResponse{ - Links: map[string]string{ - "self": fmt.Sprintf("/api/v2/buckets/%s/logs", id), - }, - Logs: logs, - } -} - // handleDeleteBucket is the HTTP handler for the DELETE /api/v2/buckets/:id route. func (h *BucketHandler) handleDeleteBucket(w http.ResponseWriter, r *http.Request) { id, err := decodeIDFromCtx(r.Context(), "id") diff --git a/http/dashboard_service.go b/http/dashboard_service.go index a8de97ecfd3..c28daa81118 100644 --- a/http/dashboard_service.go +++ b/http/dashboard_service.go @@ -61,7 +61,6 @@ const ( dashboardsIDCellsIDPath = "/api/v2/dashboards/:id/cells/:cellID" dashboardsIDCellsIDViewPath = "/api/v2/dashboards/:id/cells/:cellID/view" dashboardsIDMembersPath = "/api/v2/dashboards/:id/members" - dashboardsIDLogPath = "/api/v2/dashboards/:id/logs" dashboardsIDMembersIDPath = "/api/v2/dashboards/:id/members/:userID" dashboardsIDOwnersPath = "/api/v2/dashboards/:id/owners" dashboardsIDOwnersIDPath = "/api/v2/dashboards/:id/owners/:userID" @@ -86,7 +85,6 @@ func NewDashboardHandler(log *zap.Logger, b *DashboardBackend) *DashboardHandler h.HandlerFunc("POST", prefixDashboards, h.handlePostDashboard) h.HandlerFunc("GET", prefixDashboards, h.handleGetDashboards) h.HandlerFunc("GET", dashboardsIDPath, h.handleGetDashboard) - h.HandlerFunc("GET", dashboardsIDLogPath, h.handleGetDashboardLog) h.HandlerFunc("DELETE", dashboardsIDPath, h.handleDeleteDashboard) h.HandlerFunc("PATCH", dashboardsIDPath, h.handlePatchDashboard) @@ -140,7 +138,6 @@ type dashboardLinks struct { Members string `json:"members"` Owners string `json:"owners"` Cells string `json:"cells"` - Logs string `json:"logs"` Labels string `json:"labels"` Organization string `json:"org"` } @@ -181,7 +178,6 @@ func newDashboardResponse(d *influxdb.Dashboard, labels []*influxdb.Label) dashb Members: fmt.Sprintf("/api/v2/dashboards/%s/members", d.ID), Owners: fmt.Sprintf("/api/v2/dashboards/%s/owners", d.ID), Cells: fmt.Sprintf("/api/v2/dashboards/%s/cells", d.ID), - Logs: fmt.Sprintf("/api/v2/dashboards/%s/logs", d.ID), Labels: fmt.Sprintf("/api/v2/dashboards/%s/labels", d.ID), Organization: fmt.Sprintf("/api/v2/orgs/%s", d.OrganizationID), }, @@ -310,40 +306,6 @@ func newDashboardCellViewResponse(dashID, cellID influxdb.ID, v *influxdb.View) } } -type operationLogResponse struct { - Links map[string]string `json:"links"` - Logs []*operationLogEntryResponse `json:"logs"` -} - -func newDashboardLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse { - logs := make([]*operationLogEntryResponse, 0, len(es)) - for _, e := range es { - logs = append(logs, newOperationLogEntryResponse(e)) - } - return &operationLogResponse{ - Links: map[string]string{ - "self": fmt.Sprintf("/api/v2/dashboards/%s/logs", id), - }, - Logs: logs, - } -} - -type operationLogEntryResponse struct { - Links map[string]string `json:"links"` - *influxdb.OperationLogEntry -} - -func newOperationLogEntryResponse(e *influxdb.OperationLogEntry) *operationLogEntryResponse { - links := map[string]string{} - if e.UserID.Valid() { - links["user"] = fmt.Sprintf("/api/v2/users/%s", e.UserID) - } - return &operationLogEntryResponse{ - Links: links, - OperationLogEntry: e, - } -} - // handleGetDashboards returns all dashboards within the store. func (h *DashboardHandler) handleGetDashboards(w http.ResponseWriter, r *http.Request) { ctx := r.Context() @@ -548,60 +510,6 @@ func decodeGetDashboardRequest(ctx context.Context, r *http.Request) (*getDashbo }, nil } -// hanldeGetDashboardLog retrieves a dashboard log by the dashboards ID. -func (h *DashboardHandler) handleGetDashboardLog(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - req, err := decodeGetDashboardLogRequest(ctx, r) - if err != nil { - h.HandleHTTPError(ctx, err, w) - return - } - - log, _, err := h.DashboardOperationLogService.GetDashboardOperationLog(ctx, req.DashboardID, req.opts) - if err != nil { - h.HandleHTTPError(ctx, err, w) - return - } - - h.log.Debug("Dashboard log retrieved", zap.String("log", fmt.Sprint(log))) - - if err := encodeResponse(ctx, w, http.StatusOK, newDashboardLogResponse(req.DashboardID, log)); err != nil { - logEncodingError(h.log, r, err) - return - } -} - -type getDashboardLogRequest struct { - DashboardID influxdb.ID - opts influxdb.FindOptions -} - -func decodeGetDashboardLogRequest(ctx context.Context, r *http.Request) (*getDashboardLogRequest, error) { - params := httprouter.ParamsFromContext(ctx) - id := params.ByName("id") - if id == "" { - return nil, &influxdb.Error{ - Code: influxdb.EInvalid, - Msg: "url missing id", - } - } - - var i influxdb.ID - if err := i.DecodeFromString(id); err != nil { - return nil, err - } - - opts, err := influxdb.DecodeFindOptions(r) - if err != nil { - return nil, err - } - - return &getDashboardLogRequest{ - DashboardID: i, - opts: *opts, - }, nil -} - // handleDeleteDashboard removes a dashboard by ID. func (h *DashboardHandler) handleDeleteDashboard(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/http/dashboard_test.go b/http/dashboard_test.go index 54a94aa974d..45344e2e7cb 100644 --- a/http/dashboard_test.go +++ b/http/dashboard_test.go @@ -158,7 +158,6 @@ func TestService_handleGetDashboards(t *testing.T) { "members": "/api/v2/dashboards/da7aba5e5d81e550/members", "owners": "/api/v2/dashboards/da7aba5e5d81e550/owners", "cells": "/api/v2/dashboards/da7aba5e5d81e550/cells", - "logs": "/api/v2/dashboards/da7aba5e5d81e550/logs", "labels": "/api/v2/dashboards/da7aba5e5d81e550/labels" } }, @@ -186,7 +185,6 @@ func TestService_handleGetDashboards(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/0ca2204eca2204e0/members", "owners": "/api/v2/dashboards/0ca2204eca2204e0/owners", - "logs": "/api/v2/dashboards/0ca2204eca2204e0/logs", "cells": "/api/v2/dashboards/0ca2204eca2204e0/cells", "labels": "/api/v2/dashboards/0ca2204eca2204e0/labels" } @@ -319,7 +317,6 @@ func TestService_handleGetDashboards(t *testing.T) { "members": "/api/v2/dashboards/da7aba5e5d81e550/members", "owners": "/api/v2/dashboards/da7aba5e5d81e550/owners", "cells": "/api/v2/dashboards/da7aba5e5d81e550/cells", - "logs": "/api/v2/dashboards/da7aba5e5d81e550/logs", "labels": "/api/v2/dashboards/da7aba5e5d81e550/labels" } } @@ -481,7 +478,6 @@ func TestService_handleGetDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } @@ -562,7 +558,6 @@ func TestService_handleGetDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } @@ -641,7 +636,6 @@ func TestService_handleGetDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } @@ -716,7 +710,6 @@ func TestService_handleGetDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } @@ -878,7 +871,6 @@ func TestService_handlePostDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } @@ -1003,7 +995,6 @@ func TestService_handlePostDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } @@ -1246,7 +1237,6 @@ func TestService_handlePatchDashboard(t *testing.T) { "org": "/api/v2/orgs/0000000000000001", "members": "/api/v2/dashboards/020f755c3c082000/members", "owners": "/api/v2/dashboards/020f755c3c082000/owners", - "logs": "/api/v2/dashboards/020f755c3c082000/logs", "cells": "/api/v2/dashboards/020f755c3c082000/cells", "labels": "/api/v2/dashboards/020f755c3c082000/labels" } diff --git a/http/org_service.go b/http/org_service.go index 6d9df0a3c12..849230b8bdc 100644 --- a/http/org_service.go +++ b/http/org_service.go @@ -61,7 +61,6 @@ type OrgHandler struct { const ( prefixOrganizations = "/api/v2/orgs" organizationsIDPath = "/api/v2/orgs/:id" - organizationsIDLogPath = "/api/v2/orgs/:id/logs" organizationsIDMembersPath = "/api/v2/orgs/:id/members" organizationsIDMembersIDPath = "/api/v2/orgs/:id/members/:userID" organizationsIDOwnersPath = "/api/v2/orgs/:id/owners" @@ -112,7 +111,6 @@ func NewOrgHandler(log *zap.Logger, b *OrgBackend) *OrgHandler { h.HandlerFunc("POST", prefixOrganizations, h.handlePostOrg) h.HandlerFunc("GET", prefixOrganizations, 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) @@ -402,43 +400,6 @@ func (h *OrgHandler) handleDeleteSecrets(w http.ResponseWriter, r *http.Request) h.API.Respond(w, r, http.StatusNoContent, nil) } -// hanldeGetOrganizationLog retrieves a organization log by the organizations ID. -func (h *OrgHandler) handleGetOrgLog(w http.ResponseWriter, r *http.Request) { - orgID, err := decodeIDFromCtx(r.Context(), "id") - if err != nil { - h.API.Err(w, r, err) - return - } - - opts, err := influxdb.DecodeFindOptions(r) - if err != nil { - h.API.Err(w, r, err) - return - } - - log, _, err := h.OrganizationOperationLogService.GetOrganizationOperationLog(r.Context(), orgID, *opts) - if err != nil { - h.API.Err(w, r, err) - return - } - h.log.Debug("Org logs retrieved", zap.String("log", fmt.Sprint(log))) - - h.API.Respond(w, r, http.StatusOK, newOrganizationLogResponse(orgID, log)) -} - -func newOrganizationLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse { - logs := make([]*operationLogEntryResponse, 0, len(es)) - for _, e := range es { - logs = append(logs, newOperationLogEntryResponse(e)) - } - return &operationLogResponse{ - Links: map[string]string{ - "self": fmt.Sprintf("/api/v2/orgs/%s/logs", id), - }, - Logs: logs, - } -} - // SecretService connects to Influx via HTTP using tokens to manage secrets. type SecretService struct { Client *httpc.Client diff --git a/http/swagger.yml b/http/swagger.yml index 460bf7b38e3..95a692f6eaa 100644 --- a/http/swagger.yml +++ b/http/swagger.yml @@ -3126,36 +3126,6 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" - "/dashboards/{dashboardID}/logs": - get: - operationId: GetDashboardsIDLogs - tags: - - Dashboards - - OperationLogs - summary: Retrieve operation logs for a dashboard - parameters: - - $ref: "#/components/parameters/TraceSpan" - - $ref: "#/components/parameters/Offset" - - $ref: "#/components/parameters/Limit" - - in: path - name: dashboardID - required: true - description: The dashboard ID. - schema: - type: string - responses: - "200": - description: Operation logs for the dashboard - content: - application/json: - schema: - $ref: "#/components/schemas/OperationLogs" - default: - description: Unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" /query/ast: post: operationId: PostQueryAst @@ -3962,36 +3932,6 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" - "/buckets/{bucketID}/logs": - get: - operationId: GetBucketsIDLogs - tags: - - Buckets - - OperationLogs - summary: Retrieve operation logs for a bucket - parameters: - - $ref: "#/components/parameters/TraceSpan" - - $ref: "#/components/parameters/Offset" - - $ref: "#/components/parameters/Limit" - - in: path - name: bucketID - required: true - description: The bucket ID. - schema: - type: string - responses: - "200": - description: Operation logs for the bucket - content: - application/json: - schema: - $ref: "#/components/schemas/OperationLogs" - default: - description: Unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" /orgs: get: operationId: GetOrgs @@ -4678,36 +4618,6 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" - "/orgs/{orgID}/logs": - get: - operationId: GetOrgsIDLogs - tags: - - Organizations - - OperationLogs - summary: Retrieve operation logs for an organization - parameters: - - $ref: "#/components/parameters/TraceSpan" - - $ref: "#/components/parameters/Offset" - - $ref: "#/components/parameters/Limit" - - in: path - name: orgID - required: true - description: The organization ID. - schema: - type: string - responses: - "200": - description: Operation logs for the organization - content: - application/json: - schema: - $ref: "#/components/schemas/OperationLogs" - default: - description: Unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" /packages: post: operationId: CreatePkg @@ -5898,36 +5808,6 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" - "/users/{userID}/logs": - get: - operationId: GetUsersIDLogs - tags: - - Users - - OperationLogs - summary: Retrieve operation logs for a user - parameters: - - $ref: "#/components/parameters/TraceSpan" - - $ref: "#/components/parameters/Offset" - - $ref: "#/components/parameters/Limit" - - in: path - name: userID - required: true - description: The user ID. - schema: - type: string - responses: - "200": - description: Operation logs for the user - content: - application/json: - schema: - $ref: "#/components/schemas/OperationLogs" - default: - description: Unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" /checks: get: operationId: GetChecks @@ -7574,7 +7454,6 @@ components: readOnly: true example: labels: "/api/v2/buckets/1/labels" - logs: "/api/v2/buckets/1/logs" members: "/api/v2/buckets/1/members" org: "/api/v2/orgs/2" owners: "/api/v2/buckets/1/owners" @@ -7584,9 +7463,6 @@ components: labels: description: URL to retrieve labels for this bucket $ref: "#/components/schemas/Link" - logs: - description: URL to retrieve operation logs for this bucket - $ref: "#/components/schemas/Link" members: description: URL to retrieve members that can read this bucket $ref: "#/components/schemas/Link" @@ -7698,35 +7574,6 @@ components: description: A description of the event that occurred. type: string example: Halt and catch fire - OperationLog: - type: object - readOnly: true - properties: - description: - type: string - description: A description of the event that occurred. - example: Bucket Created - time: - type: string - description: Time event occurred, RFC3339Nano. - format: date-time - userID: - type: string - description: ID of the user who operated the event. - links: - type: object - properties: - user: - $ref: "#/components/schemas/Link" - OperationLogs: - type: object - properties: - logs: - type: array - items: - $ref: "#/components/schemas/OperationLog" - links: - $ref: "#/components/schemas/Links" Organization: properties: links: @@ -7741,7 +7588,6 @@ components: buckets: "/api/v2/buckets?org=myorg" tasks: "/api/v2/tasks?org=myorg" dashboards: "/api/v2/dashboards?org=myorg" - logs: "/api/v2/orgs/1/logs" properties: self: $ref: "#/components/schemas/Link" @@ -7759,8 +7605,6 @@ components: $ref: "#/components/schemas/Link" dashboards: $ref: "#/components/schemas/Link" - logs: - $ref: "#/components/schemas/Link" id: readOnly: true type: string @@ -8573,7 +8417,6 @@ components: self: "/api/v2/tasks/1/runs/1" task: "/api/v2/tasks/1" retry: "/api/v2/tasks/1/runs/1/retry" - logs: "/api/v2/tasks/1/runs/1/logs" properties: self: type: string @@ -8581,9 +8424,6 @@ components: task: type: string format: uri - logs: - type: string - format: uri retry: type: string format: uri @@ -8794,14 +8634,10 @@ components: readOnly: true example: self: "/api/v2/users/1" - logs: "/api/v2/users/1/logs" properties: self: type: string format: uri - logs: - type: string - format: uri required: [name] Users: type: object @@ -10064,7 +9900,6 @@ components: cells: "/api/v2/dashboards/1/cells" owners: "/api/v2/dashboards/1/owners" members: "/api/v2/dashboards/1/members" - logs: "/api/v2/dashboards/1/logs" labels: "/api/v2/dashboards/1/labels" org: "/api/v2/labels/1" properties: @@ -10076,8 +9911,6 @@ components: $ref: "#/components/schemas/Link" owners: $ref: "#/components/schemas/Link" - logs: - $ref: "#/components/schemas/Link" labels: $ref: "#/components/schemas/Link" org: @@ -10111,7 +9944,6 @@ components: cells: "/api/v2/dashboards/1/cells" owners: "/api/v2/dashboards/1/owners" members: "/api/v2/dashboards/1/members" - logs: "/api/v2/dashboards/1/logs" labels: "/api/v2/dashboards/1/labels" org: "/api/v2/labels/1" properties: @@ -10123,8 +9955,6 @@ components: $ref: "#/components/schemas/Link" owners: $ref: "#/components/schemas/Link" - logs: - $ref: "#/components/schemas/Link" labels: $ref: "#/components/schemas/Link" org: diff --git a/http/user_service.go b/http/user_service.go index bbe8d601d45..5912885770d 100644 --- a/http/user_service.go +++ b/http/user_service.go @@ -50,7 +50,6 @@ const ( mePasswordPath = "/api/v2/me/password" usersIDPath = "/api/v2/users/:id" usersPasswordPath = "/api/v2/users/:id/password" - usersLogPath = "/api/v2/users/:id/logs" ) // NewUserHandler returns a new instance of UserHandler. @@ -68,7 +67,6 @@ func NewUserHandler(log *zap.Logger, b *UserBackend) *UserHandler { h.HandlerFunc("POST", prefixUsers, h.handlePostUser) h.HandlerFunc("GET", prefixUsers, h.handleGetUsers) h.HandlerFunc("GET", usersIDPath, h.handleGetUser) - h.HandlerFunc("GET", usersLogPath, h.handleGetUserLog) h.HandlerFunc("PATCH", usersIDPath, h.handlePatchUser) h.HandlerFunc("DELETE", usersIDPath, h.handleDeleteUser) // the POST doesn't need to be nested under users in this scheme @@ -336,72 +334,6 @@ func decodeDeleteUserRequest(ctx context.Context, r *http.Request) (*deleteUserR }, nil } -// hanldeGetUserLog retrieves a user log by the users ID. -func (h *UserHandler) handleGetUserLog(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - req, err := decodeGetUserLogRequest(ctx, r) - if err != nil { - h.HandleHTTPError(ctx, err, w) - return - } - - log, _, err := h.UserOperationLogService.GetUserOperationLog(ctx, req.UserID, req.opts) - if err != nil { - h.HandleHTTPError(ctx, err, w) - return - } - h.log.Debug("User log retrieved", zap.String("log", fmt.Sprint(log))) - - if err := encodeResponse(ctx, w, http.StatusOK, newUserLogResponse(req.UserID, log)); err != nil { - h.HandleHTTPError(ctx, err, w) - return - } -} - -type getUserLogRequest struct { - UserID influxdb.ID - opts influxdb.FindOptions -} - -func decodeGetUserLogRequest(ctx context.Context, r *http.Request) (*getUserLogRequest, error) { - params := httprouter.ParamsFromContext(ctx) - id := params.ByName("id") - if id == "" { - return nil, &influxdb.Error{ - Code: influxdb.EInvalid, - Msg: "url missing id", - } - } - - var i influxdb.ID - if err := i.DecodeFromString(id); err != nil { - return nil, err - } - - opts, err := influxdb.DecodeFindOptions(r) - if err != nil { - return nil, err - } - - return &getUserLogRequest{ - UserID: i, - opts: *opts, - }, nil -} - -func newUserLogResponse(id influxdb.ID, es []*influxdb.OperationLogEntry) *operationLogResponse { - logs := make([]*operationLogEntryResponse, 0, len(es)) - for _, e := range es { - logs = append(logs, newOperationLogEntryResponse(e)) - } - return &operationLogResponse{ - Links: map[string]string{ - "self": fmt.Sprintf("/api/v2/users/%s/logs", id), - }, - Logs: logs, - } -} - type usersResponse struct { Links map[string]string `json:"links"` Users []*UserResponse `json:"users"`