Service Endpoints Concepts
Service Endpoints extension provides the capabilities to execute code to validate and populate prompts in request template wizards. Currently Azure Functions hosted in Azure Stack and Azure are supported. When Service Endpoints are called, a data-object is attached to the call that lets the Service Endpoint get access to user information and previous selections in the wizard.
Activating Service Endpoints Extension
Activating the Service Endpoint extension is a simple task.
- Open the EvOps Account that you want to activate the extension in
- Click Extensions
- Click Add
- Select Service Endpoints from the list
- Click Activate
- When extension has been activated successfully, open Service Endpoint extension and verify that it's healthy by reviewing the health graph
- Done
How to Write Your Function
There are many different types of functions in Azure Functions. For EvOps integration, HTTP triggered functions are used. In this document we show samples with PowerShell, but you can use C# or JavaScript or any other of the supported languages when writing your functions.
Quick Guide Creating a Function
- Expand your Function App
- Click +
- Check Experimental Language Support
- Click PowerShell in the HTTP trigger section
- Provide Name and select Function as Authorization level, then click Create
- Now you are ready to start writing your function
Function App PowerShell Samples
Remote Source Function
This script will use values of the wizard prompts with Prompt id purpose and role and construct a service name using a randomized number. This script shows the basic capabilities but can of course be extended with advanced functions and integrations.
# POST method: $req $requestBody = Get-Content $req -Raw | ConvertFrom-Json $purpose = $requestBody.userInput.purpose.value.value $type = $requestBody.userInput.role.value.value $random = Get-Random -Maximum 100 $generatedSvcName = '' if ($purpose.length -gt 1 -and $type.length -gt 1) { $generatedSvcName = "svc-" + $type.Substring(0,3).toLower() + $random + "-" + $purpose.toLower() } $result = New-Object -TypeName psobject -Property @{ items = @( New-Object -TypeName psobject -Property @{ displayName = $generatedSvcName; value = $generatedSvcName; isDefault = $false; } ); isReadonly = $false; } $result = $result | ConvertTo-Json Out-File -Encoding Ascii -FilePath $res -inputObject $result
Remote Validation Function App
This script will get a value to validate from the request body. Logic is then added to decide if the value is valid or not.
# POST method: $req $requestBody = Get-Content $req -Raw | ConvertFrom-Json $value = $requestBody.valueToValidate $result = New-Object -TypeName psobject -Property @{ valid = $true; message = "Ok" } if ($value -eq 'Admin' -or $value -eq 'Administrator') { $result.valid = $false; $result.message = "Username $value are not allowed as username" } $result = $result | ConvertTo-Json Out-File -Encoding Ascii -FilePath $res -inputObject $result
Adding a Function App Service Endpoint
When you have written your Azure Function and it's time to add the function to the EvOps Service Endpoints repository, you need to follow the steps below.
Getting Function App URL
- Open Azure Stack or Azure Portal dependent on where your Azure Function is hosted and open Function Apps list
- Find and expand your Function App
- In the Functions node select the function you want to add to EvOps
- Click Get function URL
- Click Copy and save the URL in a safe temporary location, you will be using it later
Note: This URL contains an access token that provides access to the function. - Close window
- Now you are ready for the next step
Registering Function App as a Service Endpoint
For the function app to be available in EvOps, please follow these steps.
- Click Extensions
- Click Service Endpoints
- Manage endpoints
- Click Add
- Select Azure Function as Type and provide a descriptive Display name
- Paste Function App URL gathered earlier into the URL field
- Select Purpose of function. Different purposes decide what data the Function App will have access to and is expected to return when executed. Currently there are two different options:
- Remote source: Function app that populates wizard prompt (Text,Text-box, List, etc.) with data when prompt blades are loaded or refreshed
- Remote validation: Function app that validates wizard prompt selection/input data and can provide a custom message if validation fails
- Click OK to Save
Configure Function to Populate Wizard Prompt Value
Prompt remote source is configured per prompt in the wizard section in the request template.
- Open a Request Template
- Click Wizard
- Add a prompt of your choice
- Click Source and select Service Endpoint
- Click Source Configuration
- Select the service endpoint registered earlier from the Endpoint list
Note: Only service endpoints with purpose Remote validation will be listed. - Click OK and save Request Template
Configure Function to Validate Wizard Prompt Value
Prompt validation is configured per prompt in the wizard section in the request template.
- Open a Request Template
- Click Wizard
- Add a prompt of your choice
- Click Add new validator and select Remote validation
- Click the new validator
- In Message, type in a text that will be shown when validation fails
- Select a service endpoint from the Endpoint list
Note: Only service endpoints with purpose Remote validation will be listed. - Click OK and save Request Template
Comments
0 comments
Article is closed for comments.