Skip to content

Commit

Permalink
Merge pull request #205 from FBoucher/vnext
Browse files Browse the repository at this point in the history
Major upgrade to version 2.0
  • Loading branch information
FBoucher authored Nov 5, 2020
2 parents 2b687b2 + aeb1b33 commit 6c3269a
Show file tree
Hide file tree
Showing 50 changed files with 2,277 additions and 164 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ TestResult.xml
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
project.fragment.lock.json
artifacts/

*_i.c
*_p.c
Expand Down
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,46 @@ A simple and easy to use and to deploy budget-friendly Url Shortener for everyon
Features:

- 1-Click deployment.
- 1-Click deployment (currently only in [V1](https://github.com/FBoucher/AzUrlShortener/tree/main-v1)).
- Create Edit and Delete short URL.
- Keep Statistics of your clicks.
- Budget-friendly and 100% open-source.

**[Version 1](https://github.com/FBoucher/AzUrlShortener/tree/main-v1)**
- A local database (file) is used for authentification.

## How To Deploy
**[Version 2](https://github.com/FBoucher/AzUrlShortener/tree/vNext)**
- Azure Active Directory AAD (Microsoft Identity) is used for authentification.

## How To Deploy Version 1

To deploy YOUR version of **Azure Url Shortener** you could fork this repo, but if you are looking for the easy way just click on the "Deploy to Azure".

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/?WT.mc_id=urlshortener-github-frbouche#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FFBoucher%2FAzUrlShortener%2Fmain%2Fdeployment%2FazureDeploy.json)
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/?WT.mc_id=urlshortener-github-frbouche#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FFBoucher%2FAzUrlShortener%2Fmain-v1%2Fdeployment%2FazureDeploy.json)

To have all details and alternative deployment refer to the [Deployment Details](azFunctions-deployment.md) page.
To have all details and alternative deployment refer to the [Deployment Details](https://github.com/FBoucher/AzUrlShortener/blob/main-v1/azFunctions-deployment.md) page.

#### Post Deployment Configuration

A good Url Shortener wouldn't be completed without a custom domain name. To know how to add it and other useful post-deployment configurations refer to the [post-deployment-configuration](post-deployment-configuration.md) page.
A good Url Shortener wouldn't be completed without a custom domain name. To know how to add it and other useful post-deployment configurations refer to the [post-deployment-configuration](https://github.com/FBoucher/AzUrlShortener/blob/main-v1/post-deployment-configuration.md) page.


## How To Deploy Version 2

Right now the deployment of the Version 2 is possible Headless (just the Azure Function) or paired with [TinyBlazorAdmin](https://github.com/FBoucher/TinyBlazorAdmin). It's a static website written in C# webassembly and it's even more budget friendly then v1. However, we are still working at the automation of the deployment.

Until we have a 1-Click deployment you should follow the documented To have all details and alternative deployment refer to the [Deployment Details](https://github.com/FBoucher/TinyBlazorAdmin/blob/main/deployment.md) page.


### How to Update / Upgrade
## How to Update / Upgrade

You deployed the Azure Url Shortener and it's now running in your Azure Subscription, but you would like to have the new feature(s). Updating your current version is in fact really simple.

#### Update the Azure Functions
>Note: Currently there is breaking changes between **v1** and **v2**. It is possible to migrate without losing anything, it's just that the documentation is not done yet. See [Issue #196](https://github.com/FBoucher/AzUrlShortener/issues/196) for more details on the progress.
---

### Update the Azure Functions

Navigate to the Azure portal (azure.portal.com) and select the Azure Function instance, for this project.

Expand Down Expand Up @@ -76,13 +92,10 @@ If you are interested to learn more about what's under the hood, and get more de

## What's Next?

We are working on the **version 1.0** (ETA Summer 2020). This version will:
We are working on the **version 2.0** (ETA Summer 2020). This version will:

- Use Azure Active Directory (AAD)
- Client side website (more budget friendly) see GitHub project: [TinyBlazorAdmin](https://github.com/FBoucher/TinyBlazorAdmin) for more details.

Optional (if not then soon after)

- Statistics
- Better Grid to display the URL

Expand Down
13 changes: 10 additions & 3 deletions deployment/debug.azcli
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ az group deployment validate -g c5mShortDemo --template-file "src/adminTools/ad
az group deployment create -g c5mShortDemo -n cloud5minsv1 --template-file "deployment/azureDeploy.json" --parameters "deployment/azureDeploy.params.json" --verbose





# Debuging fake ARM template
## validate with Parameter file
az group deployment validate -g c5mShortDemo --template-file "deployment/debugARM.json" --verbose

## deploy it
az group deployment create -g c5mShortDemo -n cloud5minsv1 --template-file "deployment/debugARM.json" --verbose


# --> IN PROGRESS <-- --> IN PROGRESS <-- --> IN PROGRESS <--

# Create the Service Princiapl and other Azure AD stuff for V1.x

#TenantID=$(az account list --query "[?name=='Frank Perso Dev'].tenantId" --output tsv)
#appID=$(az ad app create --display-name TinyAdminTestUI --reply-urls https://blue-stone-0c390700f.azurestaticapps.net/authentication/login-callback --query 'appId' -o tsv)


# --> END of IN PROGRESS zone <--
14 changes: 14 additions & 0 deletions src/adminTools/TinyBlazorAdmin/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Launch and Debug Standalone Blazor WebAssembly App",
"type": "blazorwasm",
"request": "launch",
"cwd": "${workspaceFolder}"
}
]
}
42 changes: 42 additions & 0 deletions src/adminTools/TinyBlazorAdmin/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TinyBlazorAdmin.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/TinyBlazorAdmin.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/TinyBlazorAdmin.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
23 changes: 23 additions & 0 deletions src/adminTools/TinyBlazorAdmin/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
{
<RedirectToLogin />
}
else
{
<p>You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.Extensions.Configuration;

namespace TinyBlazorAdmin.Data
{
/// <summary>
/// Handler to ensure proper credentials are sent with requests.
/// </summary>
public class AzFuncAuthorizationMessageHandler : AuthorizationMessageHandler
{
public string Endpoint { get; set; }

/// <summary>
/// Creates a new instance of the <see cref="AzFuncAuthorizationMessageHandler"/>
/// class.
/// </summary>
/// <param name="config"><see cref="IConfiguration"/> to access endpoint.</param>
/// <param name="provider"><see cref="IAccessTokenProvider"/> service.</param>
/// <param name="navigation"><see cref="NavigationManager"/> to navigate based on authentication.</param>
public AzFuncAuthorizationMessageHandler(
IConfiguration config,
IAccessTokenProvider provider,
NavigationManager navigation) : base(provider, navigation)
{
var section = config.GetSection(nameof(UrlShortenerSecuredService));
Endpoint = section.GetValue<string>(nameof(Endpoint));
ConfigureHandler(new[] { Endpoint });
}
}
}
47 changes: 47 additions & 0 deletions src/adminTools/TinyBlazorAdmin/Data/AzFuncClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Threading.Tasks;

namespace TinyBlazorAdmin.Data
{
/// <summary>
/// Service to access the Cosmos DB blog posts.
/// </summary>
public class AzFuncClient
{

/// <summary>
/// The <see cref="UrlShortenerSecuredService"/> to retrive credentials.
/// </summary>
private readonly UrlShortenerSecuredService _urlSecuredService;

/// <summary>
/// Creates a new instance of the <see cref="AzFuncClient"/> class.
/// </summary>
/// <param name="urlSecuredService">The <see cref="UrlShortenerSecuredService"/> to request the token.</param>
public AzFuncClient(UrlShortenerSecuredService urlSecuredService)
{
_urlSecuredService = urlSecuredService;
}


public async Task<ShortUrlList> GetUrlList(){
var result = await _urlSecuredService.GetUrlList();
return result;
}

public async Task<ShortUrlList> CreateShortUrl(ShortUrlRequest shortUrlRequest){
var result = await _urlSecuredService.CreateShortUrl(shortUrlRequest);
return result;
}

public async Task<ShortUrlEntity> UpdateShortUrl(ShortUrlEntity editedUrl){
var result = await _urlSecuredService.UpdateShortUrl(editedUrl);
return result;
}

public async Task<ShortUrlEntity> ArchiveShortUrl(ShortUrlEntity archivedUrl){
var result = await _urlSecuredService.ArchiveShortUrl(archivedUrl);
return result;
}

}
}
42 changes: 42 additions & 0 deletions src/adminTools/TinyBlazorAdmin/Data/ShortUrlEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Linq;

namespace TinyBlazorAdmin.Data
{
public class ShortUrlEntity
{
public string PartitionKey { get; set; }

public string RowKey { get; set; }

public string Title { get; set; }

public string Url { get; set; }

public string ShortUrl { get; set; }

public int Clicks { get; set; }

public ShortUrlEntity(){}

public static ShortUrlEntity GetEntity(string longUrl, string endUrl)
{
return new ShortUrlEntity
{
PartitionKey = endUrl.First().ToString(),
RowKey = endUrl,
Url = longUrl
};
}

public string GetDisplayableUrl(){

var length = Url.ToString().Length;
if (length >= 50){
return string.Concat(Url.Substring(0,49), "...");
}
return Url;
}
}


}
9 changes: 9 additions & 0 deletions src/adminTools/TinyBlazorAdmin/Data/ShortUrlList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace TinyBlazorAdmin.Data
{
public class ShortUrlList
{
public List<ShortUrlEntity> UrlList { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/adminTools/TinyBlazorAdmin/Data/ShortUrlRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace TinyBlazorAdmin.Data
{
public class ShortUrlRequest
{
private string _vanity;

public string Title { get; set; }


public string Vanity {
get{
return (_vanity != null)?_vanity:string.Empty;
}
set{
_vanity = value;
}
}

[Required]
public string Url { get; set; }

}
}
Loading

0 comments on commit 6c3269a

Please sign in to comment.