Skip to content

Commit

Permalink
ING-963: Added a /v1/callerIdentity endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Lawson committed Nov 1, 2024
1 parent d06977e commit 227c8c5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dataapiv1/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ info:
version: 1.0.0
title: Couchbase Data API
paths:
'/v1/callerIdentity':
parameters:
- $ref: '#/components/parameters/AuthorizationHeader'
get:
operationId: getCallerIdentity
tags:
- Tools
responses:
'200':
description: Successfully fetched the current callers identity.
content:
'application/json':
schema:
type: object
properties:
user:
type: string
description: The user that is making the request.
'403':
$ref: '#/components/responses/Forbidden'
'500':
$ref: '#/components/responses/InternalServerError'
'/v1/buckets/{bucketName}/scopes/{scopeName}/collections/{collectionName}/documents/{documentKey}':
parameters:
- $ref: '#/components/parameters/AuthorizationHeader'
Expand Down
20 changes: 20 additions & 0 deletions gateway/dapiimpl/server_v1/dataapi_tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package server_v1

import (
"context"

"github.com/couchbase/stellar-gateway/dataapiv1"
)

func (s *DataApiServer) GetCallerIdentity(
ctx context.Context, in dataapiv1.GetCallerIdentityRequestObject,
) (dataapiv1.GetCallerIdentityResponseObject, error) {
user, _, errSt := s.authHandler.GetOboUserFromRequest(ctx, in.Params.Authorization)
if errSt != nil {
return nil, errSt.Err()
}

return dataapiv1.GetCallerIdentity200JSONResponse{
User: &user,
}, nil
}
35 changes: 35 additions & 0 deletions gateway/test/dapi_tools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package test

import (
"fmt"
"net/http"

"github.com/stretchr/testify/assert"
)

func (s *GatewayOpsTestSuite) TestDapiCallerIdentity() {
s.Run("Basic", func() {
resp := s.sendTestHttpRequest(&testHttpRequest{
Method: http.MethodGet,
Path: "/v1/callerIdentity",
Headers: map[string]string{
"Authorization": s.basicRestCreds,
},
})
requireRestSuccess(s.T(), resp)
assert.JSONEq(s.T(), fmt.Sprintf(`{"user":"%s"}`, s.testClusterInfo.BasicUser), string(resp.Body))
})

s.Run("InvalidAuth", func() {
resp := s.sendTestHttpRequest(&testHttpRequest{
Method: http.MethodGet,
Path: "/v1/callerIdentity",
Headers: map[string]string{
"Authorization": s.badRestCreds,
},
})
requireRestError(s.T(), resp, http.StatusForbidden, &testRestError{
Code: "InvalidAuth",
})
})
}
File renamed without changes.

0 comments on commit 227c8c5

Please sign in to comment.