2 ;;;; Copyright (c) 2008 Zachary Beane, All Rights Reserved
4 ;;;; Redistribution and use in source and binary forms, with or without
5 ;;;; modification, are permitted provided that the following conditions
8 ;;;; * Redistributions of source code must retain the above copyright
9 ;;;; notice, this list of conditions and the following disclaimer.
11 ;;;; * Redistributions in binary form must reproduce the above
12 ;;;; copyright notice, this list of conditions and the following
13 ;;;; disclaimer in the documentation and/or other materials
14 ;;;; provided with the distribution.
16 ;;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
17 ;;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 ;;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ;;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 ;;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 ;;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 ;;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 ;;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ;;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 ;;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ;;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 (defvar *credentials
* nil
33 "Used as the default initarg value of :CREDENTIALS when creating a
36 (define-condition unsupported-credentials
(error)
39 :accessor unsupported-credentials-object
))
40 (:report
(lambda (c s
)
41 (format s
"The value ~A is unsupported as S3 credentials. (Did you set *CREDENTIALS*?)~@
42 See http://www.xach.com/lisp/zs3/#*credentials* ~
43 for supported credentials formats."
44 (unsupported-credentials-object c
)))))
46 (defgeneric access-key
(credentials)
48 (error 'unsupported-credentials
:object object
))
49 (:method
((list cons
))
52 (defgeneric secret-key
(credentials)
54 (error 'unsupported-credentials
:object object
))
55 (:method
((list cons
))
59 ;;; Lazy-loading credentials
61 (defclass lazy-credentials-mixin
() ())
63 (defmethod slot-unbound (class (credentials lazy-credentials-mixin
)
64 (slot (eql 'access-key
)))
65 (nth-value 0 (initialize-lazy-credentials credentials
)))
67 (defmethod slot-unbound (class (credentials lazy-credentials-mixin
)
68 (slot (eql 'secret-key
)))
69 (nth-value 1 (initialize-lazy-credentials credentials
)))
72 ;;; Loading credentials from a file
74 (defclass file-credentials
(lazy-credentials-mixin)
81 :accessor secret-key
)))
83 (defgeneric initialize-lazy-credentials
(credentials)
84 (:method
((credentials file-credentials
))
85 (with-open-file (stream (file credentials
))
86 (values (setf (access-key credentials
) (read-line stream
))
87 (setf (secret-key credentials
) (read-line stream
))))))
89 (defun file-credentials (file)
90 (make-instance 'file-credentials