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
* Set CORS policy
* Set bucket as public or private
* Set object as public or private
Planned feature list

View file

@ -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"

View file

@ -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();
}
}

View file

@ -123,5 +123,6 @@
<string name="custom_policy">Política personalizada</string>
<string name="set_public">Establecer como público</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>
</resources>

View file

@ -127,5 +127,6 @@
<string name="custom_policy">Custom policy</string>
<string name="set_public">Set as public</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>
</resources>

View file

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