Skip to content
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

feat(@sap-ux/odata service inquirer): Adds system selection prompting #2374

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/odata-service-inquirer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ config.snapshotFormat = {
escapeString: false,
printBasicPrototype: false
};
config.collectCoverage = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

revert

module.exports = config;
4 changes: 1 addition & 3 deletions packages/odata-service-inquirer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
"@types/inquirer-autocomplete-prompt": "2.0.1",
"@types/inquirer": "8.2.6",
"@types/lodash": "4.14.202",
"jest-extended": "3.2.4",
"lodash": "4.17.21"
},
"jest-extended": "3.2.4" },
"engines": {
"node": ">=18.x"
}
Expand Down
14 changes: 10 additions & 4 deletions packages/odata-service-inquirer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import autocomplete from 'inquirer-autocomplete-prompt';
import { ERROR_TYPE, ErrorHandler } from './error-handler/error-handler';
import { initI18nOdataServiceInquirer } from './i18n';
import { getQuestions } from './prompts';
import { newSystemChoiceValue } from './prompts/datasources/sap-system/new-system/questions';
import { newSystemChoiceValue } from './prompts/datasources/sap-system/system-selection';
import LoggerHelper from './prompts/logger-helper';
import {
DatasourceType,
Expand Down Expand Up @@ -86,18 +86,24 @@ async function prompt(
}

export {
// @derecated - temp export to support to support open source migration
DatasourceType,
// @deprecated - temp export to support to support open source migration
ERROR_TYPE,
// @deprecated - temp export to support to support open source migration
ErrorHandler,
// @deprecated - temp export to support to support open source migration
OdataVersion,
getPrompts,
// @deprecated - temp export to support to support open source migration
newSystemChoiceValue,
// @deprecated - temp export to support to support open source migration
type SapSystemType,
getPrompts,
prompt,
promptNames,
type CapRuntime,
type CapService,
type InquirerAdapter,
type OdataServiceAnswers,
type OdataServicePromptOptions,
type SapSystemType
type OdataServicePromptOptions
};
16 changes: 13 additions & 3 deletions packages/odata-service-inquirer/src/prompts/connectionValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface Validity {
canSkipCertError?: boolean;
}

type ValidationResult = string | boolean | IValidationLink;
export type ValidationResult = string | boolean | IValidationLink;

// Cert errors that may be ignored by prompt user
const ignorableCertErrors = [ERROR_TYPE.CERT_SELF_SIGNED, ERROR_TYPE.CERT_SELF_SIGNED_CERT_IN_CHAIN];
Expand Down Expand Up @@ -75,6 +75,7 @@ export class ConnectionValidator {
private _serviceInfo: ServiceInfo | undefined;
private _connectedUserName: string | undefined;
private _connectedSystemName: string | undefined;
// todo: private _isS4HanaCloud: boolean | undefined;

private _refreshToken: string | undefined;
/**
Expand Down Expand Up @@ -371,6 +372,7 @@ export class ConnectionValidator {

if (this._serviceProvider) {
LoggerHelper.attachAxiosLogger(this._serviceProvider.interceptors);
//this._isS4HanaCloud = await (this._serviceProvider as AbapServiceProvider).isS4Cloud();
}

if (!odataVersion || odataVersion === ODataVersion.v2) {
Expand Down Expand Up @@ -433,7 +435,7 @@ export class ConnectionValidator {
* @param serviceInfo the service info
* @returns the service provider
*/
private getAbapOnCloudServiceProvider(url?: URL, serviceInfo?: ServiceInfo): ServiceProvider {
private getAbapOnCloudServiceProvider(url?: URL, serviceInfo?: ServiceInfo): AbapServiceProvider {
if (this.systemAuthType === 'reentranceTicket' && url) {
return createForAbapOnCloud({
environment: AbapCloudEnvironment.EmbeddedSteampunk,
Expand All @@ -454,6 +456,8 @@ export class ConnectionValidator {

/**
* Validate the system connectivity with the specified service info (containing UAA details).
* This will create a connection to the system, updating the service provider reference.
* The connected user name will be cached for later use.
*
* @param serviceInfo the service info containing the UAA details
* @param odataVersion the odata version to restrict the catalog requests if only a specific version is required
Expand Down Expand Up @@ -490,6 +494,7 @@ export class ConnectionValidator {
* @param options.forceReValidation force re-validation of the url
* @param options.isSystem if true, the url will be treated as a system url rather than a service url, this value is retained for subsequent calls
* @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
* @param options.systemAuthType the system auth type used to create system connections, if not specified or `isSystem` is false or undefined, `basic` is assumed
* @returns true if the url is reachable, false if not, or an error message string
*/
public async validateUrl(
Expand All @@ -498,18 +503,23 @@ export class ConnectionValidator {
ignoreCertError = false,
forceReValidation = false,
isSystem = false,
odataVersion
odataVersion,
systemAuthType
}: {
ignoreCertError?: boolean;
forceReValidation?: boolean;
isSystem?: boolean;
odataVersion?: ODataVersion;
systemAuthType?: SystemAuthType;
} = {}
): Promise<ValidationResult> {
if (this.isEmptyString(serviceUrl)) {
this.resetValidity();
return false;
}
if (systemAuthType) {
this.systemAuthType = systemAuthType;
}
try {
const url = new URL(serviceUrl);
if (!forceReValidation && this.isUrlValidated(serviceUrl)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { PromptState, getDefaultChoiceIndex, getHostEnvironment } from '../../..
import { ConnectionValidator } from '../../../connectionValidator';
import LoggerHelper from '../../../logger-helper';
import { errorHandler } from '../../../prompt-helpers';
import { getSystemServiceQuestion, getSystemUrlQuestion, getUserSystemNameQuestion } from '../new-system/questions';
import { getSystemUrlQuestion, getUserSystemNameQuestion } from '../new-system/questions';
import { newSystemPromptNames } from '../new-system/types';
import { validateServiceKey } from '../validators';
import { getABAPInstanceChoices } from './cf-helper';
import { type ServiceAnswer, getSystemServiceQuestion } from '../service-selection';

const abapOnBtpPromptNamespace = 'abapOnBtp';
const systemUrlPromptName = `${abapOnBtpPromptNamespace}:${newSystemPromptNames.newSystemUrl}` as const;
Expand All @@ -41,10 +42,12 @@ interface AbapOnBtpAnswers extends Partial<OdataServiceAnswers> {
* @param promptOptions The prompt options which control the service selection and system name]
* @returns The list of questions for the ABAP on BTP system
*/
export function getAbapOnBTPSystemQuestions(promptOptions?: OdataServicePromptOptions): Question<AbapOnBtpAnswers>[] {
export function getAbapOnBTPSystemQuestions(
promptOptions?: OdataServicePromptOptions
): Question<AbapOnBtpAnswers & ServiceAnswer>[] {
PromptState.reset();
const connectValidator = new ConnectionValidator();
const questions: Question[] = [];
const questions: Question<AbapOnBtpAnswers & ServiceAnswer>[] = [];
questions.push({
type: 'list',
name: abapOnBtpPromptNames.abapOnBtpAuthType,
Expand Down Expand Up @@ -117,6 +120,7 @@ export function getAbapOnBTPSystemQuestions(promptOptions?: OdataServicePromptOp

/**
* Validate the service info for the ABAP on BTP system. This function will validate the service key file and the connection to the ABAP system.
* Updates the prompt state with the connected system.
*
* @param abapService the abap service as provided by CF tools
* @param connectionValidator connection validator instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import type {
OdataServiceAnswers,
OdataServicePromptOptions,
ServiceSelectionPromptOptions,
SystemNamePromptOptions,
promptNames
SystemNamePromptOptions
} from '../../../../types';
import { PromptState } from '../../../../utils';
import { ConnectionValidator } from '../../../connectionValidator';
import { getSystemServiceQuestion, getSystemUrlQuestion, getUserSystemNameQuestion } from '../new-system/questions';
import { newSystemPromptNames, type ServiceAnswer } from '../new-system/types';
import { getSystemUrlQuestion, getUserSystemNameQuestion } from '../new-system/questions';
import { newSystemPromptNames } from '../new-system/types';
import { type ServiceAnswer, getSystemServiceQuestion } from '../service-selection';

const abapOnPremPromptNamespace = 'abapOnPrem';
const systemUrlPromptName = `${abapOnPremPromptNamespace}:${newSystemPromptNames.newSystemUrl}` as const;
Expand All @@ -28,7 +28,6 @@ interface AbapOnPremAnswers extends Partial<OdataServiceAnswers> {
[systemUrlPromptName]?: string;
[abapOnPremInternalPromptNames.systemUsername]?: string;
[abapOnPremInternalPromptNames.systemPassword]?: string;
[promptNames.serviceSelection]?: ServiceAnswer;
}

/**
Expand All @@ -37,13 +36,15 @@ interface AbapOnPremAnswers extends Partial<OdataServiceAnswers> {
* @param promptOptions options for prompts. Applicable options are: {@link ServiceSelectionPromptOptions}, {@link SystemNamePromptOptions}
* @returns property questions for the Abap on-premise datasource
*/
export function getAbapOnPremQuestions(promptOptions?: OdataServicePromptOptions): Question<AbapOnPremAnswers>[] {
export function getAbapOnPremQuestions(
promptOptions?: OdataServicePromptOptions
): Question<AbapOnPremAnswers & ServiceAnswer>[] {
PromptState.reset();
const connectValidator = new ConnectionValidator();
// Prompt options
const requiredOdataVersion = promptOptions?.serviceSelection?.requiredOdataVersion;

const questions: Question<AbapOnPremAnswers>[] = getAbapOnPremSystemQuestions(
const questions: Question<AbapOnPremAnswers & ServiceAnswer>[] = getAbapOnPremSystemQuestions(
promptOptions?.userSystemName,
connectValidator,
requiredOdataVersion
Expand Down Expand Up @@ -106,9 +107,10 @@ export function getAbapOnPremSystemQuestions(
guiOptions: {
mandatory: true
},
guiType: 'login',
name: abapOnPremInternalPromptNames.systemPassword,
message: t('prompts.systemPassword.message'),
guiType: 'login',
//guiType: 'login',
mask: '*',
default: '',
validate: async (password, answers: AbapOnPremAnswers & Answers) => {
Expand Down
Loading
Loading