Skip to content

Commit

Permalink
chore: consistently use otelx.End(); fix some incorrect API docs (#3835)
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Sep 16, 2024
1 parent 554238b commit ee427ed
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 257 deletions.
4 changes: 2 additions & 2 deletions consent/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ type revokeOAuth2LoginSessions struct {
// in: query
Subject string `json:"subject"`

// OAuth 2.0 Subject
// Login Session ID
//
// The subject to revoke authentication sessions for.
// The login session to revoke.
//
// in: query
SessionID string `json:"sid"`
Expand Down
68 changes: 27 additions & 41 deletions hsm/manager_hsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"github.com/go-jose/go-jose/v3"
"github.com/go-jose/go-jose/v3/cryptosigner"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

const tracingComponent = "github.com/ory/hydra/hsm"
Expand All @@ -58,23 +60,21 @@ func NewKeyManager(hsm Context, config *config.DefaultProvider) *KeyManager {
}
}

func (m *KeyManager) GenerateAndPersistKeySet(ctx context.Context, set, kid, alg, use string) (*jose.JSONWebKeySet, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.GenerateAndPersistKeySet")
defer span.End()
attrs := map[string]string{
"set": set,
"kid": kid,
"alg": alg,
"use": use,
}
span.SetAttributes(otelx.StringAttrs(attrs)...)
func (m *KeyManager) GenerateAndPersistKeySet(ctx context.Context, set, kid, alg, use string) (_ *jose.JSONWebKeySet, err error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.GenerateAndPersistKeySet",
trace.WithAttributes(
attribute.String("set", set),
attribute.String("kid", kid),
attribute.String("alg", alg),
attribute.String("use", use)))
defer otelx.End(span, &err)

m.Lock()
defer m.Unlock()

set = m.prefixKeySet(set)

err := m.deleteExistingKeySet(set)
err = m.deleteExistingKeySet(set)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -119,14 +119,10 @@ func (m *KeyManager) GenerateAndPersistKeySet(ctx context.Context, set, kid, alg
}
}

func (m *KeyManager) GetKey(ctx context.Context, set, kid string) (*jose.JSONWebKeySet, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.GetKey")
defer span.End()
attrs := map[string]string{
"set": set,
"kid": kid,
}
span.SetAttributes(otelx.StringAttrs(attrs)...)
func (m *KeyManager) GetKey(ctx context.Context, set, kid string) (_ *jose.JSONWebKeySet, err error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.GetKey",
trace.WithAttributes(attribute.String("set", set), attribute.String("kid", kid)))
defer otelx.End(span, &err)

m.RLock()
defer m.RUnlock()
Expand All @@ -150,13 +146,9 @@ func (m *KeyManager) GetKey(ctx context.Context, set, kid string) (*jose.JSONWeb
return createKeySet(keyPair, id, alg, use)
}

func (m *KeyManager) GetKeySet(ctx context.Context, set string) (*jose.JSONWebKeySet, error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.GetKeySet")
defer span.End()
attrs := map[string]string{
"set": set,
}
span.SetAttributes(otelx.StringAttrs(attrs)...)
func (m *KeyManager) GetKeySet(ctx context.Context, set string) (_ *jose.JSONWebKeySet, err error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.GetKeySet", trace.WithAttributes(attribute.String("set", set)))
otelx.End(span, &err)

m.RLock()
defer m.RUnlock()
Expand Down Expand Up @@ -186,14 +178,12 @@ func (m *KeyManager) GetKeySet(ctx context.Context, set string) (*jose.JSONWebKe
}, nil
}

func (m *KeyManager) DeleteKey(ctx context.Context, set, kid string) error {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.DeleteKey")
defer span.End()
attrs := map[string]string{
"set": set,
"kid": kid,
}
span.SetAttributes(otelx.StringAttrs(attrs)...)
func (m *KeyManager) DeleteKey(ctx context.Context, set, kid string) (err error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.DeleteKey",
trace.WithAttributes(
attribute.String("set", set),
attribute.String("kid", kid)))
defer otelx.End(span, &err)

m.Lock()
defer m.Unlock()
Expand All @@ -216,13 +206,9 @@ func (m *KeyManager) DeleteKey(ctx context.Context, set, kid string) error {
return nil
}

func (m *KeyManager) DeleteKeySet(ctx context.Context, set string) error {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.DeleteKeySet")
defer span.End()
attrs := map[string]string{
"set": set,
}
span.SetAttributes(otelx.StringAttrs(attrs)...)
func (m *KeyManager) DeleteKeySet(ctx context.Context, set string) (err error) {
ctx, span := otel.GetTracerProvider().Tracer(tracingComponent).Start(ctx, "hsm.DeleteKeySet", trace.WithAttributes(attribute.String("set", set)))
defer otelx.End(span, &err)

m.Lock()
defer m.Unlock()
Expand Down
30 changes: 15 additions & 15 deletions internal/httpclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -402,7 +402,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -549,7 +549,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1008,7 +1008,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1062,7 +1062,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1166,9 +1166,9 @@ paths:
type: string
style: form
- description: |-
OAuth 2.0 Subject
Login Session ID
The subject to revoke authentication sessions for.
The login session to revoke.
explode: true
in: query
name: sid
Expand All @@ -1180,7 +1180,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1236,7 +1236,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1342,7 +1342,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1489,7 +1489,7 @@ paths:
"302":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1572,7 +1572,7 @@ paths:
"204":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand Down Expand Up @@ -1698,7 +1698,7 @@ paths:
"200":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
default:
content:
application/json:
Expand All @@ -1725,7 +1725,7 @@ paths:
"302":
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
summary: OpenID Connect Front- and Back-channel Enabled Logout
tags:
- oidc
Expand Down Expand Up @@ -1816,7 +1816,7 @@ components:
emptyResponse:
description: |-
Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is
typically 201.
typically 204.
errorOAuth2BadRequest:
content:
application/json:
Expand Down
2 changes: 1 addition & 1 deletion internal/httpclient/api_o_auth2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/httpclient/docs/OAuth2API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ import (

func main() {
subject := "subject_example" // string | OAuth 2.0 Subject The subject to revoke authentication sessions for. (optional)
sid := "sid_example" // string | OAuth 2.0 Subject The subject to revoke authentication sessions for. (optional)
sid := "sid_example" // string | Login Session ID The login session to revoke. (optional)

configuration := openapiclient.NewConfiguration()
apiClient := openapiclient.NewAPIClient(configuration)
Expand All @@ -1644,7 +1644,7 @@ Other parameters are passed through a pointer to a apiRevokeOAuth2LoginSessionsR
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**subject** | **string** | OAuth 2.0 Subject The subject to revoke authentication sessions for. |
**sid** | **string** | OAuth 2.0 Subject The subject to revoke authentication sessions for. |
**sid** | **string** | Login Session ID The login session to revoke. |

### Return type

Expand Down
Loading

0 comments on commit ee427ed

Please sign in to comment.