Skip to content

Commit

Permalink
fix: Pick up username or token from environment variables (#187)
Browse files Browse the repository at this point in the history
* Pick up username or token from environment variables

* Tooltips

* tooltip modifications

* Allow for URL too, and change keys

* Update these

* Environment always gets precedence

* modified tooltips in extension settings to say they get overridden by env vars

Co-authored-by: Artemie Jurgenson <[email protected]>
  • Loading branch information
DarthHater and Artemie Jurgenson authored Mar 15, 2021
1 parent 6017e67 commit a2c4f84
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 6 additions & 2 deletions ext-src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {url} from 'inspector';
import * as vscode from 'vscode';
import { NexusExplorer } from './NexusExplorer';
import { NEXUS_EXPLORER_DATA_SOURCE, NEXUS_IQ_PUBLIC_APPLICATION_ID, NEXUS_IQ_SERVER_URL, NEXUS_IQ_USERNAME, NEXUS_IQ_USER_PASSWORD } from './utils/Config';
import {
NEXUS_EXPLORER_DATA_SOURCE,
NEXUS_IQ_PUBLIC_APPLICATION_ID,
NEXUS_IQ_SERVER_URL,
NEXUS_IQ_USERNAME,
NEXUS_IQ_USER_PASSWORD } from './utils/Config';

export function activate(context: vscode.ExtensionContext) {

Expand Down
11 changes: 5 additions & 6 deletions ext-src/models/IqComponentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { PackageType } from "../packages/PackageType";
import { CycloneDXSbomCreator } from "../cyclonedx/CycloneDXGenerator";
import { ReportResponse } from "../services/ReportResponse";
import {
NEXUS_EXPLORER_DATA_SOURCE,
NEXUS_IQ_MAX_EVAL_POLL_ATTEMPTS,
NEXUS_IQ_PUBLIC_APPLICATION_ID,
NEXUS_IQ_SERVER_URL,
Expand All @@ -50,15 +49,15 @@ export class IqComponentModel implements ComponentModel {
options: ComponentModelOptions
) {
this.applicationPublicId = options.configuration.get(NEXUS_IQ_PUBLIC_APPLICATION_ID) as string;
this.url = options.configuration.get(NEXUS_IQ_SERVER_URL) as string;
const username = options.configuration.get(NEXUS_IQ_USERNAME) as string;
// this one is converted rather than cast as string
this.url = (process.env.IQ_SERVER ? process.env.IQ_SERVER : options.configuration.get(NEXUS_IQ_SERVER_URL) as string);
const username = (process.env.IQ_USERNAME ? process.env.IQ_USERNAME : options.configuration.get(NEXUS_IQ_USERNAME) as string);
const token = (process.env.IQ_TOKEN ? process.env.IQ_TOKEN : options.configuration.get(NEXUS_IQ_USER_PASSWORD) as string);

const maximumEvaluationPollAttempts = parseInt(
String(options.configuration.get(NEXUS_IQ_MAX_EVAL_POLL_ATTEMPTS)), 10);
const password = options.configuration.get(NEXUS_IQ_USER_PASSWORD) as string;
const strictSSL = options.configuration.get(NEXUS_IQ_STRICT_SSL) as boolean;

this.requestService = new IqRequestService(this.url, username, password, maximumEvaluationPollAttempts, strictSSL, options.logger);
this.requestService = new IqRequestService(this.url, username, token, maximumEvaluationPollAttempts, strictSSL, options.logger);

this.logger = options.logger;
}
Expand Down
6 changes: 3 additions & 3 deletions ext-src/services/IqRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export class IqRequestService implements RequestService {

public setOptions(options: RefreshOptions) {
if (options.url) {
this.setUrl(options.url);
this.setUrl((process.env.IQ_SERVER ? process.env.IQ_SERVER : options.url));
}
if (options.username) {
this.user = options.username;
this.user = (process.env.IQ_USERNAME ? process.env.IQ_USERNAME : options.username);
}
if (options.token) {
this.password = options.token;
this.password = (process.env.IQ_TOKEN ? process.env.IQ_TOKEN : options.token);
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"nexusIQ.serverUrl": {
"type": "string",
"default": "http://127.0.0.1:8070",
"description": "URL (including port) of the Nexus IQ Server"
"description": "URL endpoint of the Nexus IQ Server (overridden by $IQ_SERVER from environment)"
},
"nexusIQ.strictSSL": {
"type": "boolean",
Expand All @@ -169,12 +169,12 @@
"nexusIQ.username": {
"type": "string",
"default": "admin",
"description": "Your Nexus IQ user name"
"description": "Nexus IQ user name/token (overridden by $IQ_USERNAME from environment)"
},
"nexusIQ.userPassword": {
"type": "string",
"default": "admin123",
"description": "Your Nexus IQ password"
"description": "Nexus IQ password (default: $IQ_TOKEN from environment)"
}
}
}
Expand Down

0 comments on commit a2c4f84

Please sign in to comment.