从应用名称中获取应用GUID-通过代码 [英] Get app guid from app name - via code

查看:94
本文介绍了从应用名称中获取应用GUID-通过代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在CF空间上运行了节点应用程序 mainApp ,在此节点应用程序中,我正在获取 other 应用程序名称(部署在同一空间中),我想从中获取应用程序 guid ,我该怎么做?

I've and node application mainAppthat running on CF space, in this node application im getting other application name ( that deployed in the same space) and I want to get from it the application guid , How I can do it ?

这就是我尝试过的方法(我尝试获取该空间中的所有应用,并从 guid 但我得到了http 401-未经授权的

This is what I've tried ( I try to get all apps in this space and search for specific app from the guid but I got http 401 - unauthorized ,



  1. 任何想法我怎么能从已部署到CF的应用程序中获取应用程序guid(假设我具有应用程序名称)

  1. any idea how can I get from app that deployed to CF the app app guid (suppose I've the app name )

那里是实现此目的的更好方法?

There is a better way to achieve this ?




getAllApps: () => {

        return new Promise((resolve, reject) => {

            rp({
                uri: 'https://' + CF_API + '/v2/apps',
                json: true

            }).then((data) => {
                "use strict";
                console.log("apps data: " + data);
                resolve(data);
            });
        })


推荐答案

您必须首先获取访问令牌并将其传递给h根据您的问题提出要求。
请参见下面的示例,该示例将获取应用程序guid:

You have to first get the access token and pass it in the header of the request you have in your question. See the example below that will get the application guid:

var request = require('request-promise');

request({
      "method":"POST",
      "uri": "https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token",
      "json": true,
      "headers": {
        "content-type": "application/x-www-form-urlencoded",
        "authorization": "Basic Y2Y6",
        "accept": "application/json"
      },
      "form" : {
        "grant_type": "password",
        "username": "<your Bluemix id>",
        "password": "<your Bluemix password>"
      }
}).then(function(response) {
      return response.access_token;
}).then(function(token) {
  return request({
    "method":"GET",
    "uri": "https://api.ng.bluemix.net/v2/apps",
    "qs": {
      "q": "name:yourappname"
    },
    "json": true,
    "headers": {
      "accept": "application/json",
      "authorization": "bearer " + token
    }
  }).then(function (response) {
    console.log(response.resources[0].metadata.guid);
  });
});

这篇关于从应用名称中获取应用GUID-通过代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆