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 654BC1875C for ; Thu, 21 Jan 2016 19:45:38 +0000 (UTC) Received: (qmail 72152 invoked by uid 500); 21 Jan 2016 19:45:38 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 72096 invoked by uid 500); 21 Jan 2016 19:45:37 -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 72085 invoked by uid 99); 21 Jan 2016 19:45:37 -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; Thu, 21 Jan 2016 19:45:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 81D3ADFF94; Thu, 21 Jan 2016 19:45:37 +0000 (UTC) From: syed 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: <20160121194537.81D3ADFF94@git1-us-west.apache.org> Date: Thu, 21 Jan 2016 19:45:37 +0000 (UTC) Github user syed commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1332#discussion_r50452491 --- 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("Unable to generate temperoary URL " + e.getMessage()); --- End diff -- rethrowing exception --- 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. ---