Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of ability to use Windows Authentication for on premise TFS #3

Merged
merged 9 commits into from
Mar 5, 2017
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/sampleHelp.txt
/temp.txt
/pub.ps1
test/sample.txt
test/sample.txt
/src/.vs
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Team
Future home of PowerShell module for accessing TFS and VSTS
Home of PowerShell module for accessing TFS and VSTS

To get started you can visit this blog [PowerShell I would like you to meet TFS and VSTS](http://www.donovanbrown.com/post/PowerShell-I-would-like-you-to-meet-TFS-and-VSTS)

# Contributors
The cases of every file is very important. This module is to be used on Windows, Linux and OSx so case is important. If the casing does not match Linux and OSx might fail.

To get started you can visit this blog [PowerShell I would like you to meet TFS and VSTS](http://www.donovanbrown.com/post/PowerShell-I-would-like-you-to-meet-TFS-and-VSTS)
# Release Notes
## 0.1.15
Merge [Pull Request](https://github.com/DarqueWarrior/team/pull/3) from [Andy Neillans](https://github.com/aneillans) which included the following:
- Corrected typos in help files.
- Refactored location of common methods.
- Implemented using DefaultCredentials when using TFS. This removes the need to create a PAT.

## 0.1.14
Initial Open Source release
Binary file modified Team.psd1
Binary file not shown.
113 changes: 80 additions & 33 deletions en-US/Team-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3179,28 +3179,32 @@ entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
The ful Team Foundation Server (TFS) url including the collection.
The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<maml:name>PAT</maml:name>
<maml:description>
<maml:para>A secured string to capture your personal access token. This will allow you
to provide your personal access token without displaying it in plain text.

To use pat</maml:para>
To use pat simply omit it from the Add-TeamAccount command.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SecureString</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<!--Dynamic-->
<maml:name>Level</maml:name>
<maml:description>
<maml:para/>
<maml:para>On Windows allows you to store your account information at the Process, User or Machine levels. When saved at the User or Machine level your account information will be in any future PowerShell processes.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
<command:syntaxItem>
Expand All @@ -3220,19 +3224,49 @@ entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
The ful Team Foundation Server (TFS) url including the collection.
The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<!--Dynamic-->
<maml:name>Level</maml:name>
<maml:description>
<maml:para/>
<maml:para>On Windows allows you to store your account information at the Process, User or Machine levels. When saved at the User or Machine level your account information will be in any future PowerShell processes.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
<command:syntaxItem>
<maml:name>Add-TeamAccount</maml:name>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>Account</maml:name>
<maml:description>
<maml:para>
The Visual Studio Team Services (VSTS) account name to use. DO NOT enter the
entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection
</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<!--Dynamic-->
<maml:name>UseWindowsAuthentication</maml:name>
<maml:description>
<maml:para>Allows the use of the current user&apos;s Windows credentials to authenticate against a local TFS.</maml:para>
</maml:description>
<command:parameterValue required="false">SwitchParameter</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
Expand All @@ -3245,7 +3279,7 @@ entire URL. Just the portion before visualstudio.com. For example in the
following url mydemos is the account name.
https://mydemos.visualstudio.com
or
The ful Team Foundation Server (TFS) url including the collection.
The full Team Foundation Server (TFS) url including the collection.
http://localhost:8080/tfs/DefaultCollection</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
Expand All @@ -3255,33 +3289,35 @@ http://localhost:8080/tfs/DefaultCollection</maml:para>
</dev:type>
<dev:defaultValue/>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<maml:name>PAT</maml:name>
<maml:description>
<maml:para>A secured string to capture your personal access token. This will allow you
to provide your personal access token without displaying it in plain text.

To use pat</maml:para>
To use pat simply omit it from the Add-TeamAccount command.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SecureString</command:parameterValue>
<dev:type>
<maml:name>SecureString</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue/>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<!--Dynamic-->
<maml:name>Level</maml:name>
<maml:description>
<maml:para/>
<maml:para>On Windows allows you to store your account information at the Process, User or Machine levels. When saved at the User or Machine level your account information will be in any future PowerShell processes.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue/>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2">
<maml:name>PersonalAccessToken</maml:name>
Expand All @@ -3295,6 +3331,16 @@ To use pat</maml:para>
</dev:type>
<dev:defaultValue/>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
<!--Dynamic-->
<maml:name>UseWindowsAuthentication</maml:name>
<maml:description>
<maml:para>Allows the use of the current user&apos;s Windows credentials to authenticate against a local TFS.</maml:para>
</maml:description>
<command:parameterValue required="false">SwitchParameter</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:examples>
<!-- Examples-->
Expand All @@ -3318,6 +3364,16 @@ To use pat</maml:para>
<maml:para>Allows you to provide all the information on the command line.</maml:para>
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- EXAMPLE 3 --------------------------</maml:title>
<maml:introduction>
<maml:para>PS C:\&gt;</maml:para>
</maml:introduction>
<dev:code>Add-TeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication</dev:code>
<dev:remarks>
<maml:para>On Windows, allows you use to use Windows authentication against a local TFS server.</maml:para>
</dev:remarks>
</command:example>
</command:examples>
<maml:relatedLinks>
<!-- Links-->
Expand Down Expand Up @@ -4333,8 +4389,7 @@ the Pipeline by Property Name</maml:para>
<maml:para>Name of the project to remove.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>Force</maml:name>
Expand Down Expand Up @@ -4374,8 +4429,7 @@ the project.</maml:para>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
</command:parameters>
<command:inputTypes>
Expand Down Expand Up @@ -4985,8 +5039,7 @@ you do not have to pass the ProjectName with each call.</maml:para>
<maml:para>Get all the repositories in your Visual Studio Team Services or Team Founcation Server account, or a specific project.</maml:para>
</maml:description>
<maml:copyright>
<maml:para>
</maml:para>
<maml:para/>
</maml:copyright>
<command:verb>Get</command:verb>
<command:noun>GitRepository</command:noun>
Expand All @@ -5011,8 +5064,7 @@ You can use Set-DefaultProject to set a default project so
you do not have to pass the ProjectName with each call.</maml:para>
</maml:description>
<command:parameterValue required="false">String</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
<command:parameter required="false" pipelineinput="True (ByPropertyName)" globbing="false" position="named" aliases="RepositoryID">
<maml:name>Id</maml:name>
Expand All @@ -5022,8 +5074,7 @@ commas to separate the IDs. To find the ID of a repository, type
Get-Repository.</maml:para>
</maml:description>
<command:parameterValue required="false">Guid[]</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
</command:syntaxItem>
</command:syntax>
Expand All @@ -5045,8 +5096,7 @@ you do not have to pass the ProjectName with each call.</maml:para>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="RepositoryID">
<maml:name>Id</maml:name>
Expand All @@ -5060,8 +5110,7 @@ Get-Repository.</maml:para>
<maml:name>Int32[]</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
</command:parameters>
<command:examples>
Expand Down Expand Up @@ -5139,8 +5188,7 @@ you do not have to pass the ProjectName with each call.</maml:para>
<maml:para>Specifies the name of the repository.</maml:para>
</maml:description>
<command:parameterValue required="false">System.String</command:parameterValue>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
</command:syntaxItem>
</command:syntax>
Expand Down Expand Up @@ -5174,8 +5222,7 @@ you do not have to pass the ProjectName with each call.</maml:para>
<maml:name>Int32[]</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue>
</dev:defaultValue>
<dev:defaultValue/>
</command:parameter>
</command:parameters>
<command:examples>
Expand Down
16 changes: 12 additions & 4 deletions src/Approvals.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ function Get-Approval {

try {
# Call the REST API
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}

if (_useWindowsAuthenticationOnPremise) {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
} else {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
}

# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
_applyTypes -item $item
Expand Down Expand Up @@ -96,8 +100,12 @@ function Set-Approval {

try {
# Call the REST API
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body

if (_useWindowsAuthenticationOnPremise) {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Body $body -UseDefaultCredentials
} else {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Patch -Uri $listurl -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -Body $body
}

Write-Output "Approval $item status changed to $status"
}
catch {
Expand Down
28 changes: 22 additions & 6 deletions src/buildDefinitions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ function Get-BuildDefinition {
}

# Call the REST API
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}

if (_useWindowsAuthenticationOnPremise) {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
} else {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
}

_applyTypes -item $resp

Write-Output $resp
Expand All @@ -110,8 +114,12 @@ function Get-BuildDefinition {
}

# Call the REST API
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}

if (_useWindowsAuthenticationOnPremise) {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -UseDefaultCredentials
} else {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
}

# Apply a Type Name so we can use custom format view and custom type extensions
foreach($item in $resp.value) {
_applyTypes -item $item
Expand Down Expand Up @@ -141,7 +149,11 @@ function Add-BuildDefinition {
$url = _buildURL -projectName $projectName

# Call the REST API
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -InFile $inFile
if (_useWindowsAuthenticationOnPremise) {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -UseDefaultCredentials -InFile $inFile
} else {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Post -Uri $url -ContentType "application/json" -Headers @{Authorization = "Basic $env:TEAM_PAT"} -InFile $inFile
}

return $resp
}
Expand Down Expand Up @@ -170,7 +182,11 @@ function Remove-BuildDefinition {

if ($Force -or $pscmdlet.ShouldProcess($item, "Delete Build Definition")) {
# Call the REST API
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
if (_useWindowsAuthenticationOnPremise) {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -UseDefaultCredentials
} else {
$resp = Invoke-RestMethod -UserAgent (_getUserAgent) -Method Delete -Uri $listurl -Headers @{Authorization = "Basic $env:TEAM_PAT"}
}

Write-Output "Deleted build defintion $item"
}
Expand Down
Loading