Skip to content

Commit

Permalink
Fixzone support create by region id (qiniu#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn authored Oct 20, 2023
1 parent 63e06c2 commit cdbba26
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 23 deletions.
5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:7.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
7 changes: 3 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ android {

dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.1'

// implementation 'com.squareup.okhttp3:okhttp:3.12.+'
implementation 'com.qiniu:happy-dns:2.0.1'

// for javax.annotation.Nullable use in custom MultipartBody and Headers implements.
// implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.conscrypt:conscrypt-android:2.2.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')

androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// androidTestImplementation "androidx.test:runner:1.4.0"
// androidTestImplementation "androidx.test:core:1.4.0"
Expand Down
16 changes: 8 additions & 8 deletions library/src/androidTest/java/com/qiniu/android/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
*/
public final class TestConfig {
// TODO: 2020-05-09 bad token for testPutBytesWithFixedZoneUseBackupDomains
// 华东上传凭证
// 华东上传凭证
public static final String bucket_z0 = "kodo-phone-zone0-space";
public static final String token_z0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:c_5jTva3_WOScZi9vMK9biAV7os=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTAtc3BhY2UiLCJkZWFkbGluZSI6MTY5NTk4MDM2MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:IySl002XpGBWsDKkKNK7g_ByUrU=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华北上传凭证
public static final String bucket_z1 = "kodo-phone-zone1-space";
public static final String token_z1 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:ydDfsf5x2jWb8eX165DuAMfHH4A=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTEtc3BhY2UiLCJkZWFkbGluZSI6MTY5NTk4MDM2MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z1 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:SRqIrj9rqtDuq7N9ZuZppqnFvGI=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTEtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华南上传凭证
public static final String bucket_z2 = "kodo-phone-zone2-space";
public static final String token_z2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:R2JsVQBaOh7pREK453aIH5hmOo8=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTItc3BhY2UiLCJkZWFkbGluZSI6MTY5NTk4MDM2MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:59MIAaRbhMJUjyTayLSsTMO99H8=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTItc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 北美上传凭证
public static final String bucket_na0 = "kodo-phone-zone-na0-space";
public static final String token_na0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:oxJPDRhheBnMHbXxIZwOn0nEH0U=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1uYTAtc3BhY2UiLCJkZWFkbGluZSI6MTY5NTk4MDM2MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_na0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:hv6IeMz-bitw_nxnxYEeWJPRFq4=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1uYTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 东南亚上传凭证
public static final String bucket_as0 = "kodo-phone-zone-as0-space";
public static final String token_as0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:tApkgqOaYzs2WWaJKfJIsDhv_CE=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1hczAtc3BhY2UiLCJkZWFkbGluZSI6MTY5NTk4MDM2MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_as0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:umlUjNLKvlx7QM9dA7r7xD0Kolc=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1hczAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华北浙江2上传凭证
public static final String bucket_cn_east_2 = "kodo-phone-cn-east-2";
public static final String token_cn_east_2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:7DoLnAmoeZQZw0NnF7221j_ro-s=:eyJzY29wZSI6ImtvZG8tcGhvbmUtY24tZWFzdC0yIiwiZGVhZGxpbmUiOjE2OTU5ODAzNjIsICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKSwgXCJmc2l6ZVwiOiQoZnNpemUpfSJ9";
public static final String invalidBucketToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:GmHSNf0RubeaWvjc4P7fTHWzBmI=:eyJzY29wZSI6InpvbmVfaW52YWxpZCIsImRlYWRsaW5lIjoxNjk1OTgwMzYyLCAicmV0dXJuQm9keSI6IntcImZvb1wiOiQoeDpmb28pLCBcImJhclwiOiQoeDpiYXIpLCBcIm1pbWVUeXBlXCI6JChtaW1lVHlwZSksIFwiaGFzaFwiOiQoZXRhZyksIFwia2V5XCI6JChrZXkpLCBcImZuYW1lXCI6JChmbmFtZSksIFwiZnNpemVcIjokKGZzaXplKX0ifQ==";
public static final String token_cn_east_2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:3p87j64XIiAFG7H73leG8zjU120=:eyJzY29wZSI6ImtvZG8tcGhvbmUtY24tZWFzdC0yIiwiZGVhZGxpbmUiOjE3MDIyNjQ1MjksICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKSwgXCJmc2l6ZVwiOiQoZnNpemUpfSJ9";
public static final String invalidBucketToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:Bq_GcfQI_T5hZl78g1SboR4o75k=:eyJzY29wZSI6InpvbmVfaW52YWxpZCIsImRlYWRsaW5lIjoxNzAyMjY0NTI5LCAicmV0dXJuQm9keSI6IntcImZvb1wiOiQoeDpmb28pLCBcImJhclwiOiQoeDpiYXIpLCBcIm1pbWVUeXBlXCI6JChtaW1lVHlwZSksIFwiaGFzaFwiOiQoZXRhZyksIFwia2V5XCI6JChrZXkpLCBcImZuYW1lXCI6JChmbmFtZSksIFwiZnNpemVcIjokKGZzaXplKX0ifQ==";

// -----------
public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.qiniu.android.common;


import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.qiniu.android.BaseTest;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class FixZoneTest extends BaseTest {

@Test
public void testCreateByRegionId() {
FixedZone zone = FixedZone.createWithRegionId("na0");
ZoneInfo zoneInfo = zone.getZonesInfo(null).zonesInfo.get(0);

assertTrue(zoneInfo.regionId.equals("na0"));
assertTrue(zoneInfo.domains.get(0).equals("upload-na0.qiniup.com"));
assertTrue(zoneInfo.domains.get(1).equals("up-na0.qiniup.com"));
}
}
34 changes: 34 additions & 0 deletions library/src/main/java/com/qiniu/android/common/FixedZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,82 @@
public final class FixedZone extends Zone {
/**
* 华东机房
* <p>
* 废弃,使用 {@link FixedZone#createWithRegionId} 替换,regionId:z0
*/
@Deprecated
public static final Zone zone0 = new FixedZone(new String[]{"upload.qiniup.com", "up.qiniup.com"},
new String[]{"upload.qbox.me", "up.qbox.me"},
"z0");

/**
* 华东浙江 2 机房
* <p>
* 废弃,使用 {@link FixedZone#createWithRegionId} 替换,regionId:cn-east-2
*/
@Deprecated
public static final Zone zoneCnEast2 = new FixedZone(new String[]{"upload-cn-east-2.qiniup.com", "up-cn-east-2.qiniup.com"},
null,
"cn-east-2");

/**
* 华北机房
* <p>
* 废弃,使用 {@link FixedZone#createWithRegionId} 替换,regionId:z1
*/
@Deprecated
public static final Zone zone1 = new FixedZone(new String[]{"upload-z1.qiniup.com", "up-z1.qiniup.com"},
new String[]{"upload-z1.qbox.me", "up-z1.qbox.me"},
"z1");

/**
* 华南机房
* <p>
* 废弃,使用 {@link FixedZone#createWithRegionId} 替换,regionId:z2
*/
@Deprecated
public static final Zone zone2 = new FixedZone(new String[]{"upload-z2.qiniup.com", "up-z2.qiniup.com"},
new String[]{"upload-z2.qbox.me", "up-z2.qbox.me"},
"z2");

/**
* 北美机房
* <p>
* 废弃,使用 {@link FixedZone#createWithRegionId} 替换,regionId:na0
*/
@Deprecated
public static final Zone zoneNa0 = new FixedZone(new String[]{"upload-na0.qiniup.com", "up-na0.qiniup.com"},
new String[]{"upload-na0.qbox.me", "up-na0.qbox.me"},
"na0");

/**
* 新加坡机房
* <p>
* 废弃,使用 {@link FixedZone#createWithRegionId} 替换,regionId:as0
*/
@Deprecated
public static final Zone zoneAs0 = new FixedZone(new String[]{"upload-as0.qiniup.com", "up-as0.qiniup.com"},
new String[]{"upload-as0.qbox.me", "up-as0.qbox.me"},
"as0");

/**
* FixedZone 构造方法
* regionId 参考链接:https://developer.qiniu.com/kodo/1671/region-endpoint-fq
*
* @param regionId 根据区域 ID 创建 Zone
* @return Zone 实例
*/
public static FixedZone createWithRegionId(String regionId) {
String[] upDomains = new String[]{
"upload-" + regionId + ".qiniup.com",
"up-" + regionId + ".qiniup.com"
};
return new FixedZone(upDomains, new String[]{}, regionId);
}

private ZonesInfo zonesInfo;

@Deprecated
public static FixedZone localsZoneInfo() {
FixedZone[] localsZone = new FixedZone[]{
(FixedZone) zone0, (FixedZone) zoneCnEast2,
Expand Down
24 changes: 19 additions & 5 deletions mvn_push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ publishing {
artifactId = POM_ARTIFACT_ID
version = VERSION_NAME

afterEvaluate {
from components.release
artifacts {
artifact(androidSourcesJar)
artifact(androidJavadocsJar)
artifact("$buildDir/outputs/aar/${project.name}-release.aar")
}

artifact(androidSourcesJar)
artifact(androidJavadocsJar)

pom {
name = POM_NAME
Expand Down Expand Up @@ -97,6 +97,20 @@ publishing {
developerConnection=POM_SCM_DEV_CONNECTION
url=POM_SCM_URL
}

withXml {
def dependencies = asNode().appendNode("dependencies")

configurations
.getByName("releaseCompileClasspath")
.resolvedConfiguration
.firstLevelModuleDependencies.forEach {
def dependency = dependencies.appendNode("dependency")
dependency.appendNode("groupId", it.moduleGroup)
dependency.appendNode("artifactId", it.moduleName)
dependency.appendNode("version", it.moduleVersion)
}
}
}
}
}
Expand All @@ -117,5 +131,5 @@ publishing {

signing {
required { isReleaseBuild()}
sign publishing.publications.mavenJava
sign publishing.publications
}

0 comments on commit cdbba26

Please sign in to comment.