Skip to content

Commit

Permalink
fixup! Fix #26: Add support for running the action multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Dec 12, 2023
1 parent be61fd4 commit d47e8b1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 98 deletions.
73 changes: 31 additions & 42 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

100 changes: 45 additions & 55 deletions src/action/action.ts
Expand Up @@ -287,15 +287,15 @@ export class Action {
kind: SshConfigurationKind
isRunning: boolean
}): SshConfigurator {
if (isRunning) return new NoopSshConfiguration(this)
if (isRunning) return new LiveSshConfiguration()

core.debug(`Using SSH configuration: ${SshConfigurationKind[kind]}`)

switch (kind) {
case SshConfigurationKind.qemu:
return new QemuSshConfiguration(this)
return new InitialSshConfiguration(this)
case SshConfigurationKind.xhyve:
return new XhyveSshConfiguration(this)
return new InitialSshConfiguration(this)
default:
throw Error(`Unhandled implementation kind: $`)
}
Expand Down Expand Up @@ -521,67 +521,25 @@ class NoopVmInitializer implements VmInitializer {
}
}

export abstract class SshConfigurator {
protected readonly action: Action

constructor(action: Action) {
this.action = action
}

abstract config(ipAddress: string): void

protected get resourceDisk(): ResourceDisk {
return this.action['resourceDisk']
}

protected get publicSshKey(): fs.PathLike {
return this.action['publicSshKey']
}

protected get sshDirectory(): string {
return this.action['sshDirectory']
}

protected get cpaHost(): string {
return this.action['cpaHost']
}

protected get operatingSystem(): os.OperatingSystem {
return this.action['operatingSystem']
}

protected get privateSshKey(): fs.PathLike {
return this.action['privateSshKey']
}

protected get customSendEnv(): string {
return this.action['customSendEnv']
}

protected setupHostname(ipAddress: string): void {
if (ipAddress === 'localhost') ipAddress = '127.0.0.1'

execSync(
`sudo bash -c 'printf "${ipAddress} ${this.cpaHost}\n" >> /etc/hosts'`
)
}
export interface SshConfigurator {
config(ipAddress: string): void
}

class NoopSshConfiguration extends SshConfigurator {
class LiveSshConfiguration implements SshConfigurator {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
override config(_ipAddress: string): void {
config(_ipAddress: string): void {
// noop
}
}

class XhyveSshConfiguration extends SshConfigurator {
override config(ipAddress: string): void {
this.setupHostname(ipAddress)
class InitialSshConfiguration implements SshConfigurator {
protected readonly action: Action

constructor(action: Action) {
this.action = action
}
}

class QemuSshConfiguration extends SshConfigurator {
override config(ipAddress: string): void {
config(ipAddress: string): void {
core.debug('Configuring SSH')

this.createSSHConfig()
Expand Down Expand Up @@ -611,4 +569,36 @@ class QemuSshConfiguration extends SshConfigurator {
const publicKeyContent = fs.readFileSync(this.publicSshKey)
fs.appendFileSync(authorizedKeysPath, publicKeyContent)
}

private get publicSshKey(): fs.PathLike {
return this.action['publicSshKey']
}

private get sshDirectory(): string {
return this.action['sshDirectory']
}

private get cpaHost(): string {
return this.action['cpaHost']
}

private get operatingSystem(): os.OperatingSystem {
return this.action['operatingSystem']
}

private get privateSshKey(): fs.PathLike {
return this.action['privateSshKey']
}

private get customSendEnv(): string {
return this.action['customSendEnv']
}

private setupHostname(ipAddress: string): void {
if (ipAddress === 'localhost') ipAddress = '127.0.0.1'

execSync(
`sudo bash -c 'printf "${ipAddress} ${this.cpaHost}\n" >> /etc/hosts'`
)
}
}

0 comments on commit d47e8b1

Please sign in to comment.