我正在尝试使用API在bluemix中创建容器,因为http://ccsapi-doc.mybluemix.net在文档中提到:
将API与新模型一起使用时,应提供以下HTTP标头: X-Auth-Token = Bluemix JWT令牌 X-Auth-Project-Id =空间GUID
但我不知道如何获取或生成Bluemix JWT令牌。有人能帮助我吗?
答案 0 :(得分:4)
您可以通过import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TableBackup_1 {
private static String ip="localhost";
private static String port="3306";
private static String database="xyz";
private static String user="root";
private static String pass="pass";
private static String path="/home/Admin/abc/";
public static void export()
{
Date dateNow = new Date();
SimpleDateFormat dateformatyyyyMMdd = new SimpleDateFormat("yyyyMMdd");
String date_to_string = dateformatyyyyMMdd.format(dateNow);
System.out.println("date into yyyyMMdd format: " + date_to_string);
String ss="abc.sql";
String fullName = path + " " + date_to_string + " " + ss;
String dumpCommand = "mysqldump " + database + " -h " + ip + " -u " + user +" -p" + pass;
Runtime rt = Runtime.getRuntime();
File test=new File(fullName);
PrintStream ps;
try{
Process child = rt.exec(dumpCommand);
ps=new PrintStream(test);
InputStream in = child.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
ps.write(ch);
//System.out.write(ch); //to view it by console
}
InputStream err = child.getErrorStream();
while ((ch = err.read()) != -1) {
System.out.write(ch);
}
}catch(Exception exc) {
exc.printStackTrace();
}
}
public static void main(String args[]){
export();
}
}
命令获取X-Auth-Token
。然后在cf oauth-token
之后复制并粘贴部分的其余部分。您还可以bearer
获得X-Auth-Project-Id
。请参阅以下命令;
cf space --guid <space Name>
答案 1 :(得分:0)
答案 2 :(得分:0)
这是另一种方法:
您可以使用以下命令检索 X-Auth-Token 和 X-Auth-Project-Id :
cf login
CF_TRACE=true cf ic login
复制.txt文件中的所有输出并搜索X-Auth-Token和X-Auth-Project-Id
这里有一个简单的例子:
curl -X GET --header "Accept: application/json" --header "X-Auth-Token: asdlkfajdfdkaldkjfskl239049283049jsdfjksl29304" --header "X-Auth-Project-Id: sdfadf-0090-43ef-22932-23434234" "https://containers-api.ng.bluemix.net/v3/containers/quota"
Response:
The output of API is like this:
{
"account_type": "TRIAL",
"country_code": "ITA",
"org_quota": {
"floating_ips_max": "2",
"floating_ips_space_default": "2",
"floating_ips_usage": 2,
"ram_max": "2048",
"ram_space_default": "2048",
"ram_usage": 2048,
"subnet_usage": -1,
"subnets_default": "5",
"subnets_max": 0
},
"space_quota": {
"floating_ips_max": 2,
"ram_max": 2048,
"subnets_max": -1
}