Skip to content

Commit

Permalink
Fixes incorrect syntax in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefnoah committed Oct 28, 2023
1 parent 19f3b86 commit 33109cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/std/net/s3/api.ss
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
(def emptySHA256 (sha256 #u8()))

(def (S3Client
(endpoint "s3.amazonaws.com")
(access-key (getenv "AWS_ACCESS_KEY_ID" #f))
(secret-key (getenv "AWS_SECRET_ACCESS_KEY" #f))
(region (getenv "AWS_DEFAULT_REGION" "us-east-1")))
endpoint: (endpoint "s3.amazonaws.com")
access-key: (access-key (getenv "AWS_ACCESS_KEY_ID" #f))
secret-key: (secret-key (getenv "AWS_SECRET_ACCESS_KEY" #f))
region: (region (getenv "AWS_DEFAULT_REGION" "us-east-1")))
(cond
((not access-key)
(raise-s3-error make-s3-client "Must provide access key" "access-key"))
Expand All @@ -32,8 +32,7 @@
(S3 (make-s3-client endpoint access-key secret-key region)))

(defstruct s3-client (endpoint access-key secret-key region)
final: #t
constructor: S3Client)
final: #t)

(defstruct bucket (client name region)
final: #t)
Expand Down Expand Up @@ -103,16 +102,16 @@

(defmethod {bucket s3-client}
(lambda (self name)
(using (self self :- s3-client)
(using (self :- s3-client)
(if (s3-client::bucket-exists? self name)
(S3Bucket (make-bucket self name (s3-client-region self)))
(raise-s3-error s3-client::bucket "bucket does not exist" name)))))

; Lists the objects stored within the bucket
(defmethod {list-objects bucket}
(lambda (self)
(using ((self self :- bucket)
(client (self.client) :- s3-client))
(using ((self :- bucket)
(client self.client :- s3-client))
(let* ((name (bucket-name self))
(req (s3-request/error client verb: 'GET bucket: name))
(xml (s3-parse-xml req))
Expand All @@ -123,8 +122,10 @@
(defmethod {get bucket}
(lambda (self key)
(using ((self :- bucket)
(client (self.client) :- s3-client))
(let* ((req (s3-request/error client verb: 'GET bucket: (bucket-name self)
(client self.client :- s3-client))
(let* ((req (s3-request/error client
verb: 'GET
bucket: (bucket-name self)
path: (string-append "/" key)))
(data (request-content req)))
(request-close req)
Expand All @@ -133,7 +134,7 @@
(defmethod {put! bucket}
(lambda (self key data content-type: (content-type "binary/octet-stream"))
(using ((self :- bucket)
(client (self.client) :- s3-client))
(client self.client :- s3-client))
(let (req (s3-request/error client verb: 'PUT bucket: (bucket-name self)
path: (string-append "/" key)
body: data
Expand All @@ -144,7 +145,7 @@
(defmethod {delete! bucket}
(lambda (self key)
(using ((self :- bucket)
(client (self.client) :- s3-client))
(client self.client :- s3-client))
(let (req (s3-request/error client verb: 'DELETE bucket: (bucket-name self)
path: (string-append "/" key)))
(request-close req)
Expand All @@ -153,7 +154,7 @@
(defmethod {copy-to! bucket}
(lambda (self src dest)
(using ((self :- bucket)
(client (self.client) :- s3-client))
(client self.client :- s3-client))
(let* ((headers [["x-amz-copy-source" :: src]])
(req (s3-client::request client
verb: 'PUT
Expand Down
3 changes: 1 addition & 2 deletions src/std/net/s3/interface.ss
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
(get (name :~ string?))
(put! (name :~ string?)
(data :~ u8vector?)
; Additional options. See implementation for additional details
(opts :~ (maybe alist?) := #f))
content-type: (content-type := "octet-stream" :~ string?))
(delete! (name :~ string?))
; src should follow `bucket/file/path` format. Destination should just be `file/path`.
; Copies *from* src to *dest* in this ObjectMap.
Expand Down

0 comments on commit 33109cd

Please sign in to comment.