Skip to content

Commit

Permalink
Merge pull request #126 from rolldone/working
Browse files Browse the repository at this point in the history
Working
  • Loading branch information
rolldone authored Jul 15, 2022
2 parents a49cd23 + 56e229d commit 86968e4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app/devsync/compute/Watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default class Watcher {

gitIgnore = [
...gitIgnore,
...defaultIgnores
...defaultIgnores,
this.config.privateKey
]

let resCHeckGItIgnores = (() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/devsync/services/DevSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({

setTimeout(() => {
this.construct(this._cli);
}, 1000);
}, 2000);
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/devsync2/services/DevSync2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r');
setTimeout(() => {
this.construct(this._cli);
}, 1000);
}, 2000);
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down
13 changes: 12 additions & 1 deletion src/app/directaccess/compute/DirectAccess.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConfigInterface } from "@root/app/init/compute/Config";
import BaseModel, { BaseModelInterface } from "@root/base/BaseModel";
import SSHConfig, { SSHConfigInterface } from "@root/tool/ssh-config";
import { readFileSync, writeFileSync } from "fs";
import { existsSync, readFileSync, writeFileSync } from "fs";
import upath from 'upath';
import os from 'os';
import * as child_process from 'child_process';
Expand Down Expand Up @@ -33,6 +33,8 @@ const DirectAccess = BaseModel.extend<Omit<DirectAccessInterface, 'model'>>({
/* Manage the ssh_config from .ssh home dir */
this._ssh_config = SSHConfig.parse(readFileSync(_configFilePath).toString());



/* Loop every ssh_config collection from .ssh home dir */
for (var a = 0; a < _direct_access.ssh_configs.length; a++) {
var sshSection = this._ssh_config.find({ Host: _direct_access.ssh_configs[a].Host })
Expand All @@ -44,6 +46,15 @@ const DirectAccess = BaseModel.extend<Omit<DirectAccessInterface, 'model'>>({

/* Insert the curent new config */
for (var a = 0; a < _direct_access.ssh_configs.length; a++) {
// If the IdentityFile is a relative convert to absolute path
if (existsSync(upath.normalize(process.cwd() + "/" + _direct_access.ssh_configs[a].IdentityFile)) == true) {
_direct_access.ssh_configs[a].IdentityFile = upath.normalize(process.cwd() + "/" + _direct_access.ssh_configs[a].IdentityFile);
} else { }
if (os.platform() == "win32") {
child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Inheritance:r`)
child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Grant:r "%username%":"(F)"`)
// Source : https://stackoverflow.com/questions/2928738/how-to-grant-permission-to-users-for-a-directory-using-command-line-in-windows
}
this._ssh_config.append(_direct_access.ssh_configs[a]);
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/forcersync/compute/SyncPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,11 @@ const SyncPush = BaseModel.extend<Omit<SyncPushInterface, 'model'>>({
}
}
}

_filterPatternRules.ignores = [
...newIgnores,
..._filterPatternRules.ignores
..._filterPatternRules.ignores,
this._config.privateKeyPath
];

let extraWatch: Array<{
Expand Down
15 changes: 14 additions & 1 deletion src/app/init/compute/Config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import BaseModel, { BaseModelInterface } from "@root/base/BaseModel";
import { CliInterface, EXIT_CODE } from "../services/CliService";
import path, { join as pathJoin } from "path";
import { readFileSync, existsSync, statSync, createReadStream } from "fs";
import { readFileSync, existsSync, statSync, createReadStream, chmod, chmodSync } from "fs";
import { String, uniq } from "lodash";
import upath from 'upath';
const { parse } = require("jsonplus");
import YAML from 'yaml'
import os from 'os';
import { MasterDataInterface } from "@root/bootstrap/StartMasterData";
import filendir from 'filendir';
import { execSync } from "child_process";

export const CONFIG_FILE_NAME = "sync-config.yaml";
export type trigger_permission = {
Expand Down Expand Up @@ -189,6 +190,14 @@ const Config = BaseModel.extend<ConfigInterface>({
}
/** @type {boolean} */
let hasPasspharse = await this._hasPassphrase(this._config.privateKey);
if (os.platform() == "win32") {
execSync(`Icacls "${this._config.privateKey}" /Inheritance:r`)
execSync(`Icacls "${this._config.privateKey}" /Grant:r "%username%":"(F)"`)
// Source :: https://stackoverflow.com/questions/2928738/how-to-grant-permission-to-users-for-a-directory-using-command-line-in-windows
}else{
chmodSync(this._config.privateKey, 0o400);
}
// console.log(this._config.privateKey);
if (hasPasspharse == true) {
this.cli.read("Enter Passphrase to connect : ", true).then(answer => {
this.password = this._config.password = answer;
Expand Down Expand Up @@ -280,6 +289,10 @@ const Config = BaseModel.extend<ConfigInterface>({
}
});

_overrideSyncConfig = {
...this._config,
..._overrideSyncConfig,
}
// Override the sync-config if getting new and replace old version
filendir.writeFileSync(path.resolve("", "sync-config.yaml"), YAML.stringify(_overrideSyncConfig, null), "utf8");
} catch (ex) {
Expand Down
5 changes: 4 additions & 1 deletion src/app/init/services/InitConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const InitConfigService = BaseService.extend<InitConfigInterface>({
test = YAML.parse(readFileSync(upath.normalizeSafe(basePathFolder + '/example.yaml'), 'utf8'));
test.sync_collection.src = sync_collection_src || upath.normalize(homedir() + "/sync_collections");
}
// console.log("test.sync_collection.src :: ",test.sync_collection.src);
if (existsSync(path.resolve('sync-config.yaml')) == false) {
writeFileSync(CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8');
if (silent == false) {
Expand All @@ -59,6 +60,8 @@ const InitConfigService = BaseService.extend<InitConfigInterface>({
console.log('---------------------------------------------------')
console.log(' Replace xxx_sync-config.yaml to sync-config.yaml');
console.log('---------------------------------------------------')
}else{
writeFileSync(CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8');
}
}
if (existsSync('.sync_ignore') == false) {
Expand Down Expand Up @@ -96,7 +99,7 @@ const InitConfigService = BaseService.extend<InitConfigInterface>({
this.generateTemplate(true, upath.normalize(answers.path));
setTimeout(() => {
masterData.saveData('command.load_save.data', {});
}, 1000);
}, 3000);
})
return;
}
Expand Down

0 comments on commit 86968e4

Please sign in to comment.