Skip to content

Commit 2438ca0

Browse files
author
Ajay Kelkar
authored
feat: add handler with openapi def for admin revoke session (#2867)
1 parent 65aeb0a commit 2438ca0

File tree

13 files changed

+506
-1
lines changed

13 files changed

+506
-1
lines changed

internal/httpclient/.openapi-generator/FILES

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.travis.yml
44
README.md
55
api/openapi.yaml
6+
api_identity.go
67
api_metadata.go
78
api_v0alpha2.go
89
client.go
@@ -25,6 +26,7 @@ docs/GenericError.md
2526
docs/HealthNotReadyStatus.md
2627
docs/HealthStatus.md
2728
docs/Identity.md
29+
docs/IdentityApi.md
2830
docs/IdentityCredentials.md
2931
docs/IdentityCredentialsOidc.md
3032
docs/IdentityCredentialsOidcProvider.md

internal/httpclient/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ All URIs are relative to *http://localhost*
8383

8484
Class | Method | HTTP request | Description
8585
------------ | ------------- | ------------- | -------------
86+
*IdentityApi* | [**DisableSession**](docs/IdentityApi.md#disablesession) | **Delete** /admin/sessions/{id} | Deactivate a Session
8687
*MetadataApi* | [**GetVersion**](docs/MetadataApi.md#getversion) | **Get** /version | Return Running Software Version.
8788
*MetadataApi* | [**IsAlive**](docs/MetadataApi.md#isalive) | **Get** /health/alive | Check HTTP Server Status
8889
*MetadataApi* | [**IsReady**](docs/MetadataApi.md#isready) | **Get** /health/ready | Check HTTP Server and Database Status

internal/httpclient/api/openapi.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,44 @@ paths:
743743
tags:
744744
- v0alpha2
745745
/admin/sessions/{id}:
746+
delete:
747+
description: Calling this endpoint deactivates the specified session. Session
748+
data is not deleted.
749+
operationId: disableSession
750+
parameters:
751+
- description: ID is the session's ID.
752+
explode: false
753+
in: path
754+
name: id
755+
required: true
756+
schema:
757+
type: string
758+
style: simple
759+
responses:
760+
"204":
761+
description: Empty responses are sent when, for example, resources are deleted.
762+
The HTTP status code for empty responses is typically 201.
763+
"400":
764+
content:
765+
application/json:
766+
schema:
767+
$ref: '#/components/schemas/jsonError'
768+
description: jsonError
769+
"401":
770+
content:
771+
application/json:
772+
schema:
773+
$ref: '#/components/schemas/jsonError'
774+
description: jsonError
775+
default:
776+
content:
777+
application/json:
778+
schema:
779+
$ref: '#/components/schemas/jsonError'
780+
description: jsonError
781+
summary: Deactivate a Session
782+
tags:
783+
- identity
746784
get:
747785
description: |-
748786
This endpoint is useful for:

internal/httpclient/api_identity.go

+167
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/httpclient/client.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# \IdentityApi
2+
3+
All URIs are relative to *http://localhost*
4+
5+
Method | HTTP request | Description
6+
------------- | ------------- | -------------
7+
[**DisableSession**](IdentityApi.md#DisableSession) | **Delete** /admin/sessions/{id} | Deactivate a Session
8+
9+
10+
11+
## DisableSession
12+
13+
> DisableSession(ctx, id).Execute()
14+
15+
Deactivate a Session
16+
17+
18+
19+
### Example
20+
21+
```go
22+
package main
23+
24+
import (
25+
"context"
26+
"fmt"
27+
"os"
28+
openapiclient "./openapi"
29+
)
30+
31+
func main() {
32+
id := "id_example" // string | ID is the session's ID.
33+
34+
configuration := openapiclient.NewConfiguration()
35+
apiClient := openapiclient.NewAPIClient(configuration)
36+
resp, r, err := apiClient.IdentityApi.DisableSession(context.Background(), id).Execute()
37+
if err != nil {
38+
fmt.Fprintf(os.Stderr, "Error when calling `IdentityApi.DisableSession``: %v\n", err)
39+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
40+
}
41+
}
42+
```
43+
44+
### Path Parameters
45+
46+
47+
Name | Type | Description | Notes
48+
------------- | ------------- | ------------- | -------------
49+
**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.
50+
**id** | **string** | ID is the session's ID. |
51+
52+
### Other Parameters
53+
54+
Other parameters are passed through a pointer to a apiDisableSessionRequest struct via the builder pattern
55+
56+
57+
Name | Type | Description | Notes
58+
------------- | ------------- | ------------- | -------------
59+
60+
61+
### Return type
62+
63+
(empty response body)
64+
65+
### Authorization
66+
67+
No authorization required
68+
69+
### HTTP request headers
70+
71+
- **Content-Type**: Not defined
72+
- **Accept**: application/json
73+
74+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints)
75+
[[Back to Model list]](../README.md#documentation-for-models)
76+
[[Back to README]](../README.md)
77+

persistence/sql/persister_session.go

+22
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,28 @@ func (p *Persister) RevokeSessionByToken(ctx context.Context, token string) erro
312312
return nil
313313
}
314314

315+
// RevokeSessionById revokes a given session
316+
func (p *Persister) RevokeSessionById(ctx context.Context, sID uuid.UUID) error {
317+
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.RevokeSessionById")
318+
defer span.End()
319+
320+
// #nosec G201
321+
count, err := p.GetConnection(ctx).RawQuery(fmt.Sprintf(
322+
"UPDATE %s SET active = false WHERE id = ? AND nid = ?",
323+
"sessions",
324+
),
325+
sID,
326+
p.NetworkID(ctx),
327+
).ExecWithCount()
328+
if err != nil {
329+
return sqlcon.HandleError(err)
330+
}
331+
if count == 0 {
332+
return errors.WithStack(sqlcon.ErrNoRows)
333+
}
334+
return nil
335+
}
336+
315337
// RevokeSession revokes a given session. If the session does not exist or was not modified,
316338
// it effectively has been revoked already, and therefore that case does not return an error.
317339
func (p *Persister) RevokeSession(ctx context.Context, iID, sID uuid.UUID) error {

0 commit comments

Comments
 (0)