-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding CSP changes to grafana integration #14
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@dkuldeep22 Please add the Datasource CLI commands for CSP OAuth and API token in the README.md. |
This reverts commit 0f4df13.
There was a problem hiding this 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.
<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 |
There was a problem hiding this comment.
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.
Please remove console.log statements from all files. These were added for debugging and should not be checked-in |
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 = "" |
There was a problem hiding this comment.
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.
@@ -15,6 +21,9 @@ export function WavefrontDatasource(instanceSettings, $q, backendSrv, templateSr | |||
this.backendSrv = new BackendSrvCancelledRetriesDecorator(backendSrv, $q); | |||
this.templateSrv = templateSrv; | |||
this.defaultRequestTimeoutSecs = 15; | |||
const appId = instanceSettings.jsonData.cspOAuthClientId | |||
const appSecret = instanceSettings.jsonData.cspOAuthClientSecret | |||
const credentials = `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`; | |||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}
)};``
src/plugin/datasource.ts
Outdated
const endSecs = dateToEpochSeconds(options.range.to); | ||
console.log("********endSecs", endSecs); |
There was a problem hiding this comment.
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.
src/plugin/datasource.ts
Outdated
grant_type: "client_credentials", | ||
}), | ||
headers: { | ||
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Authorization": credentials
@@ -15,6 +21,9 @@ export function WavefrontDatasource(instanceSettings, $q, backendSrv, templateSr | |||
this.backendSrv = new BackendSrvCancelledRetriesDecorator(backendSrv, $q); | |||
this.templateSrv = templateSrv; | |||
this.defaultRequestTimeoutSecs = 15; | |||
const appId = instanceSettings.jsonData.cspOAuthClientId | |||
const appSecret = instanceSettings.jsonData.cspOAuthClientSecret | |||
const credentials = `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`; | |||
|
There was a problem hiding this comment.
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}
)};``
} catch(e) { | ||
console.error(e); | ||
} | ||
this.requestConfigProto.headers["Authorization"] = "Bearer " + instanceSettings.jsonData.cspAPIToken; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with OAuth
@@ -515,4 +575,51 @@ export function WavefrontDatasource(instanceSettings, $q, backendSrv, templateSr | |||
return this.backendSrv.datasourceRequest(reqConfig); | |||
}; | |||
|
|||
|
|||
function refreshToken() { | |||
if (instanceSettings.jsonData.cspAPIToken) { |
There was a problem hiding this comment.
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
} | ||
|
||
// Execute the function initially | ||
refreshToken(); |
There was a problem hiding this comment.
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
refreshToken(); | ||
|
||
// Execute the function every 25 minutes (25 * 60 * 1000 milliseconds) | ||
const interval = setInterval(refreshToken, 25 * 60 * 1000); |
There was a problem hiding this comment.
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);
No description provided.