new release

This commit is contained in:
Page Asgardius 2023-01-24 06:23:21 -07:00
parent 303f0469d7
commit 7be7d93b50
7 changed files with 81 additions and 5 deletions

View file

@ -26,6 +26,7 @@ Current feature list
* get bucket info * get bucket info
* Set CORS policy * Set CORS policy
* Set bucket as public or private * Set bucket as public or private
* Set object as public or private
Planned feature list Planned feature list

View file

@ -9,8 +9,8 @@ android {
applicationId "asgardius.page.s3manager" applicationId "asgardius.page.s3manager"
minSdk 23 minSdk 23
targetSdk 33 targetSdk 33
versionCode 72 versionCode 73
versionName "0.8.1" versionName "0.8.2"
setProperty("archivesBaseName", "s3-manager-$versionName") setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -21,7 +21,7 @@ public class ObjectPolicy extends AppCompatActivity {
S3ClientOptions s3ClientOptions; S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials; AWSCredentials myCredentials;
AmazonS3 s3client; AmazonS3 s3client;
boolean style, publicbucket, publicobject; boolean style, publicbucket, publicobject, parent;
ProgressBar simpleProgressBar; ProgressBar simpleProgressBar;
TextView permission; TextView permission;
Button setpublic, setprivate; Button setpublic, setprivate;
@ -63,9 +63,11 @@ public class ObjectPolicy extends AppCompatActivity {
policy = s3client.getBucketPolicy(bucket).getPolicyText(); policy = s3client.getBucketPolicy(bucket).getPolicyText();
publicbucket = policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject"); publicbucket = policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject");
publicobject = false; publicobject = false;
parent = true;
if(!publicbucket && policy.contains("s3:GetObject")) { 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")) { 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; publicobject = true;
parent = false;
} else { } else {
String[] path = filename.split("/"); String[] path = filename.split("/");
String filepath = ""; String filepath = "";
@ -88,10 +90,16 @@ public class ObjectPolicy extends AppCompatActivity {
//Your code goes here //Your code goes here
if(publicbucket){ if(publicbucket){
permission.setText(getResources().getString(R.string.public_object)); 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) { }else if(publicobject) {
permission.setText(getResources().getString(R.string.public_object)); 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 { }else {
permission.setText(getResources().getString(R.string.private_object)); permission.setText(getResources().getString(R.string.private_object));
setpublic.setVisibility(View.VISIBLE); setpublic.setVisibility(View.VISIBLE);
@ -130,6 +138,14 @@ public class ObjectPolicy extends AppCompatActivity {
setPublic(); setPublic();
} }
}); });
setprivate.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
simpleProgressBar.setVisibility(View.VISIBLE);
setPrivate();
}
});
} }
private void setPublic() { private void setPublic() {
@ -185,4 +201,60 @@ public class ObjectPolicy extends AppCompatActivity {
}); });
setPublic.start(); 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();
}
} }

View file

@ -123,5 +123,6 @@
<string name="custom_policy">Política personalizada</string> <string name="custom_policy">Política personalizada</string>
<string name="set_public">Establecer como público</string> <string name="set_public">Establecer como público</string>
<string name="set_private">Establecer como privado</string> <string name="set_private">Establecer como privado</string>
<string name="parent_policy">Política establecida por carpeta padre</string>
<string name="expiration_not_required">Fecha de expiración no requerida</string> <string name="expiration_not_required">Fecha de expiración no requerida</string>
</resources> </resources>

View file

@ -127,5 +127,6 @@
<string name="custom_policy">Custom policy</string> <string name="custom_policy">Custom policy</string>
<string name="set_public">Set as public</string> <string name="set_public">Set as public</string>
<string name="set_private">Set as private</string> <string name="set_private">Set as private</string>
<string name="parent_policy">Policy set by parent folder</string>
<string name="expiration_not_required">Expiration date not required</string> <string name="expiration_not_required">Expiration date not required</string>
</resources> </resources>

View file

@ -22,6 +22,7 @@ Current feature list
<li>get bucket info</li> <li>get bucket info</li>
<li>Set CORS policy</li> <li>Set CORS policy</li>
<li>Set bucket as public or private</li> <li>Set bucket as public or private</li>
<li>Set object as public or private</li>
Planned feature list Planned feature list