CF连接到云控制器

我使用下面的lib连接到云控制器

https://github.com/prosociallearnEU/cf-nodejs-client

const endpoint = "https://api.mycompany.com/"; const username = "myuser"; const password = "mypass"; const CloudController = new (require("cf-client")).CloudController(endpoint); const UsersUAA = new (require("cf-client")).UsersUAA; const Apps = new (require("cf-client")).Apps(endpoint); CloudController.getInfo().then((result) => { UsersUAA.setEndPoint(result.authorization_endpoint); return UsersUAA.login(username, password); }).then((result) => { Apps.setToken(result); return Apps.getApps(); }).then((result) => { console.log(result); }).catch((reason) => { console.error("Error: " + reason); }); 
  1. 我试图运行它对我们的API和它不工作,我没有得到任何错误消息在控制台,它可以是什么?

  2. 空间/组织在哪里处理? 因为当我从cli连接它问我到哪个空间/组织我想连接…

我能够通过CLIlogin ,只是从我不能代码 ,任何想法是什么在这里丢失?

当我运行它的问题我没有得到任何错误,可以帮助了解什么是根本原因

我克隆了原始的git仓库,并修改了一些支持代理的方法。 请注意,我修改了一些方法来获取示例代码,但是需要对包进行完整的重构。

基本上你所要做的就是在调用request方法之前添加一个proxy参数(这是在整个包中完成的,因此需要进行一些修改),例如这是针对Organization.js文件中的一个方法:

 getSummary (guid) { const url = `${this.API_URL}/v2/organizations/${guid}/summary`; const proxy = `${this.API_PROXY}`; const options = { method: "GET", url: url, proxy: proxy, headers: { Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` } }; return this.REST.request(options, this.HttpStatus.OK, true); } 

你可以在下面的git仓库中find我的更改:

https://github.com/adasilva70/cf-nodejs-client.git

我也在下面创build了一个新的示例。 此示例列出用户的所有组织,获取第一个返回的组织并列出其空间。 您可以修改代码以提供cflogin提供的类似function(允许您select一个组织,然后select一个空间)。

 const endpoint = "https://api.mycompany.com/"; const username = "youruser"; const password = "yourpassword"; const proxy = "http://proxy.mycompany.com:8080"; const CloudController = new (require("cf-nodejs-client")).CloudController(endpoint, proxy); const UsersUAA = new (require("cf-nodejs-client")).UsersUAA; const Apps = new (require("cf-nodejs-client")).Apps(endpoint, proxy); const Orgs = new (require("cf-nodejs-client")).Organizations(endpoint, proxy); CloudController.getInfo().then((result) => { console.log(result); UsersUAA.setEndPoint(result.authorization_endpoint, proxy); return UsersUAA.login(username, password); }).then((result) => { //Apps.setToken(result); //return Apps.getApps(); Orgs.setToken(result); return Orgs.getOrganizations(); }).then((result) => { console.log(result); org_guid = result.resources[1].metadata.guid; return Orgs.getSummary(org_guid); }).then((result) => { console.log(result); }).catch((reason) => { console.error("Error: " + reason); }); 

我已经做了很小的testing,以确保样品的工作,所以要小心使用。 此外,这些更改仅适用于现在需要代理的情况。

我在图书馆的github网站上发现的第一件事是警告:

注意:该软件包尚未准备好用于生产应用程序。

似乎这个项目还没有得到维护,因为有好几个月没有回应的门票。

无论如何,要弄清楚为什么库不工作,没有产生错误信息,我会检查出库源代码,并添加一些控制台日志语句,可能从HttpUtils开始。 例如:

 requestWithDefaults(options, function (error, response, body) { console.log("requestWithDefaults error: ", error) console.log("requestWithDefaults response: ", response) console.log("requestWithDefaults body: ", body) ... } 

或者,您可以尝试使用nodejs debugging器将断点添加到库中的requestWithDefaults和其他关键位置来debugging代码 。

你也可以尝试debuggingnetworking调用类似于这个如何监视node.js上的networking类似于Chrome / Firefox的开发者工具?

为了理解如何使用这个库,我会查看这个testing文件夹,然后寻找一个类似于你的用例的testing。 如果testing在test / lib / model / cloudcontroller文件夹中看起来有用,那么有一个合理的数量。

至于关于空间的问题,我已经find了一个例子 ,你可以通过一个空间guid来返回应用程序的空间guid。

 CloudFoundrySpaces.getSpaceApps(space_guid, filter).then( ... ) 

我假设你正在使用App.getApps()的调用将返回所有空间/组织的应用程序。