Skip to content

Commit fece0cc

Browse files
Merge pull request #2 from easymorph/ver.1.3
Ver.1.3.0 ems-cmd ver 1.3.0 added: space auth, parameters for tasks; new commands: space status, spaces list;
2 parents aa12501 + 335caae commit fece0cc

22 files changed

+551
-232
lines changed

README.md

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ EasyMorph Server Command Line Client (in further text – **ems-cmd**) allows yo
1212
#### Download
1313
ems-cmd comes together with EasyMorph Server. Also it can be [downloaded](https://github.com/easymorph/server-cmd/releases) separately
1414

15-
Current version is 1.2.0.
16-
1715

1816
#### General command format:
1917

@@ -33,6 +31,13 @@ ems-cmd may return one of the following exit codes:
3331
* `0` ems-cmd was successfully run to completion.
3432
* `1` A fatal error occurred during command parsing or execution.
3533

34+
#### Authorization
35+
For password protected spaces you should pass password via command parameter `-password`.
36+
```
37+
ems-cmd upload http://192.168.100.200:6330 -space Default -password your_password -source D:\your\local\folder\file.xml -target \
38+
```
39+
In the example above, a session will be opened for the specified space Default, of course if password was correct. In case of incorrect password or public spaces, error will be thrown.
40+
Some hash computations are applied to the password before it is sent to the server.
3641

3742

3843
### Commands
@@ -53,24 +58,87 @@ Retrieving server status...
5358
STATUS:
5459
StatusCode: OK
5560
StatusMessage: Server is OK
56-
ServerVersion:1.2.0.0
61+
ServerVersion:1.3.0.0
62+
```
63+
64+
65+
#### Retrieve spaces list
66+
A list of all spaces will be displayed. This command doesn't require authorization.
67+
68+
```bash
69+
ems-cmd listspaces http://192.168.100.200:6330
70+
```
71+
###### Parameters
72+
This command has no additional parameters
73+
74+
###### Output
5775
```
76+
Available spaces:
77+
* closed one
78+
Default
79+
Listing done
80+
```
81+
Asterisk `*` means that the space requires an authorization.
82+
83+
84+
#### Space status
85+
Returns specified space status. This command may require authorization if space is password protected.
86+
87+
```bash
88+
ems-cmd spacestatus http://192.168.100.200:6330 -space "closed one" -password some_password
89+
```
90+
###### Parameters
91+
92+
* `-space` - space name.
93+
* `-password` - if password is required.
94+
95+
###### Output
96+
```
97+
Checking space default status...
98+
Space: Default
99+
IsPublic: True
100+
Permissions: FilesList, FileDownload
101+
done
102+
```
103+
104+
58105

59106
### Tasks Related
60107
#### Start the task
61108
This command will start specified task and wait until it is done.
62109

63110
To start the task you need to know space name and the task ID.
64111
Make sure to check the task execution server log to determine task execution info.
112+
113+
65114
```
66115
ems-cmd run http://192.168.100.200:6330 -space Default -taskID 59b824f0-4b81-453f-b9e0-1c58b97c9fb9
67116
```
68117
###### Parameters
69118
* `-space` - space name, e.g. `Default`
70119
* `-taskID` - task guid.
120+
* `-param:XXX ZZ` - set task parameter `XXX` with value `ZZ`.
71121

72122
Task guid can be found in the browser location toolbar. E.g, if you have clicked on the edit task link, your browser location seems to be `http://localhost:6330/default/tasks/edit/59b824f0-4b81-453f-b9e0-1c58b97c9fb9`, where `59b824f0-4b81-453f-b9e0-1c58b97c9fb9` - is a desired value
73123

124+
If you want to pass (or override) parameters that were defined in morph project, add `-param:XXX ZZ` to ems-cmd execution line.
125+
Where `XXX` is a parameter name and `ZZ` is a parameter value.
126+
At least one space between parameter name and parameter value is required.
127+
128+
129+
E.g. If you've defined parameter `Timeout` in your morph project, and want to set it to 73 use `-param:Timeout 73`. Pay attention, that parameters are case sensitive.
130+
131+
132+
Examples:
133+
134+
135+
Set parameter `Rounds` to `10` : `-param:Timeout 73`
136+
137+
Set parameter `Full name` to `John Smith` : `-param:"Full name" "John Smith"`
138+
139+
Set parameter `From Date` to the `10th of December 2000` : `-param:"From Date" "2000-12-10"` (ISO 8601 date format)
140+
141+
74142
###### Output
75143
```
76144
Attempting to start task 59b824f0-4b81-453f-b9e0-1c58b97c9fb9
@@ -91,9 +159,28 @@ ems-cmd runasync http://192.168.100.200:6330 -space Default -taskID 59b824f0-4b8
91159
###### Parameters
92160
* `-space` - space name, e.g. `Default`
93161
* `-taskID` - task guid.
162+
* `-param:XXX ZZ` - set task parameter `XXX` with value `ZZ`.
94163

95164
Task guid can be found in the browser location toolbar. E.g, if you have clicked on the edit task link, your browser location seems to be `http://localhost:6330/default/tasks/edit/59b824f0-4b81-453f-b9e0-1c58b97c9fb9`, where `59b824f0-4b81-453f-b9e0-1c58b97c9fb9` - is a desired value
96165

166+
If you want to pass (or override) parameters that were defined in morph project, add `-param:XXX ZZ` to ems-cmd execution line.
167+
Where `XXX` is a parameter name and `ZZ` is a parameter value.
168+
At least one space between parameter name and parameter value is required.
169+
170+
171+
E.g. If you've defined parameter `Timeout` in your morph project, and want to set it to 73 use `-param:Timeout 73`. Pay attention, that parameters are case sensitive.
172+
173+
174+
Examples:
175+
176+
177+
Set parameter `Rounds` to `10` : `-param:Timeout 73`
178+
179+
Set parameter `Full name` to `John Smith` : `-param:"Full name" "John Smith"`
180+
181+
Set parameter `From Date` to the `10th of December 2000` : `-param:"From Date" "2000-12-10"` (ISO 8601 date format)
182+
183+
97184
###### Output
98185
```
99186
Attempting to start task 59b824f0-4b81-453f-b9e0-1c58b97c9fb9

src/BusinessLogic/Commands/BaseCommand.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Morph.Server.Sdk.Client;
2+
using Morph.Server.Sdk.Model;
23
using MorphCmd.Interfaces;
4+
using MorphCmd.Models;
35
using System;
46
using System.Collections.Generic;
57
using System.Linq;
@@ -31,5 +33,23 @@ protected void RequireParam(Guid? value)
3133

3234
}
3335

36+
protected async Task<ApiSession> OpenSession(Parameters parameters)
37+
{
38+
// for simplification we just check that the user has pass any password
39+
// in more complex logic, you should call GetSpacesListAsync to retrieve a spaces list and check the isPublic property or the space
40+
// isPublic means that you need to open an anon session, otherwise - open a real session
41+
if (string.IsNullOrWhiteSpace(parameters.Password))
42+
{
43+
var apiSession = ApiSession.Anonymous(parameters.SpaceName);
44+
return apiSession;
45+
}
46+
else
47+
{
48+
var apiSession = await _apiClient.OpenSessionAsync(parameters.SpaceName, parameters.Password, _cancellationTokenSource.Token);
49+
return apiSession;
50+
}
51+
52+
}
53+
3454
}
3555
}

src/BusinessLogic/Commands/BrowseCommand.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Morph.Server.Sdk.Client;
2+
using Morph.Server.Sdk.Model;
3+
using MorphCmd.Interfaces;
4+
using MorphCmd.Models;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace MorphCmd.BusinessLogic.Commands
12+
{
13+
14+
internal class BrowseFilesCommand : BaseCommand, ICommand
15+
{
16+
public BrowseFilesCommand(IOutputEndpoint output, IInputEndpoint input, IMorphServerApiClient apiClient) : base(output, input, apiClient)
17+
{
18+
19+
}
20+
21+
public bool IsApiSessionRequired => true;
22+
23+
public async Task Execute(Parameters parameters)
24+
{
25+
if (string.IsNullOrWhiteSpace(parameters.Location))
26+
{
27+
_output.WriteInfo("Browsing the root folder of the space " + parameters.SpaceName);
28+
}
29+
else
30+
{
31+
_output.WriteInfo("Browsing the folder '" + parameters.Location + "' of the space " + parameters.SpaceName);
32+
}
33+
34+
using (var apiSession = await OpenSession(parameters))
35+
{
36+
37+
var data = await _apiClient.BrowseSpaceAsync(apiSession, parameters.Location, _cancellationTokenSource.Token);
38+
_output.WriteInfo("Space: " + data.SpaceName);
39+
_output.WriteInfo("Free space: " + data.FreeSpaceBytes + " bytes");
40+
foreach (var folder in data.Folders)
41+
{
42+
_output.WriteInfo(string.Format("{0}{1} {2}", folder.LastModified.ToLocalTime().ToString("MM/dd/yyyy hh:mm:ss tt").PadRight(30), "<DIR>".PadRight(16), folder.Name));
43+
}
44+
foreach (var file in data.Files)
45+
{
46+
_output.WriteInfo(string.Format("{0}{1} {2}", file.LastModified.ToLocalTime().ToString("MM/dd/yyyy hh:mm:ss tt").PadRight(30), file.FileSizeBytes.ToString("n0").PadLeft(16), file.Name));
47+
}
48+
49+
50+
_output.WriteInfo("Listing done");
51+
}
52+
53+
}
54+
}
55+
}

src/BusinessLogic/Commands/CommandsFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ public static ICommand Construct(Command command, IOutputEndpoint output, IInput
2424
case Command.Upload:
2525
return new UploadFileCommand(output, input, apiClient);
2626
case Command.Browse:
27-
return new BrowseCommand(output, input, apiClient);
27+
return new BrowseFilesCommand(output, input, apiClient);
2828
case Command.Del:
2929
return new DeleteFileCommand(output, input, apiClient);
3030
case Command.Download:
3131
return new DownloadFileCommand(output, input, apiClient);
3232
case Command.ValidateTasks:
3333
return new ValidateTasksCommand(output, input, apiClient);
34+
case Command.ListSpaces:
35+
return new ListSpacesCommand(output, input, apiClient);
36+
case Command.SpaceStatus:
37+
return new SpaceStatusCommand(output, input, apiClient);
3438
default:
3539
throw new Exception("Command not supported");
3640
}

src/BusinessLogic/Commands/DeleteFileCommand.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Morph.Server.Sdk.Client;
2+
using Morph.Server.Sdk.Model;
23
using MorphCmd.Exceptions;
34
using MorphCmd.Interfaces;
45
using MorphCmd.Models;
@@ -17,16 +18,21 @@ public DeleteFileCommand(IOutputEndpoint output, IInputEndpoint input, IMorphSer
1718

1819
}
1920

21+
public bool IsApiSessionRequired => true;
22+
2023
public async Task Execute(Parameters parameters)
2124
{
2225
if (string.IsNullOrWhiteSpace(parameters.Target))
2326
{
2427
throw new WrongCommandFormatException("Target is required");
2528
}
2629

27-
_output.WriteInfo(string.Format("Deleting file {0} in space {1}...", parameters.Target, parameters.Space ?? "Default"));
28-
await _apiClient.DeleteFileAsync(parameters.Space, parameters.Target, null, _cancellationTokenSource.Token);
29-
_output.WriteInfo("Operation completed");
30+
using (var apiSession = await OpenSession(parameters))
31+
{
32+
_output.WriteInfo(string.Format("Deleting file {0} in space {1}...", parameters.Target, apiSession.SpaceName));
33+
await _apiClient.DeleteFileAsync(apiSession, parameters.Target, null, _cancellationTokenSource.Token);
34+
_output.WriteInfo("Operation completed");
35+
}
3036

3137
}
3238
}

0 commit comments

Comments
 (0)