@@ -11,13 +11,17 @@ import (
1111
1212// AccessToken - auth tokens, can be created for the agents
1313type AccessToken struct {
14- ID string `json:"id"`
15- CreatedAt time.Time `json:"created_at"`
16- UpdatedAt time.Time `json:"updated_at"`
17- LastLogin string `json:"last_login"`
18- Description string `json:"description"`
19-
20- Active bool `json:"active"`
14+ ID string `json:"id"` // read-only
15+ CreatedAt time.Time `json:"created_at"` // read-only
16+ UpdatedAt time.Time `json:"updated_at"` // read-only
17+ LastLogin string `json:"last_login"` // read-only
18+ Description string `json:"description"`
19+ Scopes AccessTokenScopes `json:"scopes"`
20+ // APIAccess allows to enable/disabled API access. Tokens that have disabled
21+ // access can be used to subscribe to webhooks or tunnel connections.
22+ // Defaults to "enabled"
23+ APIAccess AccessTokenAPIAccess `json:"api_access"`
24+ Active bool `json:"active"`
2125}
2226
2327// MarshalJSON helper to marshal unix time
@@ -58,8 +62,26 @@ type AccessTokenCreateResponse struct {
5862 Secret string `json:"secret"`
5963}
6064
65+ // AccessTokenAPIAccess - enables/disables API access for the token
66+ type AccessTokenAPIAccess string
67+
68+ // Available API access token status
69+ const (
70+ AccessTokenAPIAccessEnabled AccessTokenAPIAccess = "enabled"
71+ AccessTokenAPIAccessDisabled AccessTokenAPIAccess = "disabled"
72+ )
73+
6174// AccessTokenCreateOptions - used to create an access token
6275type AccessTokenCreateOptions struct {
76+ Description string `json:"description"`
77+ Scopes AccessTokenScopes `json:"scopes"`
78+ APIAccess AccessTokenAPIAccess `json:"api_access"`
79+ }
80+
81+ // AccessTokenScopes define optional limits for tokens
82+ type AccessTokenScopes struct {
83+ Tunnels []string `json:"tunnels"`
84+ Buckets []string `json:"buckets"`
6385}
6486
6587// AccessTokenListOptions - TODO
@@ -109,6 +131,24 @@ func (api *API) DeleteAccessToken(options *AccessTokenDeleteOptions) error {
109131 return fmt .Errorf ("invalid access token ID '%s'" , options .ID )
110132 }
111133
112- _ , err := api .makeRequest ("DELETE" , "/buckets /" + options .ID , nil )
134+ _ , err := api .makeRequest (http . MethodDelete , "/tokens /" + options .ID , nil )
113135 return err
114136}
137+
138+ // UpdateAccessToken updates access token scopes, description and enabled/disable API access
139+ func (api * API ) UpdateAccessToken (options * AccessToken ) (* AccessToken , error ) {
140+ if ! IsUUID (options .ID ) {
141+ return nil , fmt .Errorf ("invalid access token ID '%s'" , options .ID )
142+ }
143+
144+ resp , err := api .makeRequest (http .MethodPut , "/tokens/" + options .ID , options )
145+ if err != nil {
146+ return nil , err
147+ }
148+
149+ var result AccessToken
150+ if err := json .Unmarshal (resp , & result ); err != nil {
151+ return nil , err
152+ }
153+ return & result , nil
154+ }
0 commit comments