Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

adding CSP changes to grafana integration#14

Open
dkuldeep22 wants to merge 5 commits intowavefrontHQ:masterfrom
dkuldeep22:dkuldeep22/INT-1949
Open

adding CSP changes to grafana integration#14
dkuldeep22 wants to merge 5 commits intowavefrontHQ:masterfrom
dkuldeep22:dkuldeep22/INT-1949

Conversation

@dkuldeep22
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@gangadharaswamy gangadharaswamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gangadharaswamy
Copy link
Copy Markdown

@dkuldeep22 Please add the Datasource CLI commands for CSP OAuth and API token in the README.md.

Copy link
Copy Markdown

@Margarita-Staneva Margarita-Staneva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one comment. I think CSP API token should be replaced with VMware Cloud services API token.

Comment thread dist/partials/config.html
<a class="btn btn-secondary gf-form-btn" style="flex-grow:1" type="submit" ng-click="ctrl.resetCspApiToken()" ng-show="ctrl.cspApiTokenExists">Reset</a>
<input type="text" class="gf-form-input max-width-24" ng-hide="ctrl.cspApiTokenExists" ng-model="ctrl.current.jsonData.cspAPIToken"/>
<info-popover mode="right-absolute" ng-hide="ctrl.cspApiTokenExists">
Paste your CSP API token here. You can find and manage your tokens on your profile page in the Wavefront app
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this throughout:

Paste your VMware Cloud services API token here. You can find and manage your API tokens on your profile page in the Wavefront app.

@amahajan02
Copy link
Copy Markdown

Please remove console.log statements from all files. These were added for debugging and should not be checked-in

Comment thread src/plugin/datasource.ts Outdated
const CSP_API_TOKEN_URL = "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize";
const CSP_OAUTH_TOKEN_URL = "https://console.cloud.vmware.com/csp/gateway/am/api/auth/authorize";

const appSecret = ""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused variable. Please remove.

Comment thread src/plugin/datasource.ts
const appId = instanceSettings.jsonData.cspOAuthClientId
const appSecret = instanceSettings.jsonData.cspOAuthClientSecret
const credentials = `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`;

Copy link
Copy Markdown

@amahajan02 amahajan02 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we trying to do here?
Buffer does not exist and credentials is not getting used anywhere.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use btoa for base64 encoding.
Try this: const credentials = Basic ${btoa(${appId}:${appSecret})};``

Comment thread src/plugin/datasource.ts Outdated
const startSecs = dateToEpochSeconds(options.range.from);

const endSecs = dateToEpochSeconds(options.range.to);
console.log("********endSecs", endSecs);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove all console.log statements here.

Comment thread src/plugin/datasource.ts Outdated
grant_type: "client_credentials",
}),
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add "Authorization" in headers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Authorization": credentials

Comment thread src/plugin/datasource.ts
const appId = instanceSettings.jsonData.cspOAuthClientId
const appSecret = instanceSettings.jsonData.cspOAuthClientSecret
const credentials = `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use btoa for base64 encoding.
Try this: const credentials = Basic ${btoa(${appId}:${appSecret})};``

Comment thread src/plugin/datasource.ts
} catch(e) {
console.error(e);
}
this.requestConfigProto.headers["Authorization"] = "Bearer " + instanceSettings.jsonData.cspAPIToken;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set "Authorization" header to access token which we get after making call to CSP_OAUTH_TOKEN_URL. Not directly to csp api token. Please confirm this point from Gangadhar or Sadanand.
If they confirm, then change line#45 from :
.then((json) => console.log(json));
to:
then((accessToken) => this.requestConfigProto.headers["Authorization"] = accessToken)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with OAuth

Comment thread src/plugin/datasource.ts


function refreshToken() {
if (instanceSettings.jsonData.cspAPIToken) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is same as what we are doing at line#35 and 51.
Can we create two functions like: fetchAccessTokenUsingCSPAPIToken and fetchAccessTokenUsingCSPOAuth and use these functions during initialisation and interval update

Comment thread src/plugin/datasource.ts
}

// Execute the function initially
refreshToken();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since, we are already calling it during initialisation at line#33, we can skip this initial call of refreshToken

Comment thread src/plugin/datasource.ts
refreshToken();

// Execute the function every 25 minutes (25 * 60 * 1000 milliseconds)
const interval = setInterval(refreshToken, 25 * 60 * 1000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not stopping the interval at any time. No need to store the result in interval const. Calling the function should be sufficient.
setInterval(refreshToken, 25 * 60 * 1000);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants