train-pwsh 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -12
- data/lib/train-pwsh/connection.rb +12 -2
- data/lib/train-pwsh/transport.rb +0 -3
- data/lib/train-pwsh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89e3a18c81cf9e11a8c44fab1922b73b7b131d79bc06e880f2465b0fa1855f86
|
4
|
+
data.tar.gz: 0eed86dd58bfeaa57ae2d838f24f8c1b29f518f012c55638f393e5b58fc0b3dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c03186763343739f788179381799a58b817012ae2d364de5c8a72f6d356950c25a8953449ef17343486c63cace359efba0548f5394d78c2e8f047154defb5edf
|
7
|
+
data.tar.gz: 9ac43a9c24bdf4d9612f323507ec58ff8579ec7c7b34a533ee04c3c9f6784f0f4d174ca5a58785cc584b578f94fcdfb4ca3c97bceee4941e3c5db0a1ed98338f
|
data/README.md
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
# Train::Pwsh
|
2
2
|
|
3
|
-
A train-pwsh connection has
|
4
|
-
- client_id
|
5
|
-
- tenant_id
|
6
|
-
- client_secret
|
7
|
-
- certificate_path
|
8
|
-
- certificate_password
|
9
|
-
- organization
|
10
|
-
- sharepoint_admin_url
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
A train-pwsh connection has eight fields that are needed for authentication, which are listed below:
|
4
|
+
- client_id (id of client)
|
5
|
+
- tenant_id (id of tenant)
|
6
|
+
- client_secret (secret key for client)
|
7
|
+
- certificate_path (path on machine where authentication certificate is stored)
|
8
|
+
- certificate_password (password for certificate)
|
9
|
+
- organization (organization domain)
|
10
|
+
- sharepoint_admin_url (sharepoint url for admin)
|
11
|
+
- pwsh_path (path on machine where the powershell executable is stored)
|
12
|
+
|
13
|
+
These fields need to be defined in the config file stored at this directory: `~/.inspec/config.json`. Particularly, under the `credentials` key of the json file, create a `pwsh` key with the value being another dictionary. This dictionary should have a key named `pwsh-options` with the value being another dictionary. This dictionary should contain the names of the eight fields above as well as their values. Please refer to this [link](https://origin.inspec.io/docs/reference/config/) for more detailed instructions.
|
14
|
+
|
15
|
+
On top of this, environment variables may need to be defined for some of these eight fields if they are to be used elsewhere in the profile as inputs. The README for the profile will specify which ones need to be stored as environment variables.
|
16
|
+
|
17
|
+
To set an environment variable on Mac, go to the `zschrc` file located at `~/.zschrc` and enter in the following syntax: `export VARIABLE_NAME='insert_value'`
|
18
|
+
|
19
|
+
To se and environment variable on Windows, click `Win + R`, type `cmd`, and hit enter. Then, this syntax can be used `setx VARIABLE_NAME "Variable Value"`
|
20
|
+
|
21
|
+
If train is being invoked using code, this is how it can be used:
|
15
22
|
|
16
23
|
**Pwsh**
|
17
24
|
|
@@ -50,8 +50,11 @@ module TrainPlugins
|
|
50
50
|
#Instance variables that store the necessary authentication credentials
|
51
51
|
#@pwsh_session_graph_exchange = ::Pwsh::Manager.instance('/opt/homebrew/bin/pwsh', ['-NoLogo'])
|
52
52
|
#@pwsh_session_teams_pnp = ::Pwsh::Manager.instance('/opt/homebrew/bin/pwsh', [])
|
53
|
-
@
|
54
|
-
|
53
|
+
@pwsh_path = @options.delete(:pwsh_path)
|
54
|
+
#@pwsh_session_graph_exchange = @options.delete(:graph_exchange_session)
|
55
|
+
#@pwsh_session_teams_pnp = @options.delete(:teams_pnp_session)
|
56
|
+
@pwsh_session_graph_exchange = ::Pwsh::Manager.instance("#{@pwsh_path}", ['-NoLogo'])
|
57
|
+
@pwsh_session_teams_pnp = ::Pwsh::Manager.instance("#{@pwsh_path}", [])
|
55
58
|
@client_id = @options.delete(:client_id)
|
56
59
|
@tenant_id = @options.delete(:tenant_id)
|
57
60
|
@client_secret = @options.delete(:client_secret)
|
@@ -106,6 +109,7 @@ module TrainPlugins
|
|
106
109
|
If($null -eq (get-module -name "ExchangeOnlineManagement")){import-module ExchangeOnlineManagement}
|
107
110
|
$password = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
|
108
111
|
$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential($client_id,$password)
|
112
|
+
Connect-IPPSSession -AppID $client_id -CertificateFilePath $certificate_path -CertificatePassword (ConvertTo-SecureString -String $certificate_password -AsPlainText -Force) -Organization $organization -ShowBanner:$false
|
109
113
|
Connect-ExchangeOnline -CertificateFilePath $certificate_path -CertificatePassword (ConvertTo-SecureString -String $certificate_password -AsPlainText -Force) -AppID $client_id -Organization $organization -ShowBanner:$false
|
110
114
|
}
|
111
115
|
|
@@ -144,11 +148,17 @@ module TrainPlugins
|
|
144
148
|
|
145
149
|
def run_script_in_graph_exchange(script)
|
146
150
|
result = @pwsh_session_graph_exchange.execute(script)
|
151
|
+
if result[:stdout].nil?
|
152
|
+
result[:stdout] = ""
|
153
|
+
end
|
147
154
|
return CommandResult.new(result[:stdout],result[:stderr],result[:exitcode])
|
148
155
|
end
|
149
156
|
|
150
157
|
def run_script_in_teams_pnp(script)
|
151
158
|
result = @pwsh_session_teams_pnp.execute(script)
|
159
|
+
if result[:stdout].nil?
|
160
|
+
result[:stdout] = ""
|
161
|
+
end
|
152
162
|
return CommandResult.new(result[:stdout],result[:stderr],result[:exitcode])
|
153
163
|
end
|
154
164
|
end
|
data/lib/train-pwsh/transport.rb
CHANGED
@@ -20,9 +20,6 @@ module TrainPlugins
|
|
20
20
|
#option :certificate_password, required: true, default: proc { ENV['CERTIFICATE_PASSWORD'] } unless ENV['CERTIFICATE_PASSWORD'].empty?
|
21
21
|
#option :organization, required: true, default: proc { ENV['ORGANIZATION'] } unless ENV['ORGANIZATION'].empty?
|
22
22
|
#option :sharepoint_admin_url, required: true, default: proc { ENV['SHAREPOINT_ADMIN_URL'] } unless ENV['SHAREPOINT_ADMIN_URL'].empty?
|
23
|
-
|
24
|
-
option :graph_exchange_session, required: true, default: proc { ::Pwsh::Manager.instance(ENV['PWSH_PATH'], ['-NoLogo']) }
|
25
|
-
option :teams_pnp_session, required: true, default: proc { ::Pwsh::Manager.instance(ENV['PWSH_PATH'], []) }
|
26
23
|
|
27
24
|
# The options passed to this are undocumented and rarely used.
|
28
25
|
def connection(_instance_opts = nil)
|
data/lib/train-pwsh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train-pwsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sujay Kandwal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|