User needs to always provide the endpoint in S3 cloud

This commit is contained in:
Julian Raufelder 2021-05-12 11:34:41 +02:00
parent d5598c3dd0
commit 19d08fa692
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
5 changed files with 32 additions and 79 deletions

View File

@ -45,15 +45,8 @@ class S3ClientFactory {
MinioClient.Builder minioClientBuilder = MinioClient.builder();
if (cloud.s3Endpoint() != null) {
minioClientBuilder.endpoint(cloud.s3Endpoint());
} else {
minioClientBuilder.endpoint("https://s3.amazonaws.com");
}
if (cloud.s3Region() != null) {
minioClientBuilder.region(cloud.s3Region());
}
minioClientBuilder.endpoint(cloud.s3Endpoint());
minioClientBuilder.region(cloud.s3Region());
OkHttpClient.Builder httpClientBuilder = new OkHttpClient() //
.newBuilder() //
@ -67,7 +60,10 @@ class S3ClientFactory {
httpClientBuilder.cache(cache).addInterceptor(provideOfflineCacheInterceptor(context));
}
return minioClientBuilder.credentials(decrypt(cloud.accessKey(), context), decrypt(cloud.secretKey(), context)).httpClient(httpClientBuilder.build()).build();
return minioClientBuilder //
.credentials(decrypt(cloud.accessKey(), context), decrypt(cloud.secretKey(), context)) //
.httpClient(httpClientBuilder.build()) //
.build();
}
private static Interceptor provideOfflineCacheInterceptor(final Context context) {

View File

@ -35,14 +35,10 @@ class S3AddOrChangePresenter @Inject internal constructor( //
if (displayName.isEmpty()) {
statusMessage = getString(R.string.screen_s3_settings_msg_display_name_not_empty)
}
if (endpoint.isNullOrEmpty() && region.isNullOrEmpty()) {
if (endpoint.isNullOrEmpty() || region.isNullOrEmpty()) {
statusMessage = getString(R.string.screen_s3_settings_msg_endpoint_and_region_not_empty)
}
if (!endpoint.isNullOrEmpty() && region.isNullOrEmpty()) {
statusMessage = getString(R.string.screen_s3_settings_msg_endpoint_set_and_region_empty)
}
if (statusMessage != null) {
Toast.makeText(context(), statusMessage, Toast.LENGTH_SHORT).show()
} else {

View File

@ -1,9 +1,7 @@
package org.cryptomator.presentation.ui.fragment
import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import com.google.android.material.switchmaterial.SwitchMaterial
import org.cryptomator.generator.Fragment
import org.cryptomator.presentation.R
import org.cryptomator.presentation.model.S3CloudModel
@ -15,10 +13,8 @@ import kotlinx.android.synthetic.main.fragment_setup_s3.bucketEditText
import kotlinx.android.synthetic.main.fragment_setup_s3.createCloudButton
import kotlinx.android.synthetic.main.fragment_setup_s3.displayNameEditText
import kotlinx.android.synthetic.main.fragment_setup_s3.endpointEditText
import kotlinx.android.synthetic.main.fragment_setup_s3.ll_custom_s3
import kotlinx.android.synthetic.main.fragment_setup_s3.regionEditText
import kotlinx.android.synthetic.main.fragment_setup_s3.secretKeyEditText
import kotlinx.android.synthetic.main.fragment_setup_s3.toggleCustomS3
import timber.log.Timber
@Fragment(R.layout.fragment_setup_s3)
@ -42,16 +38,6 @@ class S3AddOrChangeFragment : BaseFragment() {
}
showEditableCloudContent(s3CloudModel)
toggleCustomS3.setOnClickListener { switch ->
toggleUseAmazonS3((switch as SwitchMaterial).isChecked)
}
}
private fun toggleUseAmazonS3(checked: Boolean) = if (checked) {
ll_custom_s3.visibility = View.GONE
} else {
ll_custom_s3.visibility = View.VISIBLE
}
private fun showEditableCloudContent(s3CloudModel: S3CloudModel?) {
@ -61,17 +47,8 @@ class S3AddOrChangeFragment : BaseFragment() {
accessKeyEditText.setText(decrypt(s3CloudModel.accessKey()))
secretKeyEditText.setText(decrypt(s3CloudModel.secretKey()))
bucketEditText.setText(s3CloudModel.s3Bucket())
endpointEditText.setText(s3CloudModel.s3Endpoint())
regionEditText.setText(s3CloudModel.s3Region())
if (it.s3Endpoint().isNotEmpty()) {
toggleCustomS3.isChecked = false
ll_custom_s3.visibility = View.VISIBLE
endpointEditText.setText(s3CloudModel.s3Endpoint())
} else {
toggleCustomS3.isChecked = false
ll_custom_s3.visibility = View.VISIBLE
}
}
}
@ -94,11 +71,14 @@ class S3AddOrChangeFragment : BaseFragment() {
val bucket = bucketEditText.text.toString().trim()
val displayName = displayNameEditText.text.toString().trim()
if (toggleCustomS3.isChecked) {
s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, null, regionEditText.text.toString().trim(), cloudId, displayName)
} else {
s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, endpointEditText.text.toString().trim(), regionEditText.text.toString().trim(), cloudId, displayName)
}
s3AddOrChangePresenter.checkUserInput( //
accessKey, //
secretKey, //
bucket, //
endpointEditText.text.toString().trim(), //
regionEditText.text.toString().trim(), //
cloudId, //
displayName)
}
fun hideKeyboard() {

View File

@ -78,6 +78,21 @@
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/endpointEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/screen_s3_settings_endpoint_label"
android:imeOptions="flagNoPersonalizedLearning"
android:maxLines="1"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -93,39 +108,6 @@
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/toggleCustomS3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:checked="true"
android:text="@string/screen_s3_settings_amazon_s3_text" />
<LinearLayout
android:id="@+id/ll_custom_s3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:visibility="gone">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/endpointEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/screen_s3_settings_endpoint_label"
android:imeOptions="flagNoPersonalizedLearning"
android:maxLines="1"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<Button
android:id="@+id/createCloudButton"
style="?android:textAppearanceSmall"

View File

@ -193,8 +193,7 @@
<string name="screen_s3_settings_msg_access_key_not_empty">Access Key can\'t be empty</string>
<string name="screen_s3_settings_msg_secret_key_not_empty">Secret Key can\'t be empty</string>
<string name="screen_s3_settings_msg_bucket_not_empty">Bucket can\'t be empty</string>
<string name="screen_s3_settings_msg_endpoint_and_region_not_empty">Endpoint and Region can\'t be empty</string>
<string name="screen_s3_settings_msg_endpoint_set_and_region_empty">If Endpoint is set, Region must be set too</string>
<string name="screen_s3_settings_msg_endpoint_and_region_not_empty">Endpoint or Region can\'t be empty</string>
<!-- ## screen: enter vault name -->
<string name="screen_enter_vault_name_title" translatable="false">@string/screen_vault_list_action_create_new_vault</string>