scf get region

pull/128/head
qkqpttgf 2020-07-29 13:40:14 +08:00 committed by GitHub
parent 097254f084
commit a3b1430041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 48 deletions

View File

@ -33,20 +33,15 @@ function GetPathSetting($event, $context)
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]); $_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($event['headers']['accept-language'],';')[0],',')[0]);
$_SERVER['function_name'] = $context['function_name']; $_SERVER['function_name'] = $context['function_name'];
$_SERVER['namespace'] = $context['namespace']; $_SERVER['namespace'] = $context['namespace'];
$_SERVER['Region'] = getenv('TENCENTCLOUD_REGION');
$host_name = $event['headers']['host']; $host_name = $event['headers']['host'];
$_SERVER['HTTP_HOST'] = $host_name; $_SERVER['HTTP_HOST'] = $host_name;
$serviceId = $event['requestContext']['serviceId']; $serviceId = $event['requestContext']['serviceId'];
if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) { if ( $serviceId === substr($host_name,0,strlen($serviceId)) ) {
$_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/'; $_SERVER['base_path'] = '/'.$event['requestContext']['stage'].'/'.$_SERVER['function_name'].'/';
$_SERVER['Region'] = getenv('Region');
if ($_SERVER['Region'] == '') {
$_SERVER['Region'] = substr($host_name, strpos($host_name, '.')+1);
$_SERVER['Region'] = substr($_SERVER['Region'], 0, strpos($_SERVER['Region'], '.'));
}
$path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/')); $path = substr($event['path'], strlen('/'.$_SERVER['function_name'].'/'));
} else { } else {
$_SERVER['base_path'] = $event['requestContext']['path']; $_SERVER['base_path'] = $event['requestContext']['path'];
$_SERVER['Region'] = getenv('Region');
$path = substr($event['path'], strlen($event['requestContext']['path'])); $path = substr($event['path'], strlen($event['requestContext']['path']));
} }
if (substr($path,-1)=='/') $path=substr($path,0,-1); if (substr($path,-1)=='/') $path=substr($path,0,-1);
@ -154,27 +149,24 @@ function install()
<meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302); <meta http-equiv="refresh" content="3;URL=' . path_format($_SERVER['base_path'] . '/') . '">', 302);
} }
if ($_GET['install1']) { if ($_GET['install1']) {
//if ($_POST['admin']!='') { $tmp['timezone'] = $_COOKIE['timezone'];
//$tmp['language'] = $_POST['language']; $SecretId = getConfig('SecretId');
$tmp['Region'] = $_POST['Region']; if ($SecretId=='') {
$tmp['timezone'] = $_COOKIE['timezone']; $SecretId = $_POST['SecretId'];
$SecretId = getConfig('SecretId'); $tmp['SecretId'] = $SecretId;
if ($SecretId=='') { }
$SecretId = $_POST['SecretId']; $SecretKey = getConfig('SecretKey');
$tmp['SecretId'] = $SecretId; if ($SecretKey=='') {
} $SecretKey = $_POST['SecretKey'];
$SecretKey = getConfig('SecretKey'); $tmp['SecretKey'] = $SecretKey;
if ($SecretKey=='') { }
$SecretKey = $_POST['SecretKey']; $response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_SERVER['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response'];
$tmp['SecretKey'] = $SecretKey; if (api_error($response)) {
} $html = api_error_msg($response);
$response = json_decode(SetbaseConfig($tmp, $_SERVER['function_name'], $_POST['Region'], $_SERVER['namespace'], $SecretId, $SecretKey), true)['Response']; $title = 'Error';
if (api_error($response)) { return message($html, $title, 201);
$html = api_error_msg($response); } else {
$title = 'Error'; $html .= '
return message($html, $title, 201);
} else {
$html .= '
<form action="?install2" method="post" onsubmit="return notnull(this);"> <form action="?install2" method="post" onsubmit="return notnull(this);">
<label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br> <label>'.getconstStr('SetAdminPassword').':<input name="admin" type="password" placeholder="' . getconstStr('EnvironmentsDescription')['admin'] . '" size="' . strlen(getconstStr('EnvironmentsDescription')['admin']) . '"></label><br>
<input type="submit" value="'.getconstStr('Submit').'"> <input type="submit" value="'.getconstStr('Submit').'">
@ -189,10 +181,9 @@ function install()
return true; return true;
} }
</script>'; </script>';
$title = getconstStr('SetAdminPassword'); $title = getconstStr('SetAdminPassword');
return message($html, $title, 201); return message($html, $title, 201);
} }
//}
} }
if ($_GET['install0']) { if ($_GET['install0']) {
$html .= ' $html .= '
@ -207,21 +198,6 @@ language:<br>';
<label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br> <label>SecretId:<input name="SecretId" type="text" placeholder="" size=""></label><br>
<label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>'; <label>SecretKey:<input name="SecretKey" type="text" placeholder="" size=""></label><br>';
$html .= ' $html .= '
<select class="changelanguage" name="Region">
<option value="">选择区域</option>
<option value="ap-beijing">华北地区(北京)</option>
<option value="ap-chengdu">西南地区(成都)</option>
<option value="ap-guangzhou">华南地区(广州)</option>
<option value="ap-guangzhou-open">华南地区(广州Open)</option>
<option value="ap-hongkong">港澳台地区(中国香港)</option>
<option value="ap-mumbai">亚太南部(孟买)</option>
<option value="ap-shanghai">华东地区(上海)</option>
<option value="ap-shanghai-fsi">华东地区(上海金融)</option>
<option value="ap-singapore">亚太东南(新加坡)</option>
<option value="ap-tokyo">亚太东北(东京)</option>
<option value="na-siliconvalley">美国西部(硅谷)</option>
<option value="na-toronto">北美地区(多伦多)</option>
</select>(腾讯几个月了还不做出来,只能先弄选择了)<br>
<input type="submit" value="'.getconstStr('Submit').'"> <input type="submit" value="'.getconstStr('Submit').'">
</form> </form>
<script> <script>
@ -325,7 +301,7 @@ function updateEnvironment($Envs, $function_name, $Region, $Namespace, $SecretId
$tmp_env[$key1] = $value1; $tmp_env[$key1] = $value1;
} }
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值 $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
$tmp_env['Region'] = $Region; //$tmp_env['Region'] = $Region;
ksort($tmp_env); ksort($tmp_env);
$i = 0; $i = 0;
@ -366,7 +342,7 @@ function SetbaseConfig($Envs, $function_name, $Region, $Namespace, $SecretId, $S
$tmp_env[$key1] = $value1; $tmp_env[$key1] = $value1;
} }
$tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值 $tmp_env = array_filter($tmp_env, 'array_value_isnot_null'); // remove null. 清除空值
$tmp_env['Region'] = $Region; //$tmp_env['Region'] = $Region;
ksort($tmp_env); ksort($tmp_env);
$i = 0; $i = 0;