train-pwsh 0.1.1 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dee3811f1e76e743dad03b5fbda0ef38f5ce9f0d0503a2634d109674a4f80c1e
4
- data.tar.gz: f3e63fb43c571e462a9a253968daece5d18d8083c21280c3749104a521407d8b
3
+ metadata.gz: 3ec867288676127f29ea07114e8acbb29e126b7dbc15aba96ca8669fd8818ee8
4
+ data.tar.gz: f0f08b98e659a6ebae79e6045c928e2bddae9331c5c740ad8b1f4e526841ff1d
5
5
  SHA512:
6
- metadata.gz: b4a6938760a23e90e50904f7953d39d2706ba7b4b5f6db48f91a1308dea5ce8391c50def5aeed255e9d3eac9eacc28c4b975fc019e187389ac616a302a805486
7
- data.tar.gz: 33914e811691e4b1f284b2e33d49515808e0a19925795935485484278f9df90e0607bee8898efcdc1a81d185183325f3b495b395892a72c84da8f121cd28769c
6
+ metadata.gz: ac445931a17e3a433a4d1b5ccc8901064db19a1763952ca0a339d070c912c70e0c6421f236f97ccc45eee3a4748f92d4725faba4923f24cfe6c1d2d67d3435fe
7
+ data.tar.gz: '02475499a432dbd135519783e3afe67bcb166459f3dcf51865cec217f3622c1d3ecb75dc7e87d91b9b44c60c69d5c43d5a41e30162f8a514591c9db97f283474'
data/README.md CHANGED
@@ -1,17 +1,18 @@
1
1
  # Train::Pwsh
2
2
 
3
- A train-pwsh connection has 7 fields that are needed for authentication, which are listed below:
4
- - client_id
5
- - tenant_id
6
- - client_secret
7
- - certificate_path
8
- - certificate_password
9
- - organization
10
- - sharepoint_admin_url
11
-
12
- 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 seven fields above as well as their values. Please refer to this [link](https://origin.inspec.io/docs/reference/config/) for more detailed instructions.
13
-
14
- On top of this, environment variables may need to be defined for some of these seven 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.
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.
15
16
 
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'`
17
18
 
@@ -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
- @pwsh_session_graph_exchange = @options.delete(:graph_exchange_session)
54
- @pwsh_session_teams_pnp = @options.delete(:teams_pnp_session)
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)
@@ -148,6 +151,11 @@ module TrainPlugins
148
151
  if result[:stdout].nil?
149
152
  result[:stdout] = ""
150
153
  end
154
+ if !result[:stdout].empty? && result[:stdout].match?(/is not recognized|session is not established/i)
155
+ result[:stderr] = result[:stdout]
156
+ result[:stdout] = ""
157
+ result[:exitcode] = -1
158
+ end
151
159
  return CommandResult.new(result[:stdout],result[:stderr],result[:exitcode])
152
160
  end
153
161
 
@@ -156,6 +164,11 @@ module TrainPlugins
156
164
  if result[:stdout].nil?
157
165
  result[:stdout] = ""
158
166
  end
167
+ if !result[:stdout].empty? && result[:stdout].match?(/is not recognized|session is not established/i)
168
+ result[:stderr] = result[:stdout]
169
+ result[:stdout] = ""
170
+ result[:exitcode] = -1
171
+ end
159
172
  return CommandResult.new(result[:stdout],result[:stderr],result[:exitcode])
160
173
  end
161
174
  end
@@ -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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Train
4
4
  module Pwsh
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
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.1
4
+ version: 0.1.3
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-21 00:00:00.000000000 Z
11
+ date: 2024-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train