Skip to content

Commit 7629636

Browse files
committed
Merge branch 'personal-token-types' into 'master'
fix: remove personal token types See merge request postgres-ai/database-lab!766
2 parents 2d09655 + b679790 commit 7629636

File tree

3 files changed

+5
-32
lines changed

3 files changed

+5
-32
lines changed

engine/internal/platform/platform.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"errors"
1111
"fmt"
1212
"net/url"
13-
"time"
1413

1514
"gitlab.com/postgres-ai/database-lab/v3/pkg/client/platform"
1615
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
@@ -42,8 +41,6 @@ type Service struct {
4241
// Token defines verified Platform Token.
4342
type Token struct {
4443
OrganizationID uint
45-
TokenType string
46-
ValidUntil *time.Time
4744
}
4845

4946
// New creates a new platform service.
@@ -84,8 +81,6 @@ func New(ctx context.Context, cfg Config, instanceID string) (*Service, error) {
8481

8582
s.token = Token{
8683
OrganizationID: platformToken.OrganizationID,
87-
TokenType: platformToken.TokenType,
88-
ValidUntil: platformToken.ValidUntil,
8984
}
9085
}
9186

@@ -100,16 +95,16 @@ func (s *Service) Reload(newService *Service) {
10095
// IsAllowedToken checks if the Platform Personal Token is allowed.
10196
func (s *Service) IsAllowedToken(ctx context.Context, personalToken string) bool {
10297
if !s.IsPersonalTokenEnabled() {
103-
return true
98+
return false
10499
}
105100

106101
platformToken, err := s.Client.CheckPlatformToken(ctx, platform.TokenCheckRequest{Token: personalToken})
107102
if err != nil {
108103
return false
109104
}
110105

111-
if platformToken.TokenType != platform.PersonalType {
112-
log.Dbg(fmt.Sprintf("Non-personal token given: %s", platformToken.TokenType))
106+
if !platformToken.Personal {
107+
log.Dbg("Non-personal token given")
113108

114109
return false
115110
}

engine/pkg/client/platform/client_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"io"
1212
"net/http"
1313
"testing"
14-
"time"
1514

1615
"github.com/stretchr/testify/assert"
1716
"github.com/stretchr/testify/require"
@@ -128,13 +127,8 @@ func TestClientChecksPlatformToken(t *testing.T) {
128127
}
129128

130129
func TestClientChecksPlatformSEToken(t *testing.T) {
131-
validDateTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00")
132-
require.NoError(t, err)
133-
134130
expectedResponse := TokenCheckResponse{
135131
OrganizationID: 2,
136-
TokenType: HashType,
137-
ValidUntil: &validDateTime,
138132
}
139133

140134
testClient := NewTestClient(func(req *http.Request) *http.Response {
@@ -158,8 +152,6 @@ func TestClientChecksPlatformSEToken(t *testing.T) {
158152
require.NoError(t, err)
159153

160154
assert.Equal(t, expectedResponse.OrganizationID, platformToken.OrganizationID)
161-
assert.Equal(t, expectedResponse.ValidUntil, platformToken.ValidUntil)
162-
assert.Equal(t, expectedResponse.TokenType, platformToken.TokenType)
163155
assert.False(t, platformToken.Personal)
164156
}
165157

engine/pkg/client/platform/token.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@ package platform
88
import (
99
"context"
1010
"fmt"
11-
"time"
1211

1312
"github.com/pkg/errors"
1413

1514
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
1615
)
1716

18-
const (
19-
// PersonalType defines personal type of the Platform token.
20-
PersonalType = "personal"
21-
22-
// AdminType defines administrative type of the Platform token.
23-
AdminType = "admin"
24-
25-
// HashType defines hash type of the Platform token.
26-
HashType = "hash"
27-
)
28-
2917
// TokenCheckRequest represents a token checking request.
3018
type TokenCheckRequest struct {
3119
Token string `json:"token"`
@@ -34,10 +22,8 @@ type TokenCheckRequest struct {
3422
// TokenCheckResponse represents response of a token checking request.
3523
type TokenCheckResponse struct {
3624
APIResponse
37-
OrganizationID uint `json:"org_id"`
38-
Personal bool `json:"is_personal"`
39-
TokenType string `json:"token_type"`
40-
ValidUntil *time.Time `json:"valid_until"`
25+
OrganizationID uint `json:"org_id"`
26+
Personal bool `json:"is_personal"`
4127
}
4228

4329
// CheckPlatformToken makes an HTTP request to check the Platform Access Token.

0 commit comments

Comments
 (0)