get bucket policy

This commit is contained in:
Page Asgardius 2023-01-21 20:26:37 -07:00
parent 9ee818e47a
commit 960707d4e0
5 changed files with 83 additions and 17 deletions

View file

@ -21,7 +21,7 @@
android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31">
<activity
android:name=".Bucketacl"
android:name=".BucketPolicy"
android:exported="false" />
<activity
android:name=".CorsConfig"

View file

@ -0,0 +1,80 @@
package asgardius.page.s3manager;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
public class BucketPolicy extends AppCompatActivity {
String username, password, endpoint, bucket, location, title;
Region region;
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
AmazonS3 s3client;
boolean style;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bucket_policy);
endpoint = getIntent().getStringExtra("endpoint");
title = getIntent().getStringExtra("title");
username = getIntent().getStringExtra("username");
password = getIntent().getStringExtra("password");
bucket = getIntent().getStringExtra("bucket");
style = getIntent().getBooleanExtra("style", false);
location = getIntent().getStringExtra("region");
region = Region.getRegion(location);
s3ClientOptions = S3ClientOptions.builder().build();
myCredentials = new BasicAWSCredentials(username, password);
try {
s3client = new AmazonS3Client(myCredentials, region);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
s3client.setEndpoint(endpoint);
s3ClientOptions.setPathStyleAccess(style);
s3client.setS3ClientOptions(s3ClientOptions);
Thread getAcl = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
System.out.println(policy);
runOnUiThread(new Runnable() {
@Override
public void run() {
//Your code goes here
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
if(!e.toString().contains("NoSuchBucketPolicy")) {
finish();
}
}
}
});
getAcl.start();
}
}

View file

@ -391,7 +391,7 @@ public class BucketSelect extends AppCompatActivity {
}
private void aclConfig(String bucket) {
Intent intent = new Intent(this, Bucketacl.class);
Intent intent = new Intent(this, BucketPolicy.class);
intent.putExtra("endpoint", endpoint);
intent.putExtra("username", username);
intent.putExtra("password", password);

View file

@ -1,14 +0,0 @@
package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class Bucketacl extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bucketacl);
}
}

View file

@ -4,6 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Bucketacl">
tools:context=".BucketPolicy">
</androidx.constraintlayout.widget.ConstraintLayout>