train-pwsh 0.1.4 → 0.1.6

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: 39702d4eac70b2194a4c37b925bd3029169c874b0d649360c1b64509fa81c86e
4
- data.tar.gz: 58248aeb93158177f68664d638660128fafd13f75d43d5439a5add22d4c3da5b
3
+ metadata.gz: 9c0b97bc0ab701a473da4c28af195434cfc6fc374103614bb00ea02766c7d28f
4
+ data.tar.gz: 86f25bad8916379f13ae5769dc0a0ee89d30b1798c679496903a3b8a874f015f
5
5
  SHA512:
6
- metadata.gz: '0484eace9bfecbb42c78967bdd0aca9c3c75f32202fca17ac55342202652ee5fed32e45d6f2df19eb15360e978648acaa491c85574dedd9411bf576a6f7d4855'
7
- data.tar.gz: bfcae4cdf0664ab10d3dbe819d4de61c9b067c25a7ff583afaa6184b313865f01492b6d272b791439adffb43e3ac18bcdfb869bbdaccd6dc40ebe61176bd97f5
6
+ metadata.gz: 1da78073262a500f458e9208d39850a778aa2b1993f8db53e2e8286bdb5850834e249124cee78b98a4be09b47cca338ad645f3b46fea2b45f8794b95e87672f1
7
+ data.tar.gz: e16e5aebad94903f7d7c7663eb5f41d9939029149f875fd1aa8af1fc1e2936cdd762440c47a8fe0632e362c2e69cf86f0f5f5e267d0504a2aa79ab336c12cfd0
@@ -55,6 +55,7 @@ module TrainPlugins
55
55
  #@pwsh_session_teams_pnp = @options.delete(:teams_pnp_session)
56
56
  @pwsh_session_graph_exchange = ::Pwsh::Manager.instance("#{@pwsh_path}", ['-NoLogo'])
57
57
  @pwsh_session_teams_pnp = ::Pwsh::Manager.instance("#{@pwsh_path}", [])
58
+ @pwsh_session_azure = ::Pwsh::Manager.instance("#{@pwsh_path}", ['-NoProfile'])
58
59
  @client_id = @options.delete(:client_id)
59
60
  @tenant_id = @options.delete(:tenant_id)
60
61
  @client_secret = @options.delete(:client_secret)
@@ -65,10 +66,13 @@ module TrainPlugins
65
66
 
66
67
  exit_status_graph_exchange = install_connect_graph_exchange()
67
68
  exit_status_teams_pnp = install_connect_teams_pnp()
69
+ exit_status_azure = install_azure()
68
70
  if exit_status_graph_exchange != 0
69
71
  return exit_status_graph_exchange
70
72
  elsif exit_status_teams_pnp != 0
71
73
  return exit_status_teams_pnp
74
+ elsif exit_status_azure != 0
75
+ return exit_status_azure
72
76
  end
73
77
 
74
78
  end
@@ -82,6 +86,8 @@ module TrainPlugins
82
86
  return run_script_in_graph_exchange(script)
83
87
  elsif session_type_hash.key?(:teams_pnp_session)
84
88
  return run_script_in_teams_pnp(script)
89
+ elsif session_type_hash.key?(:azure_session)
90
+ return run_script_in_azure(script)
85
91
  else
86
92
  return CommandResult.new("","",0)
87
93
  end
@@ -98,14 +104,14 @@ module TrainPlugins
98
104
  $organization = '#{@organization}'
99
105
 
100
106
  #Connect to Graph module
101
- If($null -eq (get-module -listavailable -name "microsoft.graph")){install-module microsoft.graph}
107
+ If($null -eq (get-module -listavailable -name "microsoft.graph")){install-module microsoft.graph -Force -AllowClobber}
102
108
  If($null -eq (get-module -name "microsoft.graph")){import-module microsoft.graph}
103
109
  $password = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
104
110
  $ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential($client_id,$password)
105
111
  Connect-MgGraph -TenantId $tenantid -ClientSecretCredential $ClientSecretCredential -NoWelcome
106
112
 
107
113
  #Connect to Exchange module
108
- If($null -eq (get-module -listavailable -name "ExchangeOnlineManagement")){install-module ExchangeOnlineManagement}
114
+ If($null -eq (get-module -listavailable -name "ExchangeOnlineManagement")){install-module ExchangeOnlineManagement -Force -AllowClobber}
109
115
  If($null -eq (get-module -name "ExchangeOnlineManagement")){import-module ExchangeOnlineManagement}
110
116
  $password = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
111
117
  $ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential($client_id,$password)
@@ -131,13 +137,13 @@ module TrainPlugins
131
137
  $sharepoint_admin_url = '#{@sharepoint_admin_url}'
132
138
 
133
139
  #Connect to Teams module
134
- If($null -eq (get-module -listavailable -name "MicrosoftTeams")){install-module MicrosoftTeams}
140
+ If($null -eq (get-module -listavailable -name "MicrosoftTeams")){install-module MicrosoftTeams -Force -AllowClobber}
135
141
  If($null -eq (get-module -name "MicrosoftTeams")){import-module MicrosoftTeams}
136
142
  $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certificate_path,$certificate_password)
137
143
  Connect-MicrosoftTeams -Certificate $cert -ApplicationId $client_id -TenantId $tenantid > $null
138
144
 
139
145
  #Connect to PnP module
140
- If($null -eq (get-module -listavailable -name "PnP.PowerShell")){install-module PnP.PowerShell}
146
+ If($null -eq (get-module -listavailable -name "PnP.PowerShell")){install-module PnP.PowerShell -Force -AllowClobber}
141
147
  If($null -eq (get-module -name "PnP.PowerShell")){import-module PnP.PowerShell}
142
148
  $password = (ConvertTo-SecureString -AsPlainText $certificate_password -Force)
143
149
  Connect-PnPOnline -Url $sharepoint_admin_url -ClientId $client_id -CertificatePath $certificate_path -CertificatePassword $password -Tenant $tenantid
@@ -146,6 +152,24 @@ module TrainPlugins
146
152
  return pwsh_teams_pnp_install_connect_result[:exitcode]
147
153
  end
148
154
 
155
+ def install_azure()
156
+ pwsh_azure_install_connect = %{
157
+ #Collect designated inputs required for Graph, Exchange, and PnP connections
158
+ $client_id = '#{@client_id}'
159
+ $tenantid = '#{@tenant_id}'
160
+ $certificate_password = '#{@certificate_password}'
161
+ $certificate_path = '#{@certificate_path}'
162
+ $sharepoint_admin_url = '#{@sharepoint_admin_url}'
163
+
164
+ #Connect to Teams module
165
+ If ($null -eq (Get-Module -ListAvailable -Name "Az")) {Install-Module Az -Force -AllowClobber}
166
+ If ($null -eq (Get-Module -Name "Az")) {Import-Module Az}
167
+ Connect-AzAccount
168
+ }
169
+ pwsh_azure_install_connect_result = @pwsh_session_azure.execute(pwsh_azure_install_connect)
170
+ return pwsh_azure_install_connect_result[:exitcode]
171
+ end
172
+
149
173
  def run_script_in_graph_exchange(script)
150
174
  result = @pwsh_session_graph_exchange.execute(script)
151
175
  if result[:stdout].nil?
@@ -171,6 +195,19 @@ module TrainPlugins
171
195
  end
172
196
  return CommandResult.new(result[:stdout],result[:stderr],result[:exitcode])
173
197
  end
198
+
199
+ def run_script_in_azure(script)
200
+ result = @pwsh_session_azure.execute(script)
201
+ if result[:stdout].nil?
202
+ result[:stdout] = ""
203
+ end
204
+ if !result[:stdout].empty? && result[:stdout].match?(/is not recognized|session is not established/i)
205
+ result[:stderr] = result[:stdout]
206
+ result[:stdout] = ""
207
+ result[:exitcode] = -1
208
+ end
209
+ return CommandResult.new(result[:stdout],result[:stderr],result[:exitcode])
210
+ end
174
211
  end
175
212
  end
176
213
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Train
4
4
  module Pwsh
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.6"
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.4
4
+ version: 0.1.6
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-26 00:00:00.000000000 Z
11
+ date: 2025-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train