@@ -3,8 +3,10 @@ package linodego
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "time"
78
9+ "github.com/google/go-querystring/query"
810 "github.com/linode/linodego/internal/parseabletime"
911)
1012
@@ -34,6 +36,22 @@ type ObjectStorageBucketAccess struct {
3436 CorsEnabled bool `json:"cors_enabled"`
3537}
3638
39+ // ObjectStorageBucketContent holds the content of an ObjectStorageBucket
40+ type ObjectStorageBucketContent struct {
41+ Data []ObjectStorageBucketContentData `json:"data"`
42+ IsTruncated bool `json:"is_truncated"`
43+ NextMarker * string `json:"next_marker"`
44+ }
45+
46+ // ObjectStorageBucketContentData holds the data of the content of an ObjectStorageBucket
47+ type ObjectStorageBucketContentData struct {
48+ Etag string `json:"etag"`
49+ LastModified * time.Time `json:"last_modified"`
50+ Name string `json:"name"`
51+ Owner string `json:"owner"`
52+ Size int `json:"size"`
53+ }
54+
3755// UnmarshalJSON implements the json.Unmarshaler interface
3856func (i * ObjectStorageBucket ) UnmarshalJSON (b []byte ) error {
3957 type Mask ObjectStorageBucket
@@ -76,6 +94,14 @@ type ObjectStorageBucketUpdateAccessOptions struct {
7694 CorsEnabled * bool `json:"cors_enabled,omitempty"`
7795}
7896
97+ // ObjectStorageBucketListContentsParams fields are the query parameters for ListObjectStorageBucketContents
98+ type ObjectStorageBucketListContentsParams struct {
99+ Marker * string
100+ Delimiter * string
101+ Prefix * string
102+ PageSize * int
103+ }
104+
79105// ObjectStorageACL options start with ACL and include all known ACL types
80106type ObjectStorageACL string
81107
@@ -154,3 +180,20 @@ func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterOrRegionI
154180 err := doDELETERequest (ctx , c , e )
155181 return err
156182}
183+
184+ // Lists the contents of the specified ObjectStorageBucket
185+ func (c * Client ) ListObjectStorageBucketContents (ctx context.Context , clusterOrRegionID , label string , params * ObjectStorageBucketListContentsParams ) (* ObjectStorageBucketContent , error ) {
186+ basePath := formatAPIPath ("object-storage/buckets/%s/%s/object-list" , clusterOrRegionID , label )
187+
188+ queryString := ""
189+ if params != nil {
190+ values , err := query .Values (params )
191+ if err != nil {
192+ return nil , fmt .Errorf ("failed to encode query params: %w" , err )
193+ }
194+ queryString = "?" + values .Encode ()
195+ }
196+
197+ e := basePath + queryString
198+ return doGETRequest [ObjectStorageBucketContent ](ctx , c , e )
199+ }
0 commit comments