Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

Add GetPAT function

Ahsan Barkati96267e2e3a28
diff --git a/ee/query-service/app/api/pat.go b/ee/query-service/app/api/pat.go
index 1b32ddfde5..7c6052cffb 100644
--- a/ee/query-service/app/api/pat.go
+++ b/ee/query-service/app/api/pat.go
@@ -45,7 +45,6 @@ func (ah *APIHandler) createPAT(w http.ResponseWriter, r *http.Request) {
req.Token = generatePATToken()
zap.S().Infof("Got PAT request: %+v", req)
-
if apierr := ah.AppDao().CreatePAT(ctx, &req); apierr != nil {
RespondError(w, apierr, nil)
return
diff --git a/ee/query-service/dao/interface.go b/ee/query-service/dao/interface.go
index a74fa5c6f2..5bb7c02412 100644
--- a/ee/query-service/dao/interface.go
+++ b/ee/query-service/dao/interface.go
@@ -35,6 +35,7 @@ type ModelDao interface {
GetDomainByEmail(ctx context.Context, email string) (*model.OrgDomain, basemodel.BaseApiError)
CreatePAT(ctx context.Context, p *model.PAT) basemodel.BaseApiError
+ GetPAT(ctx context.Context, patID string) (*model.PAT, basemodel.BaseApiError)
ListPATs(ctx context.Context, userID string) ([]model.PAT, basemodel.BaseApiError)
DeletePAT(ctx context.Context, id string) basemodel.BaseApiError
}
diff --git a/ee/query-service/dao/sqlite/pat.go b/ee/query-service/dao/sqlite/pat.go
index 340af1f854..fc3c406ecb 100644
--- a/ee/query-service/dao/sqlite/pat.go
+++ b/ee/query-service/dao/sqlite/pat.go
@@ -29,7 +29,7 @@ func (m *modelDao) ListPATs(ctx context.Context, userID string) ([]model.PAT, ba
if err := m.DB().Select(&pats, `SELECT * FROM personal_access_tokens WHERE user_id=?;`, userID); err != nil {
zap.S().Errorf("Failed to fetch PATs for user: %s, err: %v", userID, zap.Error(err))
- return nil, model.InternalError(fmt.Errorf("Failed to fetch PATs"))
+ return nil, model.InternalError(fmt.Errorf("failed to fetch PATs"))
}
return pats, nil
}
@@ -38,7 +38,25 @@ func (m *modelDao) DeletePAT(ctx context.Context, id string) basemodel.BaseApiEr
_, err := m.DB().ExecContext(ctx, `DELETE from personal_access_tokens where id=?;`, id)
if err != nil {
zap.S().Errorf("Failed to delete PAT, err: %v", zap.Error(err))
- return model.InternalError(fmt.Errorf("Failed to delete PAT"))
+ return model.InternalError(fmt.Errorf("failed to delete PAT"))
}
return nil
}
+
+func (m *modelDao) GetPAT(ctx context.Context, patID string) (*model.PAT, basemodel.BaseApiError) {
+ pats := []model.PAT{}
+
+ if err := m.DB().Select(&pats, `SELECT * FROM personal_access_tokens WHERE id=?;`, patID); err != nil {
+ zap.S().Errorf("Failed to fetch PAT with ID: %s, err: %v", patID, zap.Error(err))
+ return nil, model.InternalError(fmt.Errorf("failed to fetch PAT"))
+ }
+
+ if len(pats) != 1 {
+ return nil, &model.ApiError{
+ Typ: model.ErrorInternal,
+ Err: fmt.Errorf("found zero or multiple PATS with same ID"),
+ }
+ }
+
+ return &pats[0], nil
+}