Skip to content

Commit

Permalink
Remove api key fetching from the actual queries
Browse files Browse the repository at this point in the history
Summary: This removes the actual fetching from SQL queries.

Test Plan: existing

Reviewers: michelle, vihang

Reviewed By: vihang

Differential Revision: https://phab.corp.pixielabs.ai/D9591

GitOrigin-RevId: 7c915f9
  • Loading branch information
zasgar authored and copybaranaut committed Aug 26, 2021
1 parent bff7832 commit c6ebdee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/cloud/auth/apikey/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func (s *Service) List(ctx context.Context, req *authpb.ListAPIKeyRequest) (*aut
}

// Return all keys when the OrgID matches.
query := `SELECT id, org_id, CONVERT_FROM(PGP_SYM_DECRYPT(encrypted_key, $2::text)::bytea, 'UTF8'), created_at, description
query := `SELECT id, org_id, created_at, description
FROM api_keys
WHERE org_id=$1
ORDER BY created_at`
rows, err := s.db.QueryxContext(ctx, query, sCtx.Claims.GetUserClaims().OrgID, s.dbKey)
rows, err := s.db.QueryxContext(ctx, query, sCtx.Claims.GetUserClaims().OrgID)
if err != nil {
if err == sql.ErrNoRows {
return &authpb.ListAPIKeyResponse{}, nil
Expand All @@ -127,10 +127,9 @@ func (s *Service) List(ctx context.Context, req *authpb.ListAPIKeyRequest) (*aut
for rows.Next() {
var id string
var orgID string
var key string
var createdAt time.Time
var desc string
err = rows.Scan(&id, &orgID, &key, &createdAt, &desc)
err = rows.Scan(&id, &orgID, &createdAt, &desc)
if err != nil {
log.WithError(err).Error("Failed to read data from postgres")
return nil, status.Error(codes.Internal, "failed to read data")
Expand Down
7 changes: 3 additions & 4 deletions src/cloud/vzmgr/deploymentkey/deployment_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func (s *Service) List(ctx context.Context, req *vzmgrpb.ListDeploymentKeyReques
}

// Return all clusters when the OrgID matches.
query := `SELECT id, org_id, CONVERT_FROM(PGP_SYM_DECRYPT(encrypted_key, $2::text)::bytea, 'UTF8'), created_at, description
query := `SELECT id, org_id, created_at, description
FROM vizier_deployment_keys
WHERE org_id=$1
ORDER BY created_at`
rows, err := s.db.QueryxContext(ctx, query, sCtx.Claims.GetUserClaims().OrgID, s.dbKey)
rows, err := s.db.QueryxContext(ctx, query, sCtx.Claims.GetUserClaims().OrgID)
if err != nil {
if err == sql.ErrNoRows {
return &vzmgrpb.ListDeploymentKeyResponse{}, nil
Expand All @@ -116,10 +116,9 @@ func (s *Service) List(ctx context.Context, req *vzmgrpb.ListDeploymentKeyReques
for rows.Next() {
var id string
var orgID string
var key string
var createdAt time.Time
var desc string
err = rows.Scan(&id, &orgID, &key, &createdAt, &desc)
err = rows.Scan(&id, &orgID, &createdAt, &desc)
if err != nil {
log.WithError(err).Error("Failed to read data from postgres")
return nil, status.Error(codes.Internal, "failed to read data")
Expand Down

0 comments on commit c6ebdee

Please sign in to comment.