package com.mesosphere.dcos.cassandra.scheduler.resources;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotEmpty;

public class StartBackupRequest {
  @JsonProperty("backup_name")
  @NotEmpty
  private String name;

  @JsonProperty("external_location")
  @NotEmpty
  private String externalLocation;

  @JsonProperty("s3_access_key")
  private String s3AccessKey;

  @JsonProperty("s3_secret_key")
  private String s3SecretKey;

  @JsonProperty("azure_account")
  private String azureAccount;

  @JsonProperty("azure_key")
  private String azureKey;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getExternalLocation() {
    return externalLocation;
  }

  public void setExternalLocation(String externalLocation) {
    this.externalLocation = externalLocation;
  }

  public String getS3AccessKey() {
    return s3AccessKey;
  }

  public void setS3AccessKey(String s3AccessKey) {
    this.s3AccessKey = s3AccessKey;
  }

  public String getS3SecretKey() {
    return s3SecretKey;
  }

  public void setS3SecretKey(String s3SecretKey) {
    this.s3SecretKey = s3SecretKey;
  }

  public String getAzureAccount() {
    return azureAccount;
  }

  public void setAzureAccount(String azureAccount) {
    this.azureAccount = azureAccount;
  }

  public String getAzureKey() {
    return azureKey;
  }

  public void setAzureKey(String azureKey) {
    this.azureKey = azureKey;
  }

  public boolean isValid() {
    return (StringUtils.isNotBlank(name) && externalLocation != null) &&
      ((s3AccessKey != null && s3SecretKey != null && externalLocation.startsWith("s3:")) ||
        (azureAccount != null && azureKey != null && externalLocation.startsWith("azure:")));
  }

  @Override
  public String toString() {
    return "StartBackupRequest{" +
            "name='" + name + '\'' +
            ", externalLocation='" + externalLocation + '\'' +
            ", s3AccessKey='" + s3AccessKey + '\'' +
            ", s3SecretKey='" + s3SecretKey + '\'' +
            ", azureAccount='" + azureAccount + '\'' +
            ", azureKey='" + azureKey + '\'' +
            '}';
  }
}

@@ -1656,20 +1656,126 @@
 ull)
- &&%0A      ((
+%0A            && (isValidS3Request() %7C%7C isValidAzureRequest());%0A  %7D%0A%0A  private boolean isValidS3Request() %7B%0A    return 
 s3Ac
@@ -1785,24 +1785,36 @@
 sKey != null
+%0A           
  && s3Secret
@@ -1828,60 +1828,316 @@
 null
- && externalLocation.startsWith(%22s3:%22)) %7C%7C%0A        (
+%0A            && isValidS3ExternalLocation();%0A  %7D%0A%0A  private boolean isValidS3ExternalLocation() %7B%0A    return externalLocation.startsWith(%22s3:%22)%0A            %7C%7C externalLocation.startsWith(%22http:%22)%0A            %7C%7C externalLocation.startsWith(%22https:%22);%0A  %7D%0A%0A  private boolean isValidAzureRequest() %7B%0A    return 
 azur
@@ -2213,18 +2213,16 @@
 azure:%22)
-))
 ;%0A  %7D%0A%0A 

Allow S3 backup requests to specify https: or http: protocols