Skip to content

Commit

Permalink
Merge pull request #197 from FBoucher/update-dependancies
Browse files Browse the repository at this point in the history
Update all dependencies
  • Loading branch information
FBoucher authored Oct 28, 2020
2 parents 82644e1 + 9d3a098 commit 2b687b2
Show file tree
Hide file tree
Showing 31 changed files with 576 additions and 10 deletions.
62 changes: 62 additions & 0 deletions src/adminTools/PowerAutomateFlow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# PowerAutomate Flow
Like in postman you can also just use PowerAutomate Flows to create, update or archive or get all configured Urls.

The flows call the Azure Functions.

> The PowerAutomate Flows require a premium license (e.g. a per user license) to use the premium connectors.

## Deployment
You should have already deployed your version of the **Azure Url Shortener**

### Flow 1 - Create new ShortURL
[AzUrlShortener] - Create new ShortURL: [Download and import Flow](deployment/[AzUrlShortener]-CreatenewShortURL_20200621211731.zip)

When you open the new imported Flow you need to set the correct HTTP Url to the Azure Function.
![Create new List](medias/UpdateFlow_HTTPCall_with_AzureFunctionUrl.jpg)


For that goto your Azure Function App Service and copy the Url for the **UrlShortener** Azure Function.
![Get Azure Function Url](medias/GetAzureFunctionURL1.jpg)
![Copy Azure Function Url](medias/GetAzureFunctionURL2.jpg)

When you run the Flow and you have set the correct URL to the Azure Function your new ShortUrl is created and returned in the HTTP call:
![Result new created ShortUrl](medias/Result_CreateShortUrl.jpg)


### Flow 2 - Get all URLs
[AzUrlShortener] - Get all Urls: [Download and import Flow](deployment/[AzUrlShortener]-GetallURLs_20200621214422.zip)


### Flow 3/4 - Update/Archive Url
Manual update or archive is not implemented as it requires to pass a few parameter which not be known (The update Flow can be done of course, it's implemented in the SharePoint list)
Parameters to pass (e.g. to change the long Url):
- new Url
- RowKey
- PartitionKey
- Vanity

Parameters to pass to archive a Url
- RowKey
- PartitionKey
- Vanity


---


## How to use it
Import the Flows and run them


---


## Question, problem?

If you have question or encounter any problem using this admin Frontend with AzShortenerUrl please feel free to ask help in the [issues section](https://github.com/FBoucher/AzUrlShortener/issues).


[adminBlazorWebsite_Url_list]: medias/adminBlazorWebsite_Url_list.png
[adminBlazorWebsite_Add_Url]: medias/adminBlazorWebsite_Add_Url.png
[portalConfig]: medias/portalConfig.png
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 184 additions & 0 deletions src/adminTools/PowerShell/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# PowerShell

## Deployment

PowerShell is available out of the box with every Windows 10 installation, so there is no deployment needed.
Just type "PowerShell" via Windows Start button to start either the "Windows PowerShell" command window or the "Windows PowerShell ISE"

## How to use it
Get the Azure Function URL and run the PowerShell command (as long as the Azure Function doesn't require a login...)

You will need to create a request for each functions. Here some requirements:

- Set the request e.g. to POST.
- Add a header: Content-Type = application/json
- Use the URL **WITH** the security `Code` to call the Azure Function. ([Read here](https://github.com/FBoucher/AzUrlShortener/blob/feature/docs/post-deployment-configuration.md#how-to-get-the-azure-function-urls) to learn how to get the URLs )


See full examples in provided PowerShell file:
PowerShell with all commands: [PowerShell_Create_List_Update_Archive_ShortURLs.ps1](src/PowerShell_Create_List_Update_Archive_ShortURLs.ps1)


### 1a- Create a short Url

In PowerShell, use the URL from the **UrlShortener** Azure Function. In the body of the request, add a JSON document containing two properties.

See the examples bellow to create short generic URL.

```powershell
#CREATE new ShortURL
$Body = @{
title = "Microsoft"
url = "https://www.microsoft.com"
vanity = ""
}
```

If you prefer you can pass a `vanity` to have control on the end part of the Url. In this sample the vanity is `msft`.

```powershell
$Body = @{
title = "Microsoft"
url = "https://www.microsoft.com"
vanity = "msft"
}
```

To execute the call run this.
```powershell
$Parameters = @{
Method = "POST"
Uri = "https://shortenertools....azurewebsites.net/api/UrlShortener?code=..."
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}
$newUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$newUrl
```

### 1b- Bulk Import short Urls from CSV file
Create a csv file, e.g. name it BulkImportUrls.csv or save an excel file as csv.
```csv
title,url,vanity
"Microsoft1","https://www.microsoft.com","msft1"
"Microsoft2","https://www.microsoft.com"
```

Download BulkImportUrls.csv to start with: [BulkImportUrls.csv](src/BulkImportUrls.csv)

Now run the
[PowerShell_BulkImportUrls.ps1](src/PowerShell_BulkImportUrls.ps1) (maybe not the best PowerShell code but it does its job... You are welcome to enhance it to a more advanced PowerShell script, e.g. using function, etc)


### 2- List all Urls

Use the URL from the **UrlList** Azure Function. Set the request to GET. No body content is required for this request. However, make sure the url contains the security token `code`.

https://shortenertools.azurewebsites.net/api/UrlList?code=JVzE6CvlEHxDHbq.....


To execute the call:
```powershell
#GET all URls
$Parameters = @{
Method = "GET"
Uri = "https://shortenertoolsn....azurewebsites.net/api/UrlList?code=..."
ContentType = "application/json"
}
$allUrls = Invoke-RestMethod @Parameters | ConvertTo-Json
$allUrls
```

The response will be a json document with an array:
```json
{
"UrlList": [
{
"Url": "http://www.frankysnotes.com/2020/03/reading-notes-416.html",
"PartitionKey": "2",
"RowKey": "2r",
"Timestamp": "2020-03-20T13:43:47.5758051+00:00",
"ETag": "W/\"datetime'2020-03-20T13%3A43%3A47.5758051Z'\""
},
{
"Url": "http://www.frankysnotes.com/2020/03/reading-notes-416.html",
"PartitionKey": "t",
"RowKey": "test10h24",
"Timestamp": "2020-03-27T14:26:44.4342376+00:00",
"ETag": "W/\"datetime'2020-03-27T14%3A26%3A44.4342376Z'\""
},
{
"Url": "https://www.frankysnotes.com/2020/03/reading-notes-416.html",
"PartitionKey": "z",
"RowKey": "z10test",
"Timestamp": "2020-03-20T15:27:08.8691188+00:00",
"ETag": "W/\"datetime'2020-03-20T15%3A27%3A08.8691188Z'\""
}
]
}
```

### 3- Update entry

Use the URL from the **Update** Azure Function.

https://shortenertools.azurewebsites.net/api/UrlList?code=JVzE6CvlEHxDHbq.....


To update an entry:
```powershell
#UPDATE ShortURL
$Body = @{
title = "Microsoft Homepage"
url = "https://www.microsoft.com"
RowKey = "msft"
PartitionKey = "m"
vanity = "msft"
}
$Parameters = @{
Method = "POST"
Uri = "https://shortenertools....azurewebsites.net/api/UrlUpdate?code=..."
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}
$updUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$updUrl
```

### 4- Archive entry

Use the URL from the **Archive** Azure Function.

https://shortenertools.azurewebsites.net/api/UrlList?code=JVzE6CvlEHxDHbq.....


To archive an entry:
```powershell
#ARCHIVE ShortURL
$Body = @{
RowKey = "msft"
PartitionKey = "m"
vanity = "msft"
}
#Currently Method is DELETE to Archive a ShortURL, with newest code version change it to POST
$Parameters = @{
Method = "DELETE"
Uri = "https://shortenertools....azurewebsites.net/api/UrlArchive?code="
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}
$archUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$archUrl
```



## Question, problem?

If you have question or encounter any problem using this admin interface with AzShortenerUrl please feel free to ask help in the [issues section](https://github.com/FBoucher/AzUrlShortener/issues).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/adminTools/PowerShell/src/BulkImportUrls.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title,url,vanity
"Microsoft1","https://www.microsoft.com","msft1"
"Microsoft2","https://www.microsoft.com"
35 changes: 35 additions & 0 deletions src/adminTools/PowerShell/src/PowerShell_BulkImportUrls.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#Example csv => BulkImportUrls.csv
#as vanity is not mandatory just don't add a value for the vanity column like in the following Microsoft2 example
#title,url,vanity
#"Microsoft1","https://www.microsoft.com","msft1"
#"Microsoft2","https://www.microsoft.com"

$UrlValuesFromCSV = Import-CSV .\BulkImportUrls.csv
<<<<<<< HEAD
$AzureFunctionUrlShortenerUrl = "https://shortenertools....azurewebsites.net/api/UrlShortener?code=..."
=======
#$AzureFunctionUrlShortenerUrl = "https://shortenertools....azurewebsites.net/api/UrlShortener?code=..."
>>>>>>> PowerShell_BulkImport_CSV

ForEach ($csventry in $UrlValuesFromCSV)
{
if (!$($csventry.vanity)) { $vanity = '' } else {$vanity = $($csventry.vanity)}
$Body = @{
title = $($csventry.title)
url = $($csventry.url)
vanity = $vanity
}

$Body

$Parameters = @{
Method = "POST"
Uri = $AzureFunctionUrlShortenerUrl
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}

$newUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$newUrl
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#Calling a REST API from PowerShell
#Idea from: https://4bes.nl/2020/08/23/calling-a-rest-api-from-powershell/amp/

#GET all URls
$Parameters = @{
Method = "GET"
Uri = "https://shortenertoolsn....azurewebsites.net/api/UrlList?code=..."
ContentType = "application/json"
}

$allUrls = Invoke-RestMethod @Parameters | ConvertTo-Json
$allUrls


###############################################################


#CREATE new ShortURL
$Body = @{
title = "Microsoft"
url = "https://www.microsoft.com"
vanity = "msft"
}

$Parameters = @{
Method = "POST"
Uri = "https://shortenertools....azurewebsites.net/api/UrlShortener?code=..."
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}

$newUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$newUrl


###############################################################


#UPDATE ShortURL
$Body = @{
title = "Microsoft Homepage"
url = "https://www.microsoft.com"
RowKey = "msft"
PartitionKey = "m"
vanity = "msft"
}

$Parameters = @{
Method = "POST"
Uri = "https://shortenertools....azurewebsites.net/api/UrlUpdate?code=..."
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}

$updUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$updUrl


###############################################################


#ARCHIVE ShortURL
$Body = @{
RowKey = "msft"
PartitionKey = "m"
vanity = "msft"
}

#Currently Method is DELETE to Archive a ShortURL, with newest code version change it to POST
$Parameters = @{
Method = "DELETE"
Uri = "https://shortenertools....azurewebsites.net/api/UrlArchive?code="
Body = ($Body | ConvertTo-Json)
ContentType = "application/json"
}

$archUrl = Invoke-RestMethod @Parameters | ConvertTo-Json
$archUrl
Loading

0 comments on commit 2b687b2

Please sign in to comment.