Skip to content

Commit 3ee9c55

Browse files
committed
added "all" capability to sample plan creation
1 parent e0de328 commit 3ee9c55

6 files changed

Lines changed: 161 additions & 29 deletions

File tree

Synapse.Common/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
// by using the '*' as shown below:
3939
// [assembly: AssemblyVersion("1.0.*")]
4040
[assembly: AssemblyVersion( "0.1.0.0" )]
41-
[assembly: AssemblyFileVersion( "0.1.17139.0" )]
41+
[assembly: AssemblyFileVersion( "0.1.17142.0" )]

Synapse.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
// by using the '*' as shown below:
3838
// [assembly: AssemblyVersion("1.0.*")]
3939
[assembly: AssemblyVersion( "0.1.0.0" )]
40-
[assembly: AssemblyFileVersion( "0.1.17139.0" )]
40+
[assembly: AssemblyFileVersion( "0.1.17142.0" )]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Name: RunAs
2+
Description: Test change of security context
3+
Actions:
4+
- Name: 0
5+
Handler:
6+
Type: Synapse.Handlers.EchoHandler, Synapse.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=a6de1cc56b73f982
7+
Config: {}
8+
StartInfo: {}
9+
Result:
10+
Status: Complete
11+
ExitData: &o0
12+
CurrentPrincipal: SS-Mekhano\synapse0
13+
RunAs: &o2
14+
Domain: ss-mekhano
15+
UserName: synapse0
16+
Password: OmwBUBtWKJWKFTeVCHCMEOHNRqtMgjAksRunYE7A/DICYvvLpV5CsVEHfWxxxXJQHIGDtavO0YBvSFb5LwWx43wEsaK+zzoAJkAcBybGtvDv+ADNeVuiahvDywltWuRdWhf+CBA9HaIiwL6sNhcwbvPX3z8Zpp7Cp9WFWv1/oR0=
17+
Crypto:
18+
KeyUri: C:\Devo\synapse\synapse.core.net\Synapse.UnitTests\Plans\crypto\pubPriv.xml
19+
KeyContainerName: foo
20+
Elements:
21+
- Password
22+
Errors: []
23+
BranchStatus: Complete
24+
Parameters: {}
25+
Actions:
26+
- Name: 0.1
27+
Handler:
28+
Type: Synapse.Handlers.EchoHandler, Synapse.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=a6de1cc56b73f982
29+
Config: {}
30+
StartInfo:
31+
ParentExitData: *o0
32+
Result:
33+
Status: Complete
34+
ExitData:
35+
CurrentPrincipal: SS-Mekhano\synapse1
36+
InstanceId: 2
37+
ParentExitData: *o0
38+
RunAs: &o1
39+
Domain: ss-mekhano
40+
UserName: synapse1
41+
Password: BnsK2g0N8jvnRb3zfc/NIaiMhNduw9/WtR2hKfCCUqnpWV2/sEn2+T0jpdVy8WATfzTWJhv8oeJ5Nn6gD2/LL20pjtOsk7NSqobio7XB1CkIgnGgbcQS8/Y9A1TPxQiBq2umo5LsCZYS+L3++o8wV1cXdBvT7elLNKyz8wHtlMc=
42+
Crypto:
43+
KeyUri: C:\Devo\synapse\synapse.core.net\Synapse.UnitTests\Plans\crypto\pubPriv.xml
44+
KeyContainerName: foo
45+
Elements:
46+
- Password
47+
Errors: []
48+
BranchStatus: Complete
49+
Parameters: {}
50+
Actions: []
51+
RunAs: *o1
52+
InstanceId: 2
53+
RunAs: *o2
54+
- Name: 1
55+
Handler:
56+
Type: Synapse.Handlers.EchoHandler, Synapse.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=a6de1cc56b73f982
57+
Config: {}
58+
StartInfo: {}
59+
Result:
60+
Status: Complete
61+
ExitData:
62+
CurrentPrincipal: SS-Mekhano\Steve Shortt
63+
InstanceId: 1
64+
BranchStatus: Complete
65+
Parameters: {}
66+
Actions: []
67+
InstanceId: 1
68+
StartInfo: {}
69+
Result:
70+
Status: Complete
71+
BranchStatus: Complete
72+
LastModified: 5/15/2017 9:46:11 AM

Synapse.UnitTests/Plans/RunAs.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Name: RunAs
2+
Description: Test change of security context
3+
DefaultHandlerType: Synapse.Core:Synapse.Handlers.EchoHandler
4+
Actions:
5+
- Name: 0
6+
Actions:
7+
RunAs:
8+
Domain: ss-mekhano
9+
UserName: synapse0
10+
Password: OmwBUBtWKJWKFTeVCHCMEOHNRqtMgjAksRunYE7A/DICYvvLpV5CsVEHfWxxxXJQHIGDtavO0YBvSFb5LwWx43wEsaK+zzoAJkAcBybGtvDv+ADNeVuiahvDywltWuRdWhf+CBA9HaIiwL6sNhcwbvPX3z8Zpp7Cp9WFWv1/oR0=
11+
Crypto:
12+
KeyUri: C:\Devo\synapse\synapse.core.net\Synapse.UnitTests\Plans\crypto\pubPriv.xml
13+
KeyContainerName: foo
14+
Elements:
15+
- Password
16+
- Name: 0.1
17+
Actions: []
18+
RunAs:
19+
Domain: ss-mekhano
20+
UserName: synapse1
21+
Password: BnsK2g0N8jvnRb3zfc/NIaiMhNduw9/WtR2hKfCCUqnpWV2/sEn2+T0jpdVy8WATfzTWJhv8oeJ5Nn6gD2/LL20pjtOsk7NSqobio7XB1CkIgnGgbcQS8/Y9A1TPxQiBq2umo5LsCZYS+L3++o8wV1cXdBvT7elLNKyz8wHtlMc=
22+
Crypto:
23+
KeyUri: C:\Devo\synapse\synapse.core.net\Synapse.UnitTests\Plans\crypto\pubPriv.xml
24+
KeyContainerName: foo
25+
Elements:
26+
- Password
27+
- Name: 1
28+
Actions: []
29+
Crypto:
30+
KeyUri: C:\Devo\synapse\synapse.core.net\Synapse.UnitTests\Plans\crypto\pubPriv.xml
31+
KeyContainerName: foo
32+
Elements: []
33+
Errors: []
34+
StartInfo: {}
35+
LastModified: 5/15/2017 7:07:42 AM

Synapse.cli/Program.cs

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,46 +141,70 @@ static void CreateSamplePlan(string handlerCsvList, string outPath, bool verbose
141141
if( verbose )
142142
p = Plan.CreateSample();
143143

144+
//todo: [ss] this is absolute $#!+ loop structure, need to fix
144145
string[] handlers = handlerCsvList.Split( ',' );
145146
foreach( string handlerType in handlers )
146147
{
147-
ActionItem a = new ActionItem()
148+
if( handlerType.ToLower().EndsWith( ":all" ) )
148149
{
149-
Name = handlerType,
150-
Description = $"Example Action for {handlerType}."
151-
};
152-
a.Handler = new HandlerInfo();
153-
a.Actions = null;
154-
155-
IHandlerRuntime hr = null;
156-
try
157-
{
158-
hr = AssemblyLoader.Load( handlerType, handlerType );
159-
}
160-
catch { }
161-
162-
if( hr != null )
163-
{
164-
a.Description = $"Resolved Handler from [{hr.RuntimeType}].";
165-
a.Handler.Type = handlerType;
166-
a.Handler.Config = new ParameterInfo();
167-
a.Handler.Config.Values = hr.GetConfigInstance();
168-
a.Parameters = new ParameterInfo();
169-
a.Parameters.Values = hr.GetParametersInstance();
150+
string[] parts = handlerType.Split( ':' );
151+
CreateSamplePlanAll( parts[0], outPath, verbose );
170152
}
171153
else
172154
{
173-
a.Handler.Type = $"** Error - Could not load [{handlerType}].";
174-
}
155+
ActionItem a = new ActionItem()
156+
{
157+
Name = handlerType,
158+
Description = $"Example Action for {handlerType}."
159+
};
160+
a.Handler = new HandlerInfo();
161+
a.Actions = null;
162+
163+
IHandlerRuntime hr = null;
164+
try
165+
{
166+
hr = AssemblyLoader.Load( handlerType, handlerType );
167+
}
168+
catch { }
169+
170+
if( hr != null )
171+
{
172+
a.Description = $"Resolved Handler from [{hr.RuntimeType}].";
173+
a.Handler.Type = handlerType;
174+
a.Handler.Config = new ParameterInfo();
175+
a.Handler.Config.Values = hr.GetConfigInstance();
176+
a.Parameters = new ParameterInfo();
177+
a.Parameters.Values = hr.GetParametersInstance();
178+
}
179+
else
180+
{
181+
a.Handler.Type = $"** Error - Could not load [{handlerType}].";
182+
}
175183

176-
p.Actions.Add( a );
184+
p.Actions.Add( a );
185+
}
177186
}
178187

179188
if( !string.IsNullOrWhiteSpace( outPath ) )
180189
File.WriteAllText( outPath, p.ToYaml() );
181190
else
182191
Console.WriteLine( p.ToYaml() );
183192
}
193+
194+
static void CreateSamplePlanAll(string handlerLib, string outPath, bool verbose = false)
195+
{
196+
//probe all the Types, looking for partial match in name
197+
try
198+
{
199+
System.Reflection.Assembly hrAsm = System.Reflection.Assembly.Load( handlerLib );
200+
201+
Type[] types = hrAsm.GetTypes();
202+
foreach( Type t in types )
203+
if( t.GetInterfaces().Contains( typeof( IHandlerRuntime ) ) )
204+
CreateSamplePlan( $"{handlerLib}:{t.Name}", outPath, verbose );
205+
}
206+
catch( Exception ex ) { throw; }
207+
}
184208
#endregion
185209

186210

@@ -240,10 +264,11 @@ static void WriteHelpAndExit(string errorMessage = null)
240264
Console.WriteLine( " decrypt{0,5} - filePath: Valid path to plan file to decrypt.", "" );
241265
Console.WriteLine( " out{0,9} - filePath: Optional output filePath.", "" );
242266
Console.WriteLine( " {0,10}If [out] not specified, will encrypt/decrypt in-place.\r\n", "" );
243-
Console_WriteLine( " synapse.cli.exe sample:{0}handlerLib:handlerName,...{1} [out:{0}filePath{1}]", ConsoleColor.Cyan, "{", "}" );
267+
Console_WriteLine( " synapse.cli.exe sample:{0}handlerLib:{0}all|handlerName{1},...{1} [out:{0}filePath{1}]", ConsoleColor.Cyan, "{", "}" );
244268
Console.WriteLine( " [verbose:true|false]", "{", "}" );
245269
Console_WriteLine( "\r\n - Create a sample Plan with the specified Handler(s).\r\n", ConsoleColor.Green, "" );
246270
Console.WriteLine( " sample{0,5} - A csv list of handlerLib:handlerName pairs.", "" );
271+
Console.WriteLine( " {0,10}Use handlerLib:all to discover all Handlers in a lib.", "" );
247272
Console.WriteLine( " out{0,9} - filePath: Optional output filePath.", "" );
248273
Console.WriteLine( " {0,10}If [out] not specified, will output to screen.", "" );
249274
Console.WriteLine( " verbose{0,5} - If true, adds example values for all Plan options.", "" );

Synapse.cli/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion( "0.1.0.0" )]
36-
[assembly: AssemblyFileVersion( "0.1.17139.0" )]
36+
[assembly: AssemblyFileVersion( "0.1.17142.0" )]

0 commit comments

Comments
 (0)