-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathlocks.go
More file actions
66 lines (56 loc) · 2.02 KB
/
locks.go
File metadata and controls
66 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package linodego
import (
"context"
)
// LockType represents the type of lock that can be applied to a resource
// NOTE: Locks can only be used with v4beta.
type LockType string
// LockType enums
const (
LockTypeCannotDelete LockType = "cannot_delete"
LockTypeCannotDeleteWithSubresources LockType = "cannot_delete_with_subresources"
)
// LockedEntity represents the entity that is locked
// NOTE: Locks can only be used with v4beta.
type LockedEntity struct {
ID int `json:"id"`
Type EntityType `json:"type"`
Label string `json:"label"`
URL string `json:"url"`
}
// Lock represents a resource lock
// NOTE: Locks can only be used with v4beta.
type Lock struct {
ID int `json:"id"`
LockType LockType `json:"lock_type"`
Entity LockedEntity `json:"entity"`
}
// LockCreateOptions fields are those accepted by CreateLock
// NOTE: Locks can only be used with v4beta.
type LockCreateOptions struct {
EntityType EntityType `json:"entity_type"`
EntityID int `json:"entity_id"`
LockType LockType `json:"lock_type"`
}
// ListLocks returns a paginated list of Locks
// NOTE: Locks can only be used with v4beta.
func (c *Client) ListLocks(ctx context.Context, opts *ListOptions) ([]Lock, error) {
return getPaginatedResults[Lock](ctx, c, "locks", opts)
}
// GetLock gets a single Lock with the provided ID
// NOTE: Locks can only be used with v4beta.
func (c *Client) GetLock(ctx context.Context, lockID int) (*Lock, error) {
e := formatAPIPath("locks/%d", lockID)
return doGETRequest[Lock](ctx, c, e)
}
// CreateLock creates a lock for a resource
// NOTE: Locks can only be used with v4beta.
func (c *Client) CreateLock(ctx context.Context, opts LockCreateOptions) (*Lock, error) {
return doPOSTRequest[Lock](ctx, c, "locks", opts)
}
// DeleteLock deletes a single Lock with the provided ID
// NOTE: Locks can only be used with v4beta.
func (c *Client) DeleteLock(ctx context.Context, lockID int) error {
e := formatAPIPath("locks/%d", lockID)
return doDELETERequest(ctx, c, e)
}