first step
This commit is contained in:
parent
7da7a1b5ec
commit
c2289a3f83
7 changed files with 172 additions and 3 deletions
|
@ -20,6 +20,13 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.AsgardiusS3Manager"
|
android:theme="@style/Theme.AsgardiusS3Manager"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".CorsConfig"
|
||||||
|
android:exported="false">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.lib_name"
|
||||||
|
android:value="" />
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".Settings"
|
android:name=".Settings"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode|keyboardHidden"
|
||||||
|
@ -87,11 +94,11 @@
|
||||||
android:label="@string/bucket_list" />
|
android:label="@string/bucket_list" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".VideoPlayer"
|
android:name=".VideoPlayer"
|
||||||
android:resizeableActivity="true"
|
|
||||||
android:supportsPictureInPicture="true"
|
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode|keyboardHidden"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:launchMode="singleTask" />
|
android:launchMode="singleTask"
|
||||||
|
android:resizeableActivity="true"
|
||||||
|
android:supportsPictureInPicture="true" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|uiMode|keyboardHidden"
|
||||||
|
|
|
@ -171,6 +171,8 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
|
|
||||||
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
|
} else if (menuItem.getTitle() == getResources().getString(R.string.object_info)) {
|
||||||
objectInfo(Name.get(position).toString());
|
objectInfo(Name.get(position).toString());
|
||||||
|
} else if (menuItem.getTitle() == getResources().getString(R.string.cors_config)) {
|
||||||
|
corsConfig(Name.get(position).toString());
|
||||||
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
|
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
|
||||||
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
delete(prefix + Name.get(position).toString());
|
delete(prefix + Name.get(position).toString());
|
||||||
|
@ -323,4 +325,16 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void corsConfig(String bucket) {
|
||||||
|
Intent intent = new Intent(this, CorsConfig.class);
|
||||||
|
intent.putExtra("endpoint", endpoint);
|
||||||
|
intent.putExtra("username", username);
|
||||||
|
intent.putExtra("password", password);
|
||||||
|
intent.putExtra("bucket", bucket);
|
||||||
|
intent.putExtra("region", location);
|
||||||
|
intent.putExtra("style", style);
|
||||||
|
intent.putExtra("pdfendpoint", pdfendpoint);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
110
app/src/main/java/asgardius/page/s3manager/CorsConfig.java
Normal file
110
app/src/main/java/asgardius/page/s3manager/CorsConfig.java
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
package asgardius.page.s3manager;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import com.amazonaws.services.s3.model.BucketCrossOriginConfiguration;
|
||||||
|
import com.amazonaws.services.s3.model.CORSRule;
|
||||||
|
import com.amazonaws.services.s3.model.ListObjectsRequest;
|
||||||
|
import com.amazonaws.services.s3.model.ObjectListing;
|
||||||
|
import com.amazonaws.services.s3.model.S3ObjectSummary;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CorsConfig extends AppCompatActivity {
|
||||||
|
String username, password, endpoint, bucket, location, title, pdfendpoint;
|
||||||
|
Region region;
|
||||||
|
S3ClientOptions s3ClientOptions;
|
||||||
|
AWSCredentials myCredentials;
|
||||||
|
AmazonS3 s3client;
|
||||||
|
BucketCrossOriginConfiguration bucketcors;
|
||||||
|
boolean style;
|
||||||
|
boolean allorigins, pdfcompatible = false;
|
||||||
|
TextView origins;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_cors_config);
|
||||||
|
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");
|
||||||
|
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
|
||||||
|
getSupportActionBar().setTitle(bucket+"/");
|
||||||
|
region = Region.getRegion(location);
|
||||||
|
s3ClientOptions = S3ClientOptions.builder().build();
|
||||||
|
myCredentials = new BasicAWSCredentials(username, password);
|
||||||
|
origins = (TextView) findViewById(R.id.origins);
|
||||||
|
try {
|
||||||
|
s3client = new AmazonS3Client(myCredentials, region);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
s3client.setEndpoint(endpoint);
|
||||||
|
s3ClientOptions.setPathStyleAccess(style);
|
||||||
|
s3client.setS3ClientOptions(s3ClientOptions);
|
||||||
|
Thread getCors = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
//Your code goes here
|
||||||
|
bucketcors = s3client.getBucketCrossOriginConfiguration(bucket);
|
||||||
|
if (bucketcors != null) {
|
||||||
|
List<CORSRule> corsRules = bucketcors.getRules();
|
||||||
|
for (CORSRule rule: corsRules) {
|
||||||
|
System.out.println("allowOrigins: "+rule.getAllowedOrigins());
|
||||||
|
System.out.println("AllowedMethod: "+rule.getAllowedMethods());
|
||||||
|
if (rule.getAllowedOrigins().toString().equals("[*]")) {
|
||||||
|
allorigins = true;
|
||||||
|
} else if (rule.getAllowedOrigins().toString().equals("["+pdfendpoint+"]")) {
|
||||||
|
pdfcompatible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (allorigins) {
|
||||||
|
origins.setText(getResources().getString(R.string.cors_all));
|
||||||
|
} else if (pdfcompatible) {
|
||||||
|
origins.setText(getResources().getString(R.string.cors_pdf));
|
||||||
|
} else {
|
||||||
|
origins.setText(getResources().getString(R.string.cors_none));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getCors.start();
|
||||||
|
}
|
||||||
|
}
|
24
app/src/main/res/layout/activity_cors_config.xml
Normal file
24
app/src/main/res/layout/activity_cors_config.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/activity_main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".CorsConfig">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/cors_status"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textSize="30sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/origins"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textSize="25sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -13,6 +13,10 @@
|
||||||
android:id="@+id/info"
|
android:id="@+id/info"
|
||||||
android:title="@string/object_info" />
|
android:title="@string/object_info" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/cors_config"
|
||||||
|
android:title="@string/cors_config" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/deletefolder"
|
android:id="@+id/deletefolder"
|
||||||
android:title="@string/file_del" />
|
android:title="@string/file_del" />
|
||||||
|
|
|
@ -95,4 +95,9 @@
|
||||||
<string name="playback_channel_name">Reproduccion de video</string>
|
<string name="playback_channel_name">Reproduccion de video</string>
|
||||||
<string name="not_zero">este valor no puede ser cero</string>
|
<string name="not_zero">este valor no puede ser cero</string>
|
||||||
<string name="path_style">Acceso de estilo de ruta</string>
|
<string name="path_style">Acceso de estilo de ruta</string>
|
||||||
|
<string name="cors_config">Política CORS</string>
|
||||||
|
<string name="cors_status">Orígenes permitidos</string>
|
||||||
|
<string name="cors_all">Permitidos todos los orígenes</string>
|
||||||
|
<string name="cors_pdf">Permitido el uso de endpoint PDF</string>
|
||||||
|
<string name="cors_none">Uso de endpoint PDF permitido</string>
|
||||||
</resources>
|
</resources>
|
|
@ -98,4 +98,9 @@
|
||||||
<string name="playback_channel_name">Video Playback</string>
|
<string name="playback_channel_name">Video Playback</string>
|
||||||
<string name="not_zero">This value cannot be zero</string>
|
<string name="not_zero">This value cannot be zero</string>
|
||||||
<string name="path_style">Path style access</string>
|
<string name="path_style">Path style access</string>
|
||||||
|
<string name="cors_config">CORS policy</string>
|
||||||
|
<string name="cors_status">Allowed origins</string>
|
||||||
|
<string name="cors_all">All origins allowed</string>
|
||||||
|
<string name="cors_pdf">PDF Endpoint allowed</string>
|
||||||
|
<string name="cors_none">PDF Endpoint not allowed</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue