Skip to content

Commit

Permalink
feat: add user registration
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed May 24, 2024
1 parent ce601ef commit 33e3a16
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ jobs:
uses: actions/checkout@v4
- name: Run the action
uses: ./
# with:
with:
organization: ${{ secrets.ORGANIZATION }}
token: ${{ secrets.TOKEN }}

5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ branding:
inputs:
organization:
description: "The organization identifier."
required: false
required: true
token:
description: "The GoodKey API token."
required: true

runs:
using: "node20"
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as core from '@actions/core';
import path from 'node:path';
import { installGoodKey } from './utils';
import { SYSTEM_ROOT, installGoodKey, registerUser } from './utils';

const TOKEN = 'token';
const SYSTEM_ROOT = process.env['SystemRoot'] || 'C:\\Windows';
const ORGANIZATION = 'organization';

async function run() {
core.setSecret(core.getInput(TOKEN));
try {
// to System32
await installGoodKey(__dirname, path.join(SYSTEM_ROOT, 'System32'));
await registerUser(core.getInput(TOKEN), core.getInput(ORGANIZATION));
}
catch (error) {
if (error instanceof Error) {
Expand Down
53 changes: 40 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
import { promises as fs } from 'fs';
import * as path from 'path';
import { exec } from 'child_process';
import { promisify } from 'util';

export const SYSTEM_ROOT = process.env['SystemRoot'] || 'C:\\Windows';

const serviceFile = 'gksvc.exe';
const keyProvFile = 'gkcng.dll';
const certProvFile = 'gkcertsvc.dll';
const utilFile = 'gkutils.exe';
const allFiles = [serviceFile, keyProvFile, certProvFile, utilFile];

const execAsync = promisify(exec);

export async function installGoodKey(distDir: string, systemDir: string) {
for (const file of allFiles) {
const srcPath = path.join(distDir, file);
const destPath = path.join(systemDir, file);
await fs.copyFile(srcPath, destPath);
}
try {

for (const file of allFiles) {
const srcPath = path.join(distDir, file);
const destPath = path.join(systemDir, file);
await fs.copyFile(srcPath, destPath);
}

// Register DLLs
await exec(`regsvr32.exe /s "${path.join(systemDir, keyProvFile)}"`);
await exec(`regsvr32.exe /s "${path.join(systemDir, certProvFile)}"`);
// Register DLLs
await execAsync(`regsvr32.exe /s "${path.join(systemDir, keyProvFile)}"`);
await execAsync(`regsvr32.exe /s "${path.join(systemDir, certProvFile)}"`);

// Install service
await exec(`sc create gksvc binPath= "${path.join(systemDir, serviceFile)}" start= auto`);
// Install service
await execAsync(`sc create gksvc binPath= "${path.join(systemDir, serviceFile)}" start= auto`);

// Get User status using gkutils
const { stdout } = await exec(`${path.join(systemDir, utilFile)} auth status`);
console.log(stdout);
// Get User status using `gkutils auth status` and log it
const { stdout } = await execAsync(`${path.join(systemDir, utilFile)} auth status`);
console.log(stdout);
} catch (error) {
if (error instanceof Error) {
const message = 'stdout' in error && error.stdout ? error.stdout.toString() : error.message;
throw new Error(`Installation of GoodKey failed: ${message}`);
}
throw error;
}
}

export async function registerUser(token: string, organizationId: string) {
try {
const { stdout } = await execAsync(`${path.join(SYSTEM_ROOT, 'System32', utilFile)} auth register -t ${token} -o ${organizationId}`);
console.log(stdout);
} catch (error) {
if (error instanceof Error) {
const message = 'stdout' in error && error.stdout ? error.stdout.toString() : error.message;
throw new Error(`Registration of user failed: ${message}`);
}
throw error;
}
}

0 comments on commit 33e3a16

Please sign in to comment.