Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: PostPolicyV4.PostFieldsV4.Builder.addCustomMetadataField() allow…
…s to add prefixed an not prefixed custom fields (#398)

* changes to PostPolicyV4

* PostPolicyV4.addCustomMetadataField() allows to add prefixed an not prefixed custom fields

* deprecate incorrectly named method

* fix format

* addCustomMetadataField -> setCustomMetadataField
  • Loading branch information
dmitry-fa committed Jul 14, 2020
1 parent 12bd62c commit 02dc3b5
Showing 1 changed file with 27 additions and 11 deletions.
Expand Up @@ -31,8 +31,8 @@
* @see <a href="https://cloud.google.com/storage/docs/xml-api/post-object">POST Object</a>
*/
public final class PostPolicyV4 {
private String url;
private Map<String, String> fields;
private final String url;
private final Map<String, String> fields;

private PostPolicyV4(String url, Map<String, String> fields) {
this.url = url;
Expand All @@ -58,7 +58,7 @@ public Map<String, String> getFields() {
* Object Form fields</a>
*/
public static final class PostFieldsV4 {
private Map<String, String> fieldsMap;
private final Map<String, String> fieldsMap;

private PostFieldsV4(Builder builder) {
this.fieldsMap = builder.fieldsMap;
Expand All @@ -81,10 +81,11 @@ public Map<String, String> getFieldsMap() {
}

public static class Builder {
private Map<String, String> fieldsMap;
private static final String CUSTOM_FIELD_PREFIX = "x-goog-meta-";
private final Map<String, String> fieldsMap;

private Builder() {
fieldsMap = new HashMap<>();
this.fieldsMap = new HashMap<>();
}

public PostFieldsV4 build() {
Expand Down Expand Up @@ -121,7 +122,13 @@ public Builder setContentType(String contentType) {
return this;
}

/** @deprecated use {@link #setExpires(String)} */
@Deprecated
public Builder Expires(String expires) {
return setExpires(expires);
}

public Builder setExpires(String expires) {
fieldsMap.put("expires", expires);
return this;
}
Expand All @@ -136,8 +143,17 @@ public Builder setSuccessActionStatus(int successActionStatus) {
return this;
}

/** @deprecated use {@link #setCustomMetadataField(String, String)} */
@Deprecated
public Builder AddCustomMetadataField(String field, String value) {
fieldsMap.put("x-goog-meta-" + field, value);
return setCustomMetadataField(field, value);
}

public Builder setCustomMetadataField(String field, String value) {
if (!field.startsWith(CUSTOM_FIELD_PREFIX)) {
field = CUSTOM_FIELD_PREFIX + value;
}
fieldsMap.put(field, value);
return this;
}
}
Expand Down Expand Up @@ -270,8 +286,8 @@ Builder addCustomCondition(ConditionV4Type type, String field, String value) {
* Policy document</a>
*/
public static final class PostPolicyV4Document {
private String expiration;
private PostConditionsV4 conditions;
private final String expiration;
private final PostConditionsV4 conditions;

private PostPolicyV4Document(String expiration, PostConditionsV4 conditions) {
this.expiration = expiration;
Expand Down Expand Up @@ -363,9 +379,9 @@ public enum ConditionV4Type {
* Policy document</a>
*/
static final class ConditionV4 {
ConditionV4Type type;
String operand1;
String operand2;
final ConditionV4Type type;
final String operand1;
final String operand2;

private ConditionV4(ConditionV4Type type, String operand1, String operand2) {
this.type = type;
Expand Down

0 comments on commit 02dc3b5

Please sign in to comment.