-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from rpmoore/master
Adding ensureBucketExists helper
- Loading branch information
Showing
9 changed files
with
322 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/spectralogic/ds3client/commands/HeadBucketRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright 2014 Spectra Logic Corporation. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package com.spectralogic.ds3client.commands; | ||
|
||
import com.spectralogic.ds3client.HttpVerb; | ||
|
||
/** | ||
* {@code HeadBucketRequest} is used to return back information on if a bucket exists, or if a user has access to that bucket. | ||
*/ | ||
public class HeadBucketRequest extends AbstractRequest { | ||
|
||
private final String bucketName; | ||
|
||
public HeadBucketRequest(final String bucketName) { | ||
this.bucketName = bucketName; | ||
} | ||
|
||
@Override | ||
public String getPath() { | ||
return "/" + bucketName; | ||
} | ||
|
||
@Override | ||
public HttpVerb getVerb() { | ||
return HttpVerb.HEAD; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/spectralogic/ds3client/commands/HeadBucketResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright 2014 Spectra Logic Corporation. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package com.spectralogic.ds3client.commands; | ||
|
||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
|
||
import java.io.IOException; | ||
|
||
public class HeadBucketResponse extends AbstractResponse { | ||
|
||
static public enum Status { | ||
EXISTS, DOESNTEXIST, NOTAUTHORIZED | ||
} | ||
|
||
private Status status; | ||
|
||
public HeadBucketResponse(final CloseableHttpResponse response) throws IOException { | ||
super(response); | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
protected void processResponse() throws IOException { | ||
checkStatusCode(200, 403, 404); | ||
final int statusCode = getStatusCode(); | ||
setStatus(statusCode); | ||
} | ||
|
||
private void setStatus(final int statusCode) { | ||
switch(statusCode) { | ||
case 200: this.status = Status.EXISTS; break; | ||
case 403: this.status = Status.NOTAUTHORIZED; break; | ||
case 404: this.status = Status.DOESNTEXIST; break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.