Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ definitions:
user_id:
type: integer
minimum: 1
name:
type: string

ProjectRequest:
type: object
Expand Down Expand Up @@ -1426,6 +1428,16 @@ paths:
- authentication
- user
summary: Create an API token
parameters:
- name: body
in: body
required: false
schema:
type: object
properties:
name:
type: string
example: "my CI token"
responses:
201:
description: API Token
Expand Down
2 changes: 2 additions & 0 deletions api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func createAPIToken(w http.ResponseWriter, r *http.Request) {
user := helpers.GetFromContext(r, "user").(*db.User)

var body struct {
Name string `json:"name"`
ExpiresAt *time.Time `json:"expires_at"`
}
if r.ContentLength > 0 {
Expand All @@ -94,6 +95,7 @@ func createAPIToken(w http.ResponseWriter, r *http.Request) {
UserID: user.ID,
Expired: false,
ExpiresAt: body.ExpiresAt,
Name: body.Name,
})
if err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions db/APIToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type APIToken struct {
Expired bool `db:"expired" json:"expired"`
ExpiresAt *time.Time `db:"expires_at" json:"expires_at,omitempty"`
UserID int `db:"user_id" json:"user_id"`
Name string `db:"name" json:"name"`
}

// IsExpiredAt reports whether the token is revoked or past its expiry.
Expand Down
1 change: 1 addition & 0 deletions db/sql/migrations/v2.18.2.err.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
alter table `user__token` drop `expires_at`;
alter table `user__token` drop `name`;
1 change: 1 addition & 0 deletions db/sql/migrations/v2.18.2.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
alter table `user__token` add `expires_at` datetime null;
alter table `user__token` add `name` varchar(255) not null default '';
12 changes: 12 additions & 0 deletions web/public/swagger/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ definitions:
user_id:
type: integer
minimum: 1
name:
type: string

ProjectRequest:
type: object
Expand Down Expand Up @@ -1415,6 +1417,16 @@ paths:
- authentication
- user
summary: Create an API token
parameters:
- name: body
in: body
required: false
schema:
type: object
properties:
name:
type: string
example: "my CI token"
responses:
201:
description: API Token
Expand Down
1 change: 1 addition & 0 deletions web/src/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export default {
status_stopped: 'Stopped',

api_tokens: 'API Tokens',
tokenName: 'Token Name',

// Terraform/OpenTofu/Terragrunt
auto_approve: 'Auto approve',
Expand Down
20 changes: 20 additions & 0 deletions web/src/views/Tokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
<v-btn color="primary" @click="newToken()">{{ $t('New Token') }}</v-btn>
</v-toolbar>

<v-dialog v-model="newTokenDialog" max-width="400" persistent>
<v-card>
<v-card-title>{{ $t('New Token') }}</v-card-title>
<v-card-text>
<v-text-field v-model="newTokenName" :label="$t('tokenName')"></v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text @click="cancelNewToken()">{{ $t('cancel') }}</v-btn>
<v-btn color="primary" @click="newToken()">{{ $t('create') }}</v-btn>
</v-card-actions>
</v-card>
</v-dialog>

<v-divider />

<v-data-table
Expand Down Expand Up @@ -137,6 +151,7 @@ export default {

data() {
return {
newTokenName: '',
newTokenDialog: false,
creatingToken: false,
expiresInDays: 0,
Expand All @@ -163,6 +178,7 @@ export default {
},

newToken() {
this.newTokenName = '';
this.expiresInDays = 0;
this.customExpiresAt = null;
this.newTokenDialog = true;
Expand Down Expand Up @@ -208,6 +224,10 @@ export default {

getHeaders() {
return [
{
text: this.$i18n.t('name'),
value: 'name',
},
{
text: this.$i18n.t('token'),
value: 'id',
Expand Down
Loading