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

Add Profile SAS 9.4 (SASPy) #942

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions client/src/commands/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const checkProfileAndAuthorize =
commands.executeCommand("setContext", "SAS.librariesDisplayed", true);
libraryNavigator.refresh();
return finishAuthorization(profileConfig);
case ConnectionType.SASPY:
commands.executeCommand("setContext", "SAS.librariesDisplayed", true);
libraryNavigator.refresh();
return finishAuthorization(profileConfig);
default:
return finishAuthorization(profileConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import ItcLibraryAdapter from "../../connection/itc/ItcLibraryAdapter";
import RestLibraryAdapter from "../../connection/rest/RestLibraryAdapter";
import SaspyLibraryAdapter from "../../connection/saspy/SaspyLibraryAdapter";
import { ConnectionType } from "../profile";
import { LibraryAdapter } from "./types";

Expand All @@ -11,6 +12,8 @@ class LibraryAdapterFactory {
case ConnectionType.IOM:
case ConnectionType.COM:
return new ItcLibraryAdapter();
case ConnectionType.SASPY:
return new SaspyLibraryAdapter();
case ConnectionType.Rest:
default:
return new RestLibraryAdapter();
Expand Down
43 changes: 42 additions & 1 deletion client/src/components/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ enum ConnectionOptions {
SAS9COM = "SAS 9.4 (local)",
SAS9IOM = "SAS 9.4 (remote - IOM)",
SAS9SSH = "SAS 9.4 (remote - SSH)",
SAS9SASPY = "SAS 9.4 (SASPy)",
SASViya = "SAS Viya",
}

const CONNECTION_PICK_OPTS: string[] = [
ConnectionOptions.SASViya,
ConnectionOptions.SAS9SSH,
ConnectionOptions.SAS9SASPY,
ConnectionOptions.SAS9IOM,
ConnectionOptions.SAS9COM,
];
Expand Down Expand Up @@ -60,6 +62,7 @@ export enum ConnectionType {
IOM = "iom",
Rest = "rest",
SSH = "ssh",
SASPY = "saspy",
}

/**
Expand Down Expand Up @@ -91,6 +94,12 @@ export interface SSHProfile extends BaseProfile {
privateKeyFilePath?: string;
}

export interface SASPYProfile extends BaseProfile {
connectionType: ConnectionType.SASPY;
cfgname: string;
pythonpath: string;
}

export interface COMProfile extends BaseProfile {
connectionType: ConnectionType.COM;
host: string;
Expand All @@ -103,7 +112,12 @@ export interface IOMProfile extends BaseProfile {
port: number;
}

export type Profile = ViyaProfile | SSHProfile | COMProfile | IOMProfile;
export type Profile =
| ViyaProfile
| SSHProfile
| SASPYProfile
| COMProfile
| IOMProfile;

export enum AutoExecType {
File = "file",
Expand Down Expand Up @@ -469,6 +483,15 @@ export class ProfileConfig {
pv.error = l10n.t("Missing username in active profile.");
return pv;
}
} else if (profile.connectionType === ConnectionType.SASPY) {
// if (!profile.cfgname) {
// pv.error = l10n.t("Missing cfgname in active profile.");
// return pv;
// }
// if (!profile.pythonpath) {
// pv.error = l10n.t("Missing Python path in active profile.");
// return pv;
// }
}

pv.profile = profileDetail.profile;
Expand Down Expand Up @@ -590,6 +613,10 @@ export class ProfileConfig {
profileClone.privateKeyFilePath = keyPath;
}

await this.upsertProfile(name, profileClone);
} else if (profileClone.connectionType === ConnectionType.SASPY) {
profileClone.cfgname = "";
// profileClone.sasOptions = [];
await this.upsertProfile(name, profileClone);
} else if (profileClone.connectionType === ConnectionType.COM) {
profileClone.sasOptions = [];
Expand Down Expand Up @@ -668,6 +695,8 @@ export enum ProfilePromptType {
Port,
Username,
PrivateKeyFilePath,
Cfgname,
PYTHONpath,
}

/**
Expand Down Expand Up @@ -810,6 +839,16 @@ const input: ProfilePromptInput = {
placeholder: l10n.t("Enter the local private key file path"),
description: l10n.t("To use the SSH Agent or a password, leave blank."),
},
[ProfilePromptType.Cfgname]: {
title: l10n.t("SAS Server Cfgname"),
placeholder: l10n.t("Enter your cfgname"),
description: l10n.t("Enter your SAS server cfgname."),
},
[ProfilePromptType.PYTHONpath]: {
title: l10n.t("Server Path"),
placeholder: l10n.t("Enter the server path"),
description: l10n.t("Enter the server path of the PYTHON Executable."),
}
};

/**
Expand All @@ -828,6 +867,8 @@ function mapQuickPickToEnum(connectionTypePickInput: string): ConnectionType {
return ConnectionType.Rest;
case ConnectionOptions.SAS9SSH:
return ConnectionType.SSH;
case ConnectionOptions.SAS9SASPY:
return ConnectionType.SASPY;
case ConnectionOptions.SAS9COM:
return ConnectionType.COM;
case ConnectionOptions.SAS9IOM:
Expand Down
3 changes: 3 additions & 0 deletions client/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LogLine as ComputeLogLine,
LogLineTypeEnum as ComputeLogLineTypeEnum,
} from "./rest/api/compute";
import { getSession as getSASPYSession } from "./saspy";
import { Session } from "./session";
import { getSession as getSSHSession } from "./ssh";

Expand Down Expand Up @@ -54,6 +55,8 @@ export function getSession(): Session {
return getRestSession(toRestConfig(validProfile.profile));
case ConnectionType.SSH:
return getSSHSession(validProfile.profile);
case ConnectionType.SASPY:
return getSASPYSession(validProfile.profile);
case ConnectionType.COM:
return getITCSession(validProfile.profile, ITCProtocol.COM);
case ConnectionType.IOM:
Expand Down
82 changes: 82 additions & 0 deletions client/src/connection/saspy/CodeRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright © 2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { commands } from "vscode";

import { SASPYSession } from ".";
import { LogLine, getSession } from "..";
import { useRunStore } from "../../store";

let wait: Promise<string> | undefined;

export async function runCode(
code: string,
startTag: string = "",
endTag: string = "",
): Promise<string> {
const task = () => _runCode(code, startTag, endTag);

wait = wait ? wait.then(task) : task();
return wait;
}

async function _runCode(
code: string,
startTag: string = "",
endTag: string = "",
): Promise<string> {
// If we're already executing code, lets wait for it
// to finish up.
let unsubscribe;
if (useRunStore.getState().isExecutingCode) {
await new Promise((resolve) => {
unsubscribe = useRunStore.subscribe(
(state) => state.isExecutingCode,
(isExecutingCode) => !isExecutingCode && resolve(true),
);
});
}

const { setIsExecutingCode } = useRunStore.getState();
setIsExecutingCode(true, false);
commands.executeCommand("setContext", "SAS.running", true);
const session = getSession();

let logText = "";
const onExecutionLogFn = session.onExecutionLogFn;
const outputLines = [];

const addLine = (logLines: LogLine[]) =>
outputLines.push(...logLines.map(({ line }) => line));

try {
await session.setup(true);

// Lets capture output to use it on
session.onExecutionLogFn = addLine;

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
await (session as SASPYSession).run(code)

const logOutput = outputLines.filter((line) => line.trim()).join("");

logText =
startTag && endTag
? logOutput
.slice(
logOutput.lastIndexOf(startTag),
logOutput.lastIndexOf(endTag),
)
.replace(startTag, "")
.replace(endTag, "")
: logOutput;
} finally {
unsubscribe && unsubscribe();
// Lets update our session to write to the log
session.onExecutionLogFn = onExecutionLogFn;

setIsExecutingCode(false);
commands.executeCommand("setContext", "SAS.running", false);
}

return logText;
}
Loading