Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
nazoking committed Nov 27, 2014
1 parent 4f0c0df commit 727c0df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
6 changes: 3 additions & 3 deletions org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ static class TailMatcher {
private Pattern tailPattern;

public TailMatcher(String pattern) {
String p = "(^|/)"
+ Pattern.quote(pattern).replaceAll("\\*", "\\\\E.*\\\\Q")
+ "$";
String p = "(^|/)" //$NON-NLS-1$
+ Pattern.quote(pattern).replaceAll("\\*", "\\\\E.*\\\\Q") //$NON-NLS-1$ //$NON-NLS-2$
+ "$"; //$NON-NLS-1$
tailPattern = Pattern.compile(p);
}

Expand Down
6 changes: 3 additions & 3 deletions org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ private HttpURLConnection open(final String method, final String bucket,
}

private void authorize(final HttpURLConnection c) throws IOException {
if(token != null){
c.setRequestProperty("x-amz-security-token", token);
}
if (token != null) {
c.setRequestProperty("x-amz-security-token", token); //$NON-NLS-1$
}
final Map<String, List<String>> reqHdr = c.getRequestProperties();
final SortedMap<String, String> sigHdr = new TreeMap<String, String>();
for (final Map.Entry<String, List<String>> entry : reqHdr.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public Transport open(URIish uri) throws NotSupportedException {
* <code>keyPrefix + "/"</code>.
*/
private final String keyPrefix;

TransportAmazonS3(final Repository local, final URIish uri)
throws NotSupportedException {
super(local, uri);
Expand Down Expand Up @@ -181,13 +182,13 @@ public Transport open(URIish uri) throws NotSupportedException {
}

private Properties loadProperties() throws NotSupportedException {
if ("IAM".equals(uri.getUser())) {
try{
return instanceCredentialProfile();
}catch(IOException e){
throw new RuntimeException(e);
}
}
if ("IAM".equals(uri.getUser())) { //$NON-NLS-1$
try {
return instanceCredentialProfile();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
File propsFile;
if (local != null) {
if (local.getDirectory() != null) {
Expand Down Expand Up @@ -218,33 +219,38 @@ private Properties loadProperties() throws NotSupportedException {
return props;
}

private static final Pattern jsonStringPropertyPattern = Pattern.compile("\"([^\"]*)\"\\s*:\\s*\"([^\"]*)\"");
private static final String roleUrl = "http://169.254.169.254/latest/meta-data/iam/security-credentials/";
private static Properties instanceCredentialProfile() throws IOException{
private static final Pattern jsonStringPropertyPattern = Pattern
.compile("\"([^\"]*)\"\\s*:\\s*\"([^\"]*)\""); //$NON-NLS-1$

private static final String roleUrl = "http://169.254.169.254/latest/meta-data/iam/security-credentials/"; //$NON-NLS-1$

private static Properties instanceCredentialProfile() throws IOException {
Properties props = new Properties();
String role = getHttpBody(roleUrl);
String jsonBody = getHttpBody(roleUrl+role);
Matcher matcher = jsonStringPropertyPattern.matcher(jsonBody);
HashMap<String,String> values = new HashMap<String,String>();
while(matcher.find()){
values.put(matcher.group(1),matcher.group(2));
}
props.setProperty("accesskey", values.get("AccessKeyId"));
props.setProperty("secretkey", values.get("SecretAccessKey"));
props.setProperty("token", values.get("Token"));
return props;
}
private static String getHttpBody(String url) throws IOException{
final URL u = new URL(url);
final HttpURLConnection c = (HttpURLConnection) u.openConnection();
final InputStream in = c.getInputStream();
final int len = c.getContentLength();
try {
return new String(IO.readWholeStream(in, len == -1 ? 1000 : len).array(), "UTF-8");
} finally {
in.close();
}
}
String role = getHttpBody(roleUrl);
String jsonBody = getHttpBody(roleUrl + role);
Matcher matcher = jsonStringPropertyPattern.matcher(jsonBody);
HashMap<String, String> values = new HashMap<String, String>();
while (matcher.find()) {
values.put(matcher.group(1), matcher.group(2));
}
props.setProperty("accesskey", values.get("AccessKeyId")); //$NON-NLS-1$ //$NON-NLS-2$
props.setProperty("secretkey", values.get("SecretAccessKey")); //$NON-NLS-1$ //$NON-NLS-2$
props.setProperty("token", values.get("Token")); //$NON-NLS-1$ //$NON-NLS-2$
return props;
}

private static String getHttpBody(String url) throws IOException {
final URL u = new URL(url);
final HttpURLConnection c = (HttpURLConnection) u.openConnection();
final InputStream in = c.getInputStream();
final int len = c.getContentLength();
try {
return new String(IO.readWholeStream(in, len == -1 ? 1000 : len)
.array(), "UTF-8"); //$NON-NLS-1$
} finally {
in.close();
}
}

private static Properties loadPropertiesFile(File propsFile)
throws NotSupportedException {
Expand Down

0 comments on commit 727c0df

Please sign in to comment.