set policy
This commit is contained in:
parent
16fca27422
commit
0fe7f7a79b
5 changed files with 117 additions and 25 deletions
|
@ -2,6 +2,7 @@ package asgardius.page.s3manager;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -24,6 +25,7 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
boolean style;
|
||||
ProgressBar simpleProgressBar;
|
||||
TextView permission;
|
||||
Button setpublic, setprivate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -38,6 +40,7 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
bucket = getIntent().getStringExtra("bucket");
|
||||
style = getIntent().getBooleanExtra("style", false);
|
||||
location = getIntent().getStringExtra("region");
|
||||
getSupportActionBar().setTitle(bucket+"/");
|
||||
region = Region.getRegion(location);
|
||||
s3ClientOptions = S3ClientOptions.builder().build();
|
||||
myCredentials = new BasicAWSCredentials(username, password);
|
||||
|
@ -49,6 +52,8 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
s3client.setEndpoint(endpoint);
|
||||
s3ClientOptions.setPathStyleAccess(style);
|
||||
s3client.setS3ClientOptions(s3ClientOptions);
|
||||
setprivate = (Button)findViewById(R.id.set_private);
|
||||
setpublic = (Button)findViewById(R.id.set_public);
|
||||
Thread getPolicy = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +72,9 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
permission.setText(getResources().getString(R.string.public_bucket));
|
||||
} else {
|
||||
permission.setText(getResources().getString(R.string.custom_policy));
|
||||
setpublic.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setprivate.setVisibility(View.VISIBLE);
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
@ -79,8 +86,9 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
if(e.toString().contains("NoSuchBucketPolicy")) {
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
permission.setText(getResources().getString(R.string.private_bucket));
|
||||
setpublic.setVisibility(View.VISIBLE);
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
else {
|
||||
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
|
||||
|
@ -93,5 +101,92 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
getPolicy.start();
|
||||
setpublic.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//buttonaction
|
||||
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||
setPublic();
|
||||
}
|
||||
});
|
||||
setprivate.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//buttonaction
|
||||
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||
setPrivate();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void setPublic() {
|
||||
Thread setPublic = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Your code goes here
|
||||
String policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetBucketLocation\",\"s3:ListBucket\"],\"Resource\":[\"arn:aws:s3:::"
|
||||
+bucket+"\"]},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetObject\"],\"Resource\":[\"arn:aws:s3:::"+bucket+"/*\"]}]}";
|
||||
s3client.setBucketPolicy(bucket, policy);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
setPublic.start();
|
||||
}
|
||||
|
||||
private void setPrivate() {
|
||||
Thread setPrivate = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Your code goes here
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -160,7 +160,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
public void setAllowall() {
|
||||
private void setAllowall() {
|
||||
Thread addAll = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -179,7 +179,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_ok), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_ok), Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
@ -191,7 +191,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_error), Toast.LENGTH_SHORT).show();
|
||||
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();
|
||||
|
@ -201,7 +201,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
addAll.start();
|
||||
}
|
||||
|
||||
public void setAllowpdf() {
|
||||
private void setAllowpdf() {
|
||||
Thread addPdf = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -220,7 +220,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_ok), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_ok), Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
@ -232,7 +232,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_error), Toast.LENGTH_SHORT).show();
|
||||
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();
|
||||
|
@ -242,7 +242,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
addPdf.start();
|
||||
}
|
||||
|
||||
public void setDeletecors() {
|
||||
private void setDeletecors() {
|
||||
Thread delCors = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -255,7 +255,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_ok), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_ok), Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
@ -267,7 +267,7 @@ public class CorsConfig extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_error), Toast.LENGTH_SHORT).show();
|
||||
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();
|
||||
|
|
|
@ -24,24 +24,17 @@
|
|||
android:textSize="25sp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/allow_all"
|
||||
android:id="@+id/set_public"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/allow_all"
|
||||
android:text="@string/set_public_bucket"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/allow_pdf"
|
||||
android:id="@+id/set_private"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/allow_pdf"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete_cors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/delete_cors"
|
||||
android:text="@string/set_private_bucket"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -103,8 +103,8 @@
|
|||
<string name="allow_all">Permitir todo</string>
|
||||
<string name="allow_pdf">Permitir pdf</string>
|
||||
<string name="delete_cors">Eliminar CORS</string>
|
||||
<string name="cors_error">No se pudo cambiar la política CORS</string>
|
||||
<string name="cors_ok">Política CORS cambiada exitosamente</string>
|
||||
<string name="policy_error">No se pudo cambiar la política</string>
|
||||
<string name="policy_ok">Política cambiada exitosamente</string>
|
||||
<string name="download_bucket">Descargar contenido del bucket</string>
|
||||
<string name="download_folder">Descargar contenido de la carpeta</string>
|
||||
<string name="batch_download_success">Archivos descargados exitosamente</string>
|
||||
|
@ -119,4 +119,6 @@
|
|||
<string name="public_bucket">Bucket público</string>
|
||||
<string name="private_bucket">Bucket privado</string>
|
||||
<string name="custom_policy">Política personalizada</string>
|
||||
<string name="set_public_bucket">Establecer bucket como público</string>
|
||||
<string name="set_private_bucket">Establecer bucket como privado</string>
|
||||
</resources>
|
|
@ -110,8 +110,8 @@
|
|||
<string name="allow_all">Allow all</string>
|
||||
<string name="allow_pdf">Allow pdf</string>
|
||||
<string name="delete_cors">Delete CORS</string>
|
||||
<string name="cors_error">Cannot change CORS policy</string>
|
||||
<string name="cors_ok">CORS policy changed successfully</string>
|
||||
<string name="policy_error">Cannot change policy</string>
|
||||
<string name="policy_ok">Policy changed successfully</string>
|
||||
<string name="copy_name">Copy name to clipboard</string>
|
||||
<string name="copy_ok">Copied to clipboard</string>
|
||||
<string name="upload_calculate">Calculating folder size</string>
|
||||
|
@ -123,4 +123,6 @@
|
|||
<string name="public_bucket">Public bucket</string>
|
||||
<string name="private_bucket">Private bucket</string>
|
||||
<string name="custom_policy">Private bucket</string>
|
||||
<string name="set_public_bucket">Set bucket as public</string>
|
||||
<string name="set_private_bucket">Set bucket as private</string>
|
||||
</resources>
|
Loading…
Reference in a new issue