@whyvix/remote 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -24,6 +24,7 @@ export class DeploymentManager{
|
|
|
24
24
|
this.security=security;this.audit=audit;this.execFileFn=execFileFn;this.transferArtifact=transferArtifact;
|
|
25
25
|
}
|
|
26
26
|
listProfiles(){return [...this.profiles.values()].map(({alias,label="",remoteAlias})=>({alias,label,remoteAlias}));}
|
|
27
|
+
resolveOperation({profile:profileAlias,operation,commit}){return buildDeploymentOperation(this.#profile(profileAlias),{operation,commit});}
|
|
27
28
|
#profile(alias){const value=String(alias||"");if(!PROFILE_RE.test(value)||!this.profiles.has(value))fail("DEPLOY_PROFILE_DENIED","Deployment profile is not registered");return this.profiles.get(value);}
|
|
28
29
|
async prepareLocal({profile:profileAlias,commit,baseCommit=null}){
|
|
29
30
|
const profile=this.#profile(profileAlias);
|
|
@@ -33,8 +34,8 @@ export class DeploymentManager{
|
|
|
33
34
|
const {stdout:rootRaw}=await this.execFileFn("git",["rev-parse","--show-toplevel"],{cwd:repo,windowsHide:true,maxBuffer:1024*1024});
|
|
34
35
|
const root=this.security.resolveAllowed(rootRaw.trim());
|
|
35
36
|
if(path.resolve(root)!==path.resolve(repo))fail("DEPLOY_PROFILE_DENIED","Deployment repository root does not match profile");
|
|
36
|
-
const {stdout:status}=await this.execFileFn("git",["status","--porcelain"],{cwd:root,windowsHide:true,maxBuffer:1024*1024});
|
|
37
|
-
const dirty=status.split(/\r?\n/).filter(Boolean)
|
|
37
|
+
const {stdout:status}=await this.execFileFn("git",["status","--porcelain","--untracked-files=no"],{cwd:root,windowsHide:true,maxBuffer:1024*1024});
|
|
38
|
+
const dirty=status.split(/\r?\n/).filter(Boolean);
|
|
38
39
|
if(dirty.length)fail("DEPLOY_REPOSITORY_DIRTY","Deployment repository must be clean");
|
|
39
40
|
try{await this.execFileFn("git",["cat-file","-e",commit+"^{commit}"],{cwd:root,windowsHide:true,maxBuffer:1024*1024});}catch{fail("DEPLOY_COMMIT_INVALID","Deployment commit does not exist locally");}
|
|
40
41
|
let dependencyChanged=false;
|
|
@@ -22,9 +22,9 @@ export function releaseIdFromCommit(commit){
|
|
|
22
22
|
|
|
23
23
|
export function buildDeployHelperArgs(input){
|
|
24
24
|
const operation=String(input?.operation||""),commit=String(input?.commit||""),releaseId=releaseIdFromCommit(commit);
|
|
25
|
-
if(!["verify","prepare","status"].includes(operation))fail("DEPLOY_OPERATION_DENIED","Deployment helper operation is not allowed");
|
|
25
|
+
if(!["verify","prepare","certify","status","activate"].includes(operation))fail("DEPLOY_OPERATION_DENIED","Deployment helper operation is not allowed");
|
|
26
26
|
if(input?.releaseId!==undefined&&String(input.releaseId)!==releaseId)fail("DEPLOY_ARGUMENT_INVALID","Release identity does not match commit");
|
|
27
|
-
if(
|
|
27
|
+
if(["status","activate","certify"].includes(operation)){if(input?.artifactSha256!==undefined)fail("DEPLOY_ARGUMENT_INVALID",operation+" does not accept artifact checksum");return Object.freeze([operation,releaseId,commit]);}
|
|
28
28
|
const artifactSha256=String(input?.artifactSha256||"");if(!HASH_RE.test(artifactSha256))fail("DEPLOY_CHECKSUM_INVALID","Artifact SHA-256 is required");
|
|
29
29
|
return Object.freeze([operation,releaseId,commit,artifactSha256]);
|
|
30
30
|
}
|
|
@@ -11,6 +11,11 @@ function classifySshFailure(state,code){
|
|
|
11
11
|
if(text.includes("permission denied")||text.includes("authentication failed")||text.includes("no supported authentication methods available"))return "REMOTE_AUTH_FAILED";
|
|
12
12
|
return state.errorCode||"REMOTE_EXEC_FAILED";
|
|
13
13
|
}
|
|
14
|
+
function quoteRemoteArg(value){
|
|
15
|
+
const text=String(value);
|
|
16
|
+
return "'" + text.replaceAll("'", "'\"'\"'") + "'";
|
|
17
|
+
}
|
|
18
|
+
function serializeRemoteCommand(argv){return argv.map(quoteRemoteArg).join(" ");}
|
|
14
19
|
function appendBounded(state,key,chunk,maxBytes){
|
|
15
20
|
const current=Buffer.from(state[key],"utf8"),incoming=Buffer.from(chunk);
|
|
16
21
|
const room=Math.max(0,maxBytes-current.length);
|
|
@@ -52,7 +57,7 @@ export class RemoteExecutionManager {
|
|
|
52
57
|
for(const state of this.jobs.values())if(state.running)runningJobs++;
|
|
53
58
|
if(runningJobs>=this.maxRunningJobs)fail("REMOTE_JOB_LIMIT","Remote running job limit reached");
|
|
54
59
|
const target=this.#target(alias),remoteArgv=allowDeployHelper?["whyvix-deploy",...args]:this.#argv(executable,args),timeout=Math.max(1,Math.min(Number(timeoutMs)||30000,300000)),id=String(this.nextId++);
|
|
55
|
-
const sshArgs=["--",target.alias
|
|
60
|
+
const sshArgs=["--",target.alias,serializeRemoteCommand(remoteArgv)],child=this.spawnFn("ssh",sshArgs,{windowsHide:true,shell:false});
|
|
56
61
|
const state={id,ownerId:String(ownerId),alias:target.alias,executable,stdout:"",stderr:"",truncated:false,running:true,exitCode:null,child};this.jobs.set(id,state);this.audit({event:"remote.start",id,alias:state.alias,executable});
|
|
57
62
|
child.stdout?.on("data",x=>appendBounded(state,"stdout",x,this.maxOutputBytes));child.stderr?.on("data",x=>appendBounded(state,"stderr",x,this.maxOutputBytes));
|
|
58
63
|
const finish=()=>{if(state.timer){clearTimeout(state.timer);state.timer=null;}};
|
|
@@ -116,6 +116,7 @@ export function createToolExecutor({ security, processManager, remoteExecutionMa
|
|
|
116
116
|
if(tool==="remote.targets"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_TARGET_DENIED"});return{targets:remoteExecutionManager.listTargets()};}
|
|
117
117
|
if(tool==="remote.start"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_TARGET_DENIED"});return remoteExecutionManager.start(args);}
|
|
118
118
|
if(tool==="remote.deploy_status"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_TARGET_DENIED"});return remoteExecutionManager.startDeployHelper({alias:args.alias,input:{operation:"status",commit:args.commit},timeoutMs:args.timeoutMs,ownerId:args.ownerId});}
|
|
119
|
+
if(tool==="deploy.status_release"||tool==="deploy.certify_release"||tool==="deploy.activate_release"){if(!remoteExecutionManager||!deploymentManager)throw Object.assign(new Error("Deployment authority is not configured"),{code:"DEPLOY_PROFILE_DENIED"});const operation=tool==="deploy.status_release"?"status":tool==="deploy.certify_release"?"certify":"activate",resolved=deploymentManager.resolveOperation({profile:args.profile,operation,commit:args.commit});return remoteExecutionManager.startDeployHelper({alias:resolved.remoteAlias,input:{operation,commit:resolved.commit},timeoutMs:args.timeoutMs,ownerId:args.ownerId});}
|
|
119
120
|
if(tool==="remote.output"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_JOB_NOT_FOUND"});return remoteExecutionManager.output(args);}
|
|
120
121
|
if(tool==="remote.input"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_JOB_NOT_FOUND"});return remoteExecutionManager.input(args);}
|
|
121
122
|
if(tool==="remote.stop"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_JOB_NOT_FOUND"});return remoteExecutionManager.stop(args);}
|