Skip to content

Commit

Permalink
fix: address carlos comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jul 27, 2023
1 parent e4408d3 commit 63baf48
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion server/backend/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func (d *Backend) UserByAccessToken(ctx context.Context, token string) (proto.Us
token = HashToken(token)

if err := d.db.TransactionContext(ctx, func(tx *db.Tx) error {
var err error
t, err := d.store.GetAccessTokenByToken(ctx, tx, token)
if err != nil {
return db.WrapError(err)
Expand Down
4 changes: 2 additions & 2 deletions server/ssh/cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func tokenCommand() *cobra.Command {
return tablewriter.Render(
cmd.OutOrStdout(),
tokens,
[]string{"ID", "Name", "Expires In", "Created At"},
[]string{"ID", "Name", "Created At", "Expires In"},
func(t proto.AccessToken) ([]string, error) {
expiresAt := "-"
if !t.ExpiresAt.IsZero() {
Expand All @@ -108,8 +108,8 @@ func tokenCommand() *cobra.Command {
return []string{
strconv.FormatInt(t.ID, 10),
t.Name,
expiresAt,
humanize.Time(t.CreatedAt),
expiresAt,
}, nil

Check warning on line 113 in server/ssh/cmd/token.go

View check run for this annotation

Codecov / codecov/patch

server/ssh/cmd/token.go#L108-L113

Added lines #L108 - L113 were not covered by tests
},
)
Expand Down
15 changes: 7 additions & 8 deletions server/store/database/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ var _ store.AccessTokenStore = (*accessTokenStore)(nil)

// CreateAccessToken implements store.AccessTokenStore.
func (s *accessTokenStore) CreateAccessToken(ctx context.Context, h db.Handler, name string, userID int64, token string, expiresAt time.Time) (models.AccessToken, error) {
query := `INSERT INTO access_tokens (name, user_id, token,`
vquery := `VALUES (?, ?, ?,`
queryWithoutExpires := `INSERT INTO access_tokens (name, user_id, token, created_at, updated_at)
VALUES (?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`
queryWithExpires := `INSERT INTO access_tokens (name, user_id, token, expires_at, created_at, updated_at)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`

query := queryWithoutExpires
values := []interface{}{name, userID, token}
if !expiresAt.IsZero() {
query += ` expires_at,`
vquery += ` ?,`
query = queryWithExpires
values = append(values, expiresAt)
}

Check warning on line 28 in server/store/database/access_token.go

View check run for this annotation

Codecov / codecov/patch

server/store/database/access_token.go#L17-L28

Added lines #L17 - L28 were not covered by tests

query += ` created_at, updated_at)`
vquery += ` CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`
query = h.Rebind(query + " " + vquery)

result, err := h.ExecContext(ctx, query, values...)
if err != nil {
return models.AccessToken{}, err
Expand Down
4 changes: 2 additions & 2 deletions server/web/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func serviceRpc(w http.ResponseWriter, r *http.Request) {
}

user := proto.UserFromContext(ctx)
cmd.Env = append(cmd.Env, cfg.Environ()...)
cmd.Env = cfg.Environ()
cmd.Env = append(cmd.Env, []string{
"SOFT_SERVE_REPO_NAME=" + repoName,
"SOFT_SERVE_REPO_PATH=" + dir,
Expand Down Expand Up @@ -478,7 +478,7 @@ func getInfoRefs(w http.ResponseWriter, r *http.Request) {
}

user := proto.UserFromContext(ctx)
cmd.Env = append(cmd.Env, cfg.Environ()...)
cmd.Env = cfg.Environ()
cmd.Env = append(cmd.Env, []string{
"SOFT_SERVE_REPO_NAME=" + repoName,
"SOFT_SERVE_REPO_PATH=" + dir,
Expand Down

0 comments on commit 63baf48

Please sign in to comment.