forked from playframework/play1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Erwan Loisant
committed
Mar 29, 2010
1 parent
7a1b7f5
commit 6d33362
Showing
6 changed files
with
172 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from framework.pym.utils import * | ||
|
||
NAMES = ['secret'] | ||
|
||
def execute(**kargs): | ||
app = kargs.get("app") | ||
|
||
app.check() | ||
print "~ Generating the secret key..." | ||
sk = secretKey() | ||
replaceAll(os.path.join(app.path, 'conf', 'application.conf'), r'application.secret=.*', 'application.secret=%s' % sk) | ||
print "~ Keep the secret : %s" % sk | ||
print "~" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os, os.path | ||
import shutil | ||
import getopt | ||
import hmac | ||
import urllib2 | ||
from hashlib import sha1 as sha | ||
|
||
from framework.pym.utils import * | ||
|
||
NAMES = ['status', 'st'] | ||
|
||
def execute(**kargs): | ||
app = kargs.get("app") | ||
args = kargs.get("args") | ||
play_env = kargs.get("env") | ||
|
||
url = '' | ||
secret_key = '' | ||
|
||
try: | ||
optlist, args = getopt.getopt(remaining_args, '', ['url=', 'secret=']) | ||
for o, a in optlist: | ||
if o in ('--url'): | ||
if a.endswith('/'): | ||
url = a + '@status' | ||
else: | ||
url = a + '/@status' | ||
if o in ('--secret'): | ||
secret_key = a | ||
except getopt.GetoptError, err: | ||
print "~ %s" % str(err) | ||
print "~ " | ||
sys.exit(-1) | ||
|
||
if not url or not secret_key: | ||
app.check() | ||
if not url: | ||
http_port = int(play_app.readConf('http.port')) | ||
url = 'http://localhost:%s/@status' % http_port | ||
if not secret_key: | ||
secret_key = play_app.readConf('application.secret') | ||
|
||
hm = hmac.new(secret_key, '@status', sha) | ||
authorization = hm.hexdigest() | ||
|
||
try: | ||
proxy_handler = urllib2.ProxyHandler({}) | ||
req = urllib2.Request(url) | ||
req.add_header('Authorization', authorization) | ||
opener = urllib2.build_opener(proxy_handler) | ||
status = opener.open(req); | ||
print '~ Status from %s,' % url | ||
print '~' | ||
print status.read() | ||
print '~' | ||
except urllib2.HTTPError, e: | ||
print "~ Cannot retrieve the application status... (%s)" % (e.code) | ||
print "~" | ||
sys.exit(-1) | ||
except urllib2.URLError, e: | ||
print "~ Cannot contact the application..." | ||
print "~" | ||
sys.exit(-1) | ||
Oops, something went wrong.