Skip to content

Commit

Permalink
Add virtual file system storage attachment list route
Browse files Browse the repository at this point in the history
  • Loading branch information
optik-aper committed Dec 12, 2024
1 parent db4cb61 commit 7dcaa7d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion virtual_file_system_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type VirtualFileSystemStorageService interface {
Delete(ctx context.Context, vfsID string) error
List(ctx context.Context, options *ListOptions) ([]VirtualFileSystemStorage, *Meta, *http.Response, error)

Attach(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error)
AttachmentList(ctx context.Context, vfsID string) ([]VirtualFileSystemStorageAttachment, *http.Response, error)
AttachmentGet(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error)
Attach(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error)
Detach(ctx context.Context, vfsID, targetID string) error
}

Expand Down Expand Up @@ -90,6 +91,10 @@ type VirtualFileSystemStorageAttachment struct {
TargetID string `json:"target_id"`
}

type virtualFileSystemStorageAttachmentsBase struct {
Attachments []VirtualFileSystemStorageAttachment `json:"attachments"`
}

// Create sends a create request for a virtual file system storage.
func (f *VirtualFileSystemStorageServiceHandler) Create(ctx context.Context, vfsReq *VirtualFileSystemStorageReq) (*VirtualFileSystemStorage, *http.Response, error) { //nolint:lll
req, err := f.client.NewRequest(ctx, http.MethodPost, virtualFileSystemStoragePath, vfsReq)
Expand Down Expand Up @@ -196,6 +201,25 @@ func (f *VirtualFileSystemStorageServiceHandler) Attach(ctx context.Context, vfs
return att, resp, err
}

// AttachmentList retrieves a list the active attachments on a virtual file
// system storage.
func (f *VirtualFileSystemStorageServiceHandler) AttachmentList(ctx context.Context, vfsID string) ([]VirtualFileSystemStorageAttachment, *http.Response, error) { //nolint:lll
uri := fmt.Sprintf("%s/%s/attachments", virtualFileSystemStoragePath, vfsID)

req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, nil, err
}

atts := new(virtualFileSystemStorageAttachmentsBase)
resp, err := f.client.DoWithContext(ctx, req, atts)
if err != nil {
return nil, resp, err
}

return atts.Attachments, resp, err
}

// AttachmentGet retrieves the attachment of a virtual file system storage and
// its attached instance.
func (f *VirtualFileSystemStorageServiceHandler) AttachmentGet(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error) { //nolint:lll
Expand Down

0 comments on commit 7dcaa7d

Please sign in to comment.