Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 00d6aa5

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 3d5433d + 09f20eb commit 00d6aa5

17 files changed

Lines changed: 619 additions & 144 deletions

README.md

Lines changed: 236 additions & 58 deletions
Large diffs are not rendered by default.

build.gradle

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ plugins {
33
id 'eclipse'
44
id "maven"
55
id "maven-publish"
6-
id 'net.saliman.cobertura' version '2.3.0'
7-
id "com.jfrog.bintray" version "1.6"
6+
id 'net.saliman.cobertura' version '2.3.2'
7+
id "com.jfrog.bintray" version "1.7"
88
id 'co.riiid.gradle' version '0.4.2'
9-
id 'synapticloop.documentr' version '1.3.4'
9+
id 'synapticloop.documentr' version '2.6.1'
10+
id 'com.github.ben-manes.versions' version '0.13.0'
1011
}
1112

1213
group = 'synapticloop'
1314
archivesBaseName = 'backblaze-b2-java-api'
1415
description = """A java api for the truly excellent backblaze b2 storage service"""
1516

16-
version = '2.0.2'
17+
version = '2.1.3'
1718

1819
sourceCompatibility = 1.7
1920
targetCompatibility = 1.7
@@ -27,25 +28,25 @@ repositories {
2728
}
2829

2930
dependencies {
30-
runtime 'org.apache.httpcomponents:httpclient:4.5.1'
31-
runtime 'commons-io:commons-io:2.4'
32-
runtime 'org.json:json:20160212'
31+
runtime 'org.apache.httpcomponents:httpclient:4.5.2'
32+
runtime 'commons-io:commons-io:2.5'
33+
runtime 'org.json:json:20160810'
3334
runtime 'org.slf4j:slf4j-api:1.7.13'
3435

35-
compile 'org.apache.httpcomponents:httpclient:4.5.1'
36-
compile 'commons-io:commons-io:2.4'
37-
compile 'org.json:json:20160212'
36+
compile 'org.apache.httpcomponents:httpclient:4.5.2'
37+
compile 'commons-io:commons-io:2.5'
38+
compile 'org.json:json:20160810'
3839
compile 'org.slf4j:slf4j-api:1.7.13'
3940

4041
testCompile 'junit:junit:4.12'
41-
testCompile 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
42-
testCompile 'org.apache.logging.log4j:log4j-core:2.5'
43-
testCompile 'org.json:json:20160212'
42+
testCompile 'org.apache.logging.log4j:log4j-slf4j-impl:2.7'
43+
testCompile 'org.apache.logging.log4j:log4j-core:2.7'
44+
testCompile 'org.json:json:20160810'
4445

4546
testRuntime 'junit:junit:4.12'
46-
testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
47-
testRuntime 'org.apache.logging.log4j:log4j-core:2.5'
48-
testRuntime 'org.json:json:20160212'
47+
testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.7'
48+
testRuntime 'org.apache.logging.log4j:log4j-core:2.7'
49+
testRuntime 'org.json:json:20160810'
4950
}
5051

5152
configurations.all {

documentr.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
{ "type":"inbuilt", "value":"project-name" },
1111
{ "type":"inbuilt", "value":"project-description" },
1212

13+
{ "type": "markup", "value": "\n\n# Table of Contents\n\n" },
14+
15+
{ "type": "toc", "value": "2" },
16+
{ "type": "toclinks", "value": "true" },
17+
{ "type": "toplink", "value": " <a name=\"#documentr_top\"></a>" },
18+
{ "type": "tocbacktotop", "value": " <sup><sup>[top](#documentr_top)</sup></sup>" },
19+
1320
{ "type":"file", "value":"src/docs/gui.md" },
1421

15-
{ "type":"file", "value":"src/docs/usage.md" },
22+
{ "type":"file", "value":"src/docs/usage-001.md" },
23+
24+
{ "type":"file", "value":"src/test/java/synapticloop/b2/QuickExampleMain.java" },
25+
26+
{ "type":"file", "value":"src/docs/usage-002.md" },
1627

1728
{ "type":"inbuilt", "value":"gradle-build" },
1829
{ "type":"inbuilt", "value":"gradle-test" },

src/docs/usage-001.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Usage
2+
3+
```
4+
5+
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
# Usage
21

3-
```
4-
// required imports
5-
import synapticloop.b2.B2ApiClient;
6-
import synapticloop.b2.exception.B2ApiException;
7-
import synapticloop.b2.request.*;
8-
import synapticloop.b2.response.*;
9-
10-
11-
String b2AccountId = ""; // your b2 account ID
12-
String b2ApplicationKey = ""; // your b2 application Key
13-
14-
B2ApiClient b2ApiClient = new B2ApiClient();
15-
b2ApiClient.authorize(b2AccountId, b2ApplicationKey);
16-
17-
// now create a private bucket
18-
B2BucketResponse createPrivateBucket = b2ApiClient.createBucket("super-secret-bucket" , BucketType.ALL_PRIVATE);
19-
20-
// or a public one
21-
B2BucketResponse createPublicBucket = b2ApiClient.createBucket("everyone-has-access" , BucketType.ALL_PUBLIC);
22-
23-
// upload a file
24-
b2ApiClient.uploadFile(createPrivateBucket.getBucketId(), "myfile.txt", new File("/tmp/temporary-file.txt"));
252
```
263
274
see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blob/master/src/main/java/synapticloop/b2/B2ApiClient.java) for a complete list of relatively self-explanatory methods.
@@ -30,18 +7,15 @@ see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blo
307
// create a new B2ApiClient
318
B2ApiClient()
329

33-
// authorize the client
34-
authorize(String, String)
10+
// authenticate the client
11+
authenticate(String, String)
3512

3613
// create a bucket
3714
createBucket(String, BucketType)
3815

3916
// delete bucket
4017
deleteBucket(String)
4118

42-
// delete bucket and all containing files
43-
deleteBucketFully(String)
44-
4519
// delete a version of a file
4620
deleteFileVersion(String, String)
4721

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package synapticloop.b2;
2+
3+
import org.json.JSONObject;
4+
5+
/*
6+
* Copyright (c) 2016 Synapticloop.
7+
*
8+
* All rights reserved.
9+
*
10+
* This code may contain contributions from other parties which, where
11+
* applicable, will be listed in the default build file for the project
12+
* ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project.
13+
*
14+
* This source code and any derived binaries are covered by the terms and
15+
* conditions of the Licence agreement ("the Licence"). You may not use this
16+
* source code or any derived binaries except in compliance with the Licence.
17+
* A copy of the Licence is available in the file named LICENSE.txt shipped with
18+
* this source code or binaries.
19+
*/
20+
21+
/**
22+
* <p>Lifecycle rules instruct the B2 service to automatically hide and/or delete
23+
* old files. You can set up rules to do things like delete old versions of
24+
* files 30 days after a newer version was uploaded.</p>
25+
*
26+
* <p>A bucket can have up to 100 lifecycle rules. Each rule has a fileNamePrefix
27+
* that specifies which files in the bucket it applies to. Any file whose name
28+
* starts with the prefix is subject to the rule. A prefix of the empty string,
29+
* "", means that the rule applies to all files in the bucket.</p>
30+
*
31+
* <p>You're not allowed to create two rules that both apply to the same files.
32+
* For example, a rule with a file name prefix of photos/ and a rule with a file
33+
* name prefix of photos/kittens/ would both apply to a file named
34+
* photos/kittens/fluffy.jpg, so you're not allowed to have both rules at the
35+
* same time.</p>
36+
*
37+
* <p>Each lifecycle rule specifies two things:</p>
38+
*
39+
* <ul>
40+
* <li>daysFromUploadingToHiding and</li>
41+
* <li>daysFromHidingToDeleting.</li>
42+
* </ul>
43+
*
44+
* <p>Either can be null, which means that part of the rule doesn't apply. Setting
45+
* both to null is not allowed, because the rule would do nothing.</p>
46+
*
47+
* <p>Setting daysFromUploadingToHiding to 0 is not allowed. When set, it must be a
48+
* positive number.</p>
49+
*
50+
* <p>The most commonly used setting is daysFromHidingToDeleting, which says how long
51+
* to keep file versions that are not the current version. A file version counts
52+
* as hidden when explicitly hidden with b2_hide_file, or when a newer file with
53+
* the same name is uploaded. When a rule with this setting applies, the file will
54+
* be deleted the given number of days after it is hidden.</p>
55+
*
56+
* <p>For example, if you are backing up your files to B2 using the B2 command-line
57+
* tool, or another software package that uploads files when they change, B2 will
58+
* keep old versions of the file. This is very helpful, because it means the old
59+
* versions are there if the original file is accidentally deleted. On the other
60+
* hand, keeping them forever can clutter things up. For an application like this,
61+
* you might want a lifecycle rule that keeps old versions in the backup/ folder
62+
* for 30 days, and then deletes them:</p>
63+
*
64+
* <pre>
65+
{
66+
"daysFromHidingToDeleting": 30,
67+
"daysFromUploadingToHiding": null,
68+
"fileNamePrefix": "backup/"
69+
}
70+
* </pre>
71+
*
72+
* <p>The daysFromUploadingToHiding setting is less frequently used. It causes files to
73+
* be hidden automatically after the given number of days. This can be useful for things
74+
* like server log files that can be deleted after a while. This rule will keep files
75+
* in the logs/ folder for 7 days, and then hide and immediately delete them:</p>
76+
*
77+
* <pre>
78+
{
79+
"daysFromHidingToDeleting": 0,
80+
"daysFromUploadingToHiding": 7,
81+
"fileNamePrefix": "logs/"
82+
}
83+
* </pre>
84+
*
85+
* <p>The API calls related to lifecycle rules are:</p>
86+
*
87+
* <ul>
88+
* <li>b2_create_bucket - creates a new bucket</li>
89+
* <li>b2_update_bucket - changes the settings on a bucket</li>
90+
* </ul>
91+
*
92+
* <p>When you create a new bucket, you can specify the lifecycle rules. Later,
93+
* you can change the rules on a bucket by updating it.</p>
94+
*
95+
* @author synapticloop
96+
*
97+
*/
98+
public class LifecycleRule {
99+
private final Long daysFromHidingToDeleting;
100+
private final Long daysFromUploadingToHiding;
101+
private final String fileNamePrefix;
102+
103+
public LifecycleRule(Long daysFromHidingToDeleting, Long daysFromUploadingToHiding, String fileNamePrefix) {
104+
this.daysFromHidingToDeleting = daysFromHidingToDeleting;
105+
this.daysFromUploadingToHiding = daysFromUploadingToHiding;
106+
this.fileNamePrefix = fileNamePrefix;
107+
}
108+
109+
public LifecycleRule(JSONObject jsonObject) {
110+
long hide = jsonObject.optLong("daysFromHidingToDeleting", Long.MIN_VALUE);
111+
if(hide == Long.MIN_VALUE) {
112+
daysFromHidingToDeleting = null;
113+
} else {
114+
daysFromHidingToDeleting = hide;
115+
}
116+
117+
long upload = jsonObject.optLong("daysFromUploadingToHiding", Long.MIN_VALUE);
118+
if(upload == Long.MIN_VALUE) {
119+
daysFromUploadingToHiding = null;
120+
} else {
121+
daysFromUploadingToHiding = upload;
122+
}
123+
124+
fileNamePrefix = jsonObject.optString("fileNamePrefix", null);
125+
}
126+
127+
/**
128+
* The number of days from when the file was hidden to when it will be deleted
129+
*
130+
* @return the number of days from hiding to deleting
131+
*/
132+
public Long getDaysFromHidingToDeleting() { return this.daysFromHidingToDeleting; }
133+
134+
/**
135+
* The number of days from when the file was uploaded to when it will be deleted
136+
*
137+
* @return the number of days from uploading to deleting
138+
*/
139+
public Long getDaysFromUploadingToHiding() { return this.daysFromUploadingToHiding; }
140+
141+
/**
142+
* The file name prefix to which this rule applies
143+
*
144+
* @return the file name prefix to which this rule applies
145+
*/
146+
public String getFileNamePrefix() { return this.fileNamePrefix; }
147+
148+
}

src/main/java/synapticloop/b2/request/B2ListFileNamesRequest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package synapticloop.b2.request;
22

3+
import java.io.IOException;
4+
35
/*
46
* Copyright (c) 2016 Synapticloop.
57
*
@@ -19,22 +21,19 @@
1921
import org.apache.http.impl.client.CloseableHttpClient;
2022
import org.apache.http.util.EntityUtils;
2123

22-
import java.io.IOException;
23-
2424
import synapticloop.b2.exception.B2ApiException;
2525
import synapticloop.b2.response.B2AuthorizeAccountResponse;
2626
import synapticloop.b2.response.B2ListFilesResponse;
2727

2828
/**
2929
* <p>Lists the names of all files in a bucket, starting at a given name.</p>
30-
* <p>
30+
*
3131
* <p>This call returns at most 1000 file names, but it can be called repeatedly to scan through all of the file names in a bucket. Each time you call, it returns an "endFileName" that can be used as the starting point for the next call.</p>
3232
* <p>There may be many file versions for the same name, but this call will return each name only once. If you want all of the versions, use b2_list_file_versions instead.</p>
33-
* <p>
34-
* <p>
35-
* This is the interaction class for the <strong>b2_list_file_names</strong> api calls, this was
36-
* generated from the backblaze api documentation - which can be found here:
37-
* <p>
33+
*
34+
* <p>This is the interaction class for the <strong>b2_list_file_names</strong> api calls, this was
35+
* generated from the backblaze api documentation - which can be found here:</p>
36+
*
3837
* <a href="http://www.backblaze.com/b2/docs/b2_list_file_names.html">http://www.backblaze.com/b2/docs/b2_list_file_names.html</a>
3938
*
4039
* @author synapticloop

src/main/java/synapticloop/b2/request/BaseB2Request.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package synapticloop.b2.request;
22

3-
import static org.apache.http.entity.ContentType.*;
4-
53
/*
64
* Copyright (c) 2016 Synapticloop.
75
*
@@ -18,6 +16,8 @@
1816
* this source code or binaries.
1917
*/
2018

19+
import static org.apache.http.entity.ContentType.*;
20+
2121
import java.io.IOException;
2222
import java.net.URI;
2323
import java.net.URISyntaxException;
@@ -46,8 +46,6 @@
4646
import synapticloop.b2.exception.B2ApiException;
4747
import synapticloop.b2.response.B2AuthorizeAccountResponse;
4848

49-
import static org.apache.http.entity.ContentType.APPLICATION_JSON;
50-
5149
public abstract class BaseB2Request {
5250
private static final Logger LOGGER = LoggerFactory.getLogger(BaseB2Request.class);
5351

@@ -325,10 +323,14 @@ protected void setHeaders(HttpUriRequest request) throws B2ApiException {
325323
for (String headerKey : requestHeaders.keySet()) {
326324
if(!request.containsHeader(headerKey)) {
327325
final String headerValue = requestHeaders.get(headerKey);
328-
LOGGER.trace("Setting header '" + headerKey + "' to '" + headerValue + "'.");
326+
if(!HttpHeaders.AUTHORIZATION.equalsIgnoreCase(headerKey)) {
327+
LOGGER.trace("Setting header '" + headerKey + "' to '" + headerValue + "'.");
328+
} else {
329+
LOGGER.trace("Setting header '" + headerKey + "' to '[redacted]'.");
330+
}
329331
request.setHeader(headerKey, headerValue);
330332
} else {
331-
LOGGER.warn("Ignore duplicate header " + headerKey);
333+
LOGGER.warn("Ignored duplicate header " + headerKey);
332334
}
333335
}
334336
}
@@ -353,7 +355,7 @@ protected CloseableHttpResponse execute(final HttpUriRequest request) throws IOE
353355
*/
354356
private Object obfuscateData(String key, Object data) {
355357
if(LOGGER.isDebugEnabled()) {
356-
if("accountId".equals(key)) {
358+
if(B2RequestProperties.KEY_ACCOUNT_ID.equals(key)) {
357359
return("[redacted]");
358360
}
359361
}

0 commit comments

Comments
 (0)