From 7be7d93b50da10e4317897e7a843d5d070318154 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Tue, 24 Jan 2023 06:23:21 -0700 Subject: [PATCH] new release --- README.md | 1 + app/build.gradle | 4 +- .../page/s3manager/ObjectPolicy.java | 78 ++++++++++++++++++- app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../en-US/changelogs/{72.txt => 73.txt} | 0 .../android/en-US/full_description.txt | 1 + 7 files changed, 81 insertions(+), 5 deletions(-) rename fastlane/metadata/android/en-US/changelogs/{72.txt => 73.txt} (100%) diff --git a/README.md b/README.md index 1859c07..91154af 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Current feature list * get bucket info * Set CORS policy * Set bucket as public or private +* Set object as public or private Planned feature list diff --git a/app/build.gradle b/app/build.gradle index dc2a7e3..e7fb96c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "asgardius.page.s3manager" minSdk 23 targetSdk 33 - versionCode 72 - versionName "0.8.1" + versionCode 73 + versionName "0.8.2" setProperty("archivesBaseName", "s3-manager-$versionName") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java b/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java index 283cb36..a97c947 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java @@ -21,7 +21,7 @@ public class ObjectPolicy extends AppCompatActivity { S3ClientOptions s3ClientOptions; AWSCredentials myCredentials; AmazonS3 s3client; - boolean style, publicbucket, publicobject; + boolean style, publicbucket, publicobject, parent; ProgressBar simpleProgressBar; TextView permission; Button setpublic, setprivate; @@ -63,9 +63,11 @@ public class ObjectPolicy extends AppCompatActivity { policy = s3client.getBucketPolicy(bucket).getPolicyText(); publicbucket = policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject"); publicobject = false; + parent = true; if(!publicbucket && policy.contains("s3:GetObject")) { if((policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"*\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"**\"")) && policy.contains("s3:GetObject")) { publicobject = true; + parent = false; } else { String[] path = filename.split("/"); String filepath = ""; @@ -88,10 +90,16 @@ public class ObjectPolicy extends AppCompatActivity { //Your code goes here if(publicbucket){ permission.setText(getResources().getString(R.string.public_object)); - //setprivate.setVisibility(View.VISIBLE); + setprivate.setEnabled(false); + setprivate.setText(getResources().getString(R.string.parent_policy)); + setprivate.setVisibility(View.VISIBLE); }else if(publicobject) { permission.setText(getResources().getString(R.string.public_object)); - //setprivate.setVisibility(View.VISIBLE); + if(parent) { + setprivate.setEnabled(false); + setprivate.setText(getResources().getString(R.string.parent_policy)); + } + setprivate.setVisibility(View.VISIBLE); }else { permission.setText(getResources().getString(R.string.private_object)); setpublic.setVisibility(View.VISIBLE); @@ -130,6 +138,14 @@ public class ObjectPolicy extends AppCompatActivity { setPublic(); } }); + setprivate.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view) { + //buttonaction + simpleProgressBar.setVisibility(View.VISIBLE); + setPrivate(); + } + }); } private void setPublic() { @@ -185,4 +201,60 @@ public class ObjectPolicy extends AppCompatActivity { }); setPublic.start(); } + + private void setPrivate() { + Thread setPrivate = new Thread(new Runnable() { + + @Override + public void run() { + try { + //Your code goes here + String newpolicy = null; + if(policy.contains(",\"arn:aws:s3:::"+bucket+"/"+filename+"*\"")) { + newpolicy = policy.replace(",\"arn:aws:s3:::"+bucket+"/"+filename+"*\"", ""); + s3client.setBucketPolicy(bucket, newpolicy); + } else if(policy.contains(",\"arn:aws:s3:::"+bucket+"/"+filename+"**\"")) { + newpolicy = policy.replace(",\"arn:aws:s3:::"+bucket+"/"+filename+"**\"", ""); + s3client.setBucketPolicy(bucket, newpolicy); + } else if(policy.contains(",\"arn:aws:s3:::"+bucket+"/"+filename+"\"")) { + newpolicy = policy.replace(",\"arn:aws:s3:::"+bucket+"/"+filename+"\"", ""); + s3client.setBucketPolicy(bucket, newpolicy); + } else if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"*\",")) { + newpolicy = policy.replace("\"arn:aws:s3:::"+bucket+"/"+filename+"*\",", ""); + s3client.setBucketPolicy(bucket, newpolicy); + } else if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"**\",")) { + newpolicy = policy.replace("\"arn:aws:s3:::"+bucket+"/"+filename+"**\",", ""); + s3client.setBucketPolicy(bucket, newpolicy); + } else if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"\",")) { + newpolicy = policy.replace("\"arn:aws:s3:::"+bucket+"/"+filename+"\",", ""); + s3client.setBucketPolicy(bucket, newpolicy); + } else { + s3client.deleteBucketPolicy(bucket); + } + + runOnUiThread(new Runnable() { + + @Override + public void run() { + Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_ok), Toast.LENGTH_SHORT).show(); + finish(); + } + }); + + } catch (Exception e) { + e.printStackTrace(); + runOnUiThread(new Runnable() { + + @Override + public void run() { + simpleProgressBar.setVisibility(View.INVISIBLE); + Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_error), Toast.LENGTH_SHORT).show(); + } + }); + //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); + } + } + }); + setPrivate.start(); + } } \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index d156e15..f7e41d0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -123,5 +123,6 @@ Política personalizada Establecer como público Establecer como privado + Política establecida por carpeta padre Fecha de expiración no requerida \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 85a46b5..a4f8aab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -127,5 +127,6 @@ Custom policy Set as public Set as private + Policy set by parent folder Expiration date not required \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/72.txt b/fastlane/metadata/android/en-US/changelogs/73.txt similarity index 100% rename from fastlane/metadata/android/en-US/changelogs/72.txt rename to fastlane/metadata/android/en-US/changelogs/73.txt diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt index 584d9d5..9c49727 100644 --- a/fastlane/metadata/android/en-US/full_description.txt +++ b/fastlane/metadata/android/en-US/full_description.txt @@ -22,6 +22,7 @@ Current feature list
  • get bucket info
  • Set CORS policy
  • Set bucket as public or private
  • +
  • Set object as public or private
  • Planned feature list