@cloud-cli/vm 1.2.0 → 1.3.1

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/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ interface NameAndPathOption {
7
7
  }
8
8
  declare function list(): Promise<string[]>;
9
9
  declare function ls(options: NameAndPathOption): Promise<string[]>;
10
+ declare function fixPermissions(options: NameOption): Promise<boolean>;
10
11
  declare function rm(options: NameAndPathOption): Promise<boolean>;
11
12
  declare function cat(options: NameAndPathOption): Promise<string>;
12
13
  declare function show(options: NameOption): Promise<{
@@ -26,5 +27,6 @@ declare const _default: {
26
27
  ls: typeof ls;
27
28
  rm: typeof rm;
28
29
  cat: typeof cat;
30
+ fixPermissions: typeof fixPermissions;
29
31
  };
30
32
  export default _default;
package/dist/index.js CHANGED
@@ -23,7 +23,13 @@ async function ls(options) {
23
23
  const { name, path = '' } = options;
24
24
  const root = await getVolumeMountpoint(name);
25
25
  const files = await exec('ls', ['-1', join(root, path)]);
26
- return files.stdout.trim().split('\n');
26
+ return files.stdout.trim().split('\n').filter(Boolean);
27
+ }
28
+ async function fixPermissions(options) {
29
+ const { name } = options;
30
+ const root = await getVolumeMountpoint(name);
31
+ const result = await exec('chmod', ['-R', 'a+w', root]);
32
+ return result.ok;
27
33
  }
28
34
  async function rm(options) {
29
35
  const { name, path } = options;
@@ -82,4 +88,4 @@ async function prune() {
82
88
  await exec('docker', ['volume', 'prune']);
83
89
  return '';
84
90
  }
85
- export default { add, remove, list, show, prune, ls, rm, cat };
91
+ export default { add, remove, list, show, prune, ls, rm, cat, fixPermissions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/vm",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Docker volume management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.spec.ts CHANGED
@@ -48,6 +48,17 @@ describe('volume manager', () => {
48
48
  });
49
49
  });
50
50
 
51
+ describe('fixPermissions', () => {
52
+ it('should fix write permissions on volume folder', async () => {
53
+ const outputs = [inspectOutput, ''];
54
+ execMocks.exec = jest.fn().mockImplementation(() => ({ ok: true, stdout: outputs.shift() }));
55
+
56
+ await expect(vm.fixPermissions({ name: 'test' })).resolves.toEqual(true);
57
+ expect(exec.exec).toHaveBeenCalledWith('docker', ['volume', 'inspect', 'test']);
58
+ expect(exec.exec).toHaveBeenCalledWith('chmod', ['-R', 'a+w', '/var/lib/docker/volumes/test/_data']);
59
+ });
60
+ });
61
+
51
62
  describe('ls', () => {
52
63
  it('should list files of a volume and path', async () => {
53
64
  const outputs = [inspectOutput, 'dir', inspectOutput, 'a.txt\nb.txt'];
package/src/index.ts CHANGED
@@ -41,7 +41,15 @@ async function ls(options: NameAndPathOption) {
41
41
  const root = await getVolumeMountpoint(name);
42
42
  const files = await exec('ls', ['-1', join(root, path)]);
43
43
 
44
- return files.stdout.trim().split('\n');
44
+ return files.stdout.trim().split('\n').filter(Boolean);
45
+ }
46
+
47
+ async function fixPermissions(options: NameOption) {
48
+ const { name } = options;
49
+ const root = await getVolumeMountpoint(name);
50
+ const result = await exec('chmod', ['-R', 'a+w', root]);
51
+
52
+ return result.ok;
45
53
  }
46
54
 
47
55
  async function rm(options: NameAndPathOption) {
@@ -122,4 +130,4 @@ async function prune() {
122
130
  return '';
123
131
  }
124
132
 
125
- export default { add, remove, list, show, prune, ls, rm, cat };
133
+ export default { add, remove, list, show, prune, ls, rm, cat, fixPermissions };