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<String, String> 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---