Return-Path: X-Original-To: apmail-cloudstack-dev-archive@www.apache.org Delivered-To: apmail-cloudstack-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0E51118E07 for ; Wed, 27 Jan 2016 19:58:09 +0000 (UTC) Received: (qmail 32419 invoked by uid 500); 27 Jan 2016 19:58:08 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 32361 invoked by uid 500); 27 Jan 2016 19:58:08 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 32350 invoked by uid 99); 27 Jan 2016 19:58:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jan 2016 19:58:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5014ADFF96; Wed, 27 Jan 2016 19:58:08 +0000 (UTC) From: wido To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request: Add ability to download templates in Swif... Content-Type: text/plain Message-Id: <20160127195808.5014ADFF96@git1-us-west.apache.org> Date: Wed, 27 Jan 2016 19:58:08 +0000 (UTC) Github user wido commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1332#discussion_r51040885 --- Diff: utils/src/main/java/com/cloud/utils/SwiftUtil.java --- @@ -236,4 +247,60 @@ public static boolean deleteObject(SwiftClientCfg cfg, String path) { command.execute(parser); return true; } + + public static boolean setTempKey(SwiftClientCfg cfg, String tempKey){ + + Map tempKeyMap = new HashMap<>(); + tempKeyMap.put("Temp-URL-Key", tempKey); + return postMeta(cfg, "", "", tempKeyMap); + + } + + public static URL generateTempUrl(SwiftClientCfg cfg, String container, String object, String tempKey, int urlExpirationInterval) { + + int currentTime = (int) (System.currentTimeMillis() / 1000L); + int expirationSeconds = currentTime + urlExpirationInterval; + + try { + + URL endpoint = new URL(cfg.getEndPoint()); + String method = "GET"; + String path = String.format("/v1/AUTH_%s/%s/%s", cfg.getAccount(), container, object); + + //sign the request + String hmacBody = String.format("%s\n%d\n%s", method, expirationSeconds, path); + String signature = calculateRFC2104HMAC(hmacBody, tempKey); + path += String.format("?temp_url_sig=%s&temp_url_expires=%d", signature, expirationSeconds); + + //generate the temp url + URL tempUrl = new URL(endpoint.getProtocol(), endpoint.getHost(), endpoint.getPort(), path); + + return tempUrl; + + } catch (Exception e) { + logger.error(e.getMessage()); + throw new CloudRuntimeException(e.getMessage()); + } + + } + + + private static String calculateRFC2104HMAC(String data, String key) --- End diff -- Same here --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---