Follow

Getting Started with Service Endpoints

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.

  1. Open the EvOps Account that you want to activate the extension in
  2. Click Extensions
  3. Click Add
  4. Select Service Endpoints from the list
  5. Click Activate
  6. When extension has been activated successfully, open Service Endpoint extension and verify that it's healthy by reviewing the health graph 
  7. 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

  1. Expand your Function App
  2. Click +
  3. Check Experimental Language Support
  4. Click PowerShell in the HTTP trigger section
  5. Provide Name and select Function as Authorization level, then click Create
  6. 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

  1. Open Azure Stack or Azure Portal dependent on where your Azure Function is hosted and open Function Apps list
  2. Find and expand your Function App
  3. In the Functions node select the function you want to add to EvOps
  4. Click Get function URL
  5. 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.
  6. Close window
  7. 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. 

  1. Click Extensions
  2. Click Service Endpoints
  3. Manage endpoints
  4. Click Add
  5. Select Azure Function as Type and provide a descriptive Display name
  6. Paste Function App URL gathered earlier into the URL field
  7. 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:
    1. Remote source: Function app that populates wizard prompt (Text,Text-box, List, etc.) with data when prompt blades are loaded or refreshed
    2. Remote validation: Function app that validates wizard prompt selection/input data and can provide a custom message if validation fails
  8. 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.

  1. Open a Request Template
  2. Click Wizard
  3. Add a prompt of your choice
  4. Click Source and select Service Endpoint
  5. Click Source Configuration
  6. Select the service endpoint registered earlier from the Endpoint list

    Note: Only service endpoints with purpose Remote validation will be listed.
  7. 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.

  1. Open a Request Template
  2. Click Wizard
  3. Add a prompt of your choice
  4. Click Add new validator and select Remote validation
  5. Click the new validator
  6. In Message, type in a text that will be shown when validation fails
  7. Select a service endpoint from the Endpoint list
    Note: Only service endpoints with purpose Remote validation will be listed.
  8. Click OK and save Request Template
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments