From f73ef56a809e6506d2a8e3f32ccbda2436e2c465 Mon Sep 17 00:00:00 2001 From: maertend Date: Mon, 25 Jul 2016 13:59:58 -0700 Subject: [PATCH 1/6] Create readme.md --- demos/rest/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 demos/rest/readme.md diff --git a/demos/rest/readme.md b/demos/rest/readme.md new file mode 100644 index 000000000..304360cab --- /dev/null +++ b/demos/rest/readme.md @@ -0,0 +1 @@ +Readme From 11c07b806aaf3525188ca87ff8d7ef1d1ebe5fc6 Mon Sep 17 00:00:00 2001 From: maertend Date: Mon, 25 Jul 2016 15:29:42 -0700 Subject: [PATCH 2/6] Add files via upload --- demos/rest/curlDemo.txt | 20 ++++++++++++++++++ demos/rest/rest.ps1 | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 demos/rest/curlDemo.txt create mode 100644 demos/rest/rest.ps1 diff --git a/demos/rest/curlDemo.txt b/demos/rest/curlDemo.txt new file mode 100644 index 000000000..cca7dd61a --- /dev/null +++ b/demos/rest/curlDemo.txt @@ -0,0 +1,20 @@ +# EQ Linux + +# get the json from the repo api and assign it to the txt file + +# This grads the json file from the API +curl -u https://api.github.com/repos/maertend/opstest > outputtest.txt + +# Reformats the json block to proper json (removes the newlines) +string=$(cat temp.txt) + +# Replace the "private" value to false +find='"private": true' +replace='"private": false' +string2=${string/$find/$replace} + +# push the json block into a txt file +echo $string2 > output.txt + +# Post the updated JSON data to the repo +curl -u https://api.github.com/repos/maertend/opstest --data @output.txt \ No newline at end of file diff --git a/demos/rest/rest.ps1 b/demos/rest/rest.ps1 new file mode 100644 index 000000000..b478ed2da --- /dev/null +++ b/demos/rest/rest.ps1 @@ -0,0 +1,46 @@ +# NOTE: This demo is still in progress and needs validation in Linux +# ------------------------------------ + +#region Setup the credentials for use in HTTP header +$user = '' +$pass= "" +$pair = "${user}:${pass}" +$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) +$base64 = [System.Convert]::ToBase64String($bytes) +$basicAuthValue = "Basic $base64" +$headers = @{ Authorization = $basicAuthValue } +#endregion + +# Changing the status of a Private GitHub repository to Public + +# URL to PowerShell Github Repo +$PowerShellGithubUri = 'https://api.github.com/repos/maertend/opstest' + +# Get the blob from the Github API as a PS object +$JsonBlock = Invoke-RestMethod -Uri $PowerShellGithubUri -Headers $headers + +# Explore the object (Notice that it is a private repo) +$JsonBlock + +# Given it is an object, you can explore and interact with it +# Change the private value to false +$JsonBlock.private = 'false' + +# Convert the object back to a json +$Json = ConvertTo-Json $JsonBlock + +# Post the updated json block back to the GitHub +Invoke-RestMethod -Uri $PowerShellGithubUri -Headers $headers -Method Post -Body $Json + + +# -------------- + +# We can also use the PS objects to sort the different repos on github + +# If we grab the json from the PowerShell github +Invoke-RestMethod https://api.github.com/users/powershell/repos | sv repoData + +# We can sort it based on the number of forks each repo has +$repoData | Sort-Object -Property forks_count -Descending | ft -f id,name,stargazers_count,forks_count + +$repoData | Sort-Object -Property stargazers_count -Descending | ft -f id,name,stargazers_count,forks_count From 6cffe84ec01abf68de277de79363ff140a7ba957 Mon Sep 17 00:00:00 2001 From: maertend Date: Mon, 25 Jul 2016 15:42:07 -0700 Subject: [PATCH 3/6] Update readme.md --- demos/rest/readme.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/demos/rest/readme.md b/demos/rest/readme.md index 304360cab..d4980244a 100644 --- a/demos/rest/readme.md +++ b/demos/rest/readme.md @@ -1 +1,13 @@ -Readme +This demo shows interacting with the Github API via Invoke-RestMethod. +NOTE: A repo URL must be specified in these scripts and a Github PAT token with access to the repo must be generated and specified + +rest.ps1 +Invoke-RestMethod is used to get the json of a repo as a PowerShell object, +the object is then manipulated and the "private" parameter is changed to 'false'. +The object is converted back to json formating and Posted back to the repo API + +The benefit of PS is shown at the end of the script with PS objects. +Enabling users to get info on multiple repos and then sort that data as objects. + +curlDemo.txt +This shos the equavilent bash commmands to change the private status of a Github repo From 9f4dbdddc4b03cfa98b70103589338ae54021a2d Mon Sep 17 00:00:00 2001 From: maertend Date: Mon, 25 Jul 2016 15:42:30 -0700 Subject: [PATCH 4/6] Add files via upload --- demos/rest/curlDemo.txt | 4 ++-- demos/rest/rest.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demos/rest/curlDemo.txt b/demos/rest/curlDemo.txt index cca7dd61a..eff97d7e9 100644 --- a/demos/rest/curlDemo.txt +++ b/demos/rest/curlDemo.txt @@ -3,7 +3,7 @@ # get the json from the repo api and assign it to the txt file # This grads the json file from the API -curl -u https://api.github.com/repos/maertend/opstest > outputtest.txt +curl -u > outputtest.txt # Reformats the json block to proper json (removes the newlines) string=$(cat temp.txt) @@ -17,4 +17,4 @@ string2=${string/$find/$replace} echo $string2 > output.txt # Post the updated JSON data to the repo -curl -u https://api.github.com/repos/maertend/opstest --data @output.txt \ No newline at end of file +curl -u --data @output.txt \ No newline at end of file diff --git a/demos/rest/rest.ps1 b/demos/rest/rest.ps1 index b478ed2da..196ccca75 100644 --- a/demos/rest/rest.ps1 +++ b/demos/rest/rest.ps1 @@ -14,7 +14,7 @@ $headers = @{ Authorization = $basicAuthValue } # Changing the status of a Private GitHub repository to Public # URL to PowerShell Github Repo -$PowerShellGithubUri = 'https://api.github.com/repos/maertend/opstest' +$PowerShellGithubUri = '' # Get the blob from the Github API as a PS object $JsonBlock = Invoke-RestMethod -Uri $PowerShellGithubUri -Headers $headers From c4efc58f7b1e94e3ed2611d97c68af9215059095 Mon Sep 17 00:00:00 2001 From: maertend Date: Mon, 25 Jul 2016 15:47:10 -0700 Subject: [PATCH 5/6] Update readme.md --- demos/rest/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/rest/readme.md b/demos/rest/readme.md index d4980244a..cd7460325 100644 --- a/demos/rest/readme.md +++ b/demos/rest/readme.md @@ -1,7 +1,7 @@ This demo shows interacting with the Github API via Invoke-RestMethod. NOTE: A repo URL must be specified in these scripts and a Github PAT token with access to the repo must be generated and specified -rest.ps1 +rest.ps1: Invoke-RestMethod is used to get the json of a repo as a PowerShell object, the object is then manipulated and the "private" parameter is changed to 'false'. The object is converted back to json formating and Posted back to the repo API @@ -9,5 +9,5 @@ The object is converted back to json formating and Posted back to the repo API The benefit of PS is shown at the end of the script with PS objects. Enabling users to get info on multiple repos and then sort that data as objects. -curlDemo.txt +curlDemo.txt: This shos the equavilent bash commmands to change the private status of a Github repo From 38d75e30c31a42be5102e8c72d6caf0945100a2c Mon Sep 17 00:00:00 2001 From: maertend Date: Mon, 25 Jul 2016 15:48:16 -0700 Subject: [PATCH 6/6] Update readme.md --- demos/rest/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/rest/readme.md b/demos/rest/readme.md index cd7460325..5c9f7e0fb 100644 --- a/demos/rest/readme.md +++ b/demos/rest/readme.md @@ -1,7 +1,7 @@ This demo shows interacting with the Github API via Invoke-RestMethod. NOTE: A repo URL must be specified in these scripts and a Github PAT token with access to the repo must be generated and specified -rest.ps1: +rest.ps1: Invoke-RestMethod is used to get the json of a repo as a PowerShell object, the object is then manipulated and the "private" parameter is changed to 'false'. The object is converted back to json formating and Posted back to the repo API