-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmanage.lisp
69 lines (57 loc) · 3.03 KB
/
manage.lisp
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
67
68
;;;; manage.lisp
;;;; Copyright (c) 2012, Rob Blackwell. All rights reserved.
(in-package #:cl-azure)
;; Experimental
;; The Windows Azure Service Management API is a REST API for managing your services and deployments.
;; See http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx
(defconstant +service-management-version+ "2011-02-25")
(defparameter *subscription-id* "YOUR_SUBSCRIPTION_ID")
(defparameter *management-certificate* (list
:certificate "~/YOUR_CERTIFICATE.pfx.pem"
:key "~/YOUR_CERTIFICATE.pfx.pem"
:pass-phrase "YOUR_PASSWORD"))
(defun management-request (method resource &key (content nil)
(management-certificate *management-certificate*)
(handler #'identity))
"Makes an HTTP request to the Windows Azure Service Management API"
(let ((headers (list (cons "x-ms-version" +service-management-version+))))
(funcall handler
(web-request (list
:certificate management-certificate
:method method
:uri resource
:content content
:content-type "application/xml"
:headers headers)))))
(defun list-service-name-elements-handler (response)
"Returns a list of the elements named ServiceName if the HTTP status is ok, otherwise raises an error."
(if (eq (response-status response) +HTTP-OK+)
(extract-named-elements (response-body response) "ServiceName")
(windows-azure-error response)))
(defun list-storage-accounts (&key (subscription-id *subscription-id*)
(management-certificate *management-certificate*)
(handler #'list-service-name-elements-handler))
"Lists the storage accounts available for a subscription."
(management-request :get (format nil "https://management.core.windows.net/~a/services/storageservices" subscription-id)
:management-certificate management-certificate
:handler handler))
(defun list-hosted-services ( &key (subscription-id *subscription-id*)
(management-certificate *management-certificate*)
(handler #'list-service-name-elements-handler))
"Lists the hosted services available for a subscription."
(management-request :get (format nil "https://management.core.windows.net/~a/services/hostedservices" subscription-id)
:management-certificate management-certificate
:handler handler))
(defun list-thumbprint-elements-handler (response)
"Returns a list of the elements named ServiceName if the HTTP status is ok, otherwise raises an error."
(if (eq (response-status response) +HTTP-OK+)
(extract-named-elements (response-body response) "Thumbprint")
(windows-azure-error response)))
(defun list-certificates (service-name &key (subscription-id *subscription-id*)
(management-certificate *management-certificate*)
(handler #'list-thumbprint-elements-handler))
"Lists all certificates associated with the specified hosted service."
(management-request :get (format nil "https://management.core.windows.net/~a/services/hostedservices/~a/certificates"
subscription-id service-name)
:management-certificate management-certificate
:handler handler))