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

Commit fdbbe4d

Browse files
committed
adding csp oauth changes
1 parent bf6aa26 commit fdbbe4d

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

src/partials/config.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ <h5>Wavefront Settings</h5>
1616
</div>
1717
</div>
1818

19+
<div class="gf-form-inline">
20+
<div class="gf-form">
21+
<span class="gf-form-label width-10">CSP OAuth Token</span>
22+
</div>
23+
<div class="gf-form max-width-24">
24+
<i class="gf-form-label max-width-22 text-center" ng-show="ctrl.cspOAuthExists">Configured</i>
25+
<a class="btn btn-secondary gf-form-btn" style="flex-grow:1" type="submit" ng-click="ctrl.resetCspOAuth()" ng-show="ctrl.cspOAuthExists">Reset</a>
26+
<input type="text" class="gf-form-input max-width-24" ng-hide="ctrl.cspOAuthExists" ng-model="ctrl.current.jsonData.cspOAuthClientId"/>
27+
<input type="text" class="gf-form-input max-width-24" ng-hide="ctrl.cspOAuthExists" ng-model="ctrl.current.jsonData.cspOAuthClientSecret"/>
28+
<info-popover mode="right-absolute" ng-hide="ctrl.cspOAuthExists">
29+
Paste your CSP OAuth token here. You can find and manage your tokens on your profile page in the Wavefront app
30+
</info-popover>
31+
</div>
32+
</div>
33+
qqq
1934
<div class="gf-form-inline">
2035
<div class="gf-form">
2136
<span class="gf-form-label width-10">CSP API Token</span>

src/plugin/configCtrl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ export class WavefrontConfigCtrl {
44
public current: any;
55
public wavefrontTokenExists = false;
66
public cspApiTokenExists = false;
7+
public cspOAuthExists = false;
78

89
constructor() {
910
this.wavefrontTokenExists = (this.current.jsonData.wavefrontToken != null && this.current.jsonData.wavefrontToken !== "");
1011
this.cspApiTokenExists = (this.current.jsonData.cspAPIToken != null && this.current.jsonData.cspAPIToken !== "");
12+
this.cspOAuthExists = (this.current.jsonData.cspOAuthClientId != null && this.current.jsonData.cspOAuthClientSecret !== "");
1113
}
1214

1315
public resetWavefrontToken() {
@@ -19,4 +21,10 @@ export class WavefrontConfigCtrl {
1921
this.current.jsonData.cspAPIToken = "";
2022
this.cspApiTokenExists = false;
2123
}
24+
25+
public resetCspOAuth() {
26+
this.current.jsonData.cspOAuthClientId = "";
27+
this.current.jsonData.cspOAuthClientSecret = "";
28+
this.cspOAuthExists = false;
29+
}
2230
}

src/plugin/datasource.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const queryKeyLookbackMillis = 7 * 24 * 60 * 60 * 1000;
88
const CSP_API_TOKEN_URL = "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize";
99
const CSP_OAUTH_TOKEN_URL = "https://console.cloud.vmware.com/csp/gateway/am/api/auth/authorize";
1010

11+
const appSecret = ""
12+
13+
14+
1115
export function WavefrontDatasource(instanceSettings, $q, backendSrv, templateSrv) {
1216
this.url = sanitizeUrl(instanceSettings.url);
1317

@@ -17,6 +21,9 @@ export function WavefrontDatasource(instanceSettings, $q, backendSrv, templateSr
1721
this.backendSrv = new BackendSrvCancelledRetriesDecorator(backendSrv, $q);
1822
this.templateSrv = templateSrv;
1923
this.defaultRequestTimeoutSecs = 15;
24+
const appId = instanceSettings.jsonData.cspOAuthClientId
25+
const appSecret = instanceSettings.jsonData.cspOAuthClientSecret
26+
const credentials = `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`;
2027

2128
this.requestConfigProto = {
2229
headers: {
@@ -43,7 +50,23 @@ export function WavefrontDatasource(instanceSettings, $q, backendSrv, templateSr
4350
} catch(e) {
4451
console.error(e);
4552
}
46-
} else {
53+
} else if (instanceSettings.jsonData.cspOAuthClientId && instanceSettings.jsonData.cspOAuthClientSecret) {
54+
try {
55+
fetch(CSP_OAUTH_TOKEN_URL, {
56+
method: "POST",
57+
body: JSON.stringify({
58+
grant_type: "client_credentials",
59+
}),
60+
headers: {
61+
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
62+
}
63+
})
64+
.then((response) => response.json())
65+
.then((json) => console.log(json));
66+
} catch(e) {
67+
console.error(e);
68+
}
69+
}else {
4770
this.requestConfigProto.withCredentials = true;
4871
}
4972

0 commit comments

Comments
 (0)