Disabling endpoints at runtime?

Hey guys, not sure if it was possible at all but was curious, is it possible to disable endpoints at runtime?

Adding more context, I want to have more control or provide control to admin users as to when or not these endpoints fire, or possibly perhaps disabling the schedule, @adam is this currently possible? Or maybe an enterprise feature?

well you could use the cache scope
by using the following inside the endpoint.

if($cache:Endpoints.“THIS ENDPOINT”.run -eq $true) {
Endpoint code
} else {
Endpoint not enabled skipping
}

This is the best solution at the moment. There isn’t a built in way to do this.

Actually, you probably could use Authorization Policies for this with enterprise. The users would be provided JSON web tokens with particualr information in the tokens and then you could use authorization policies to validate whether those users hold the rights to execute the endpoints.

this looks promising will have to give it a shot, though I believe the endpoints themselves are dynamic, (I currently have split out for this particular project all endpoints in separate files…)

@McAndersDK I’ve tried using $cache:endpoints[0].run -eq $false, with no luck, @adam mentioned there’s probably no clean way of doing this… the JSON webtokens sounds fancy but I need to give access to stop currently running(scheduled) endpoints from executing…

Did you define the variable? :slight_smile:

@McAndersDK, what I did was give a value to the ID parameter, looking at the endpoint object, I see that the cache endpoint + that endpoint with the name value is there, using this $cache:Endpoints.Checks.run -eq $false, still cant get it to stop firing…

image

The endpoint will fire/run, but the content in the IF statement will nok run, so who care if the endpoint fire and close down miliseconds after? :slight_smile:

@McAndersDK, gotcha this would be super slick… just cant get it to work on my end :wink: can you provide a snippit that would help? when I wrap this that inside the endpoint its throwing a .net framwork error: MissingMethodException: Method not found, (also fyi I’m currently using UD 2.9.0/WinPosh 5.1)

Here’s what I’m doing…

$ScheduleAppChecks = New-UDEndpointSchedule -Every 1 -Minute

$EndpointChecks = New-UDEndpoint -Id EPChecks -Schedule $ScheduleAppChecks -Endpoint {

    if ($cache:Endpoints.EPChecks.run -eq $false) {

        $AppName = "GWServers"

        $cache:AppURLGWS = @( foreach ($server in $GWServers | select -First 2 ) {

                try {   

                    $Processexec = Start-customprocess

                }

                catch {

                    [PSCustomObject]@{

                        Results = "Err - Could not establish connection "

                        Type    = "Browser"

                        Object  = $server

                    } 

                    continue

                }

            }

        )

    }

    else {

        write-output "do nothing...."

    }

}

$cache:Endpoints = @($EndpointChecks)

Start-UDDashboard -Port 8075 -Dashboard $Dash -Endpoint  $cache:Endpoints

You need to define the variable.

@McAndersDK, where, I’m missing something…

well you wanted to disable an endpoint at runtime?..
but how do you want to do that?
you need to set that variable in “that”.

if(“IwantToDisableEndpoint” -eq $true) {

#Disable endpoint

$cache:Endpoints = [PSCustomObject]@{

EPChecks = [PSCustomObject]@{

    run = $false

}

}

} else {

#Reactivate endpoint

$cache:Endpoints = [PSCustomObject]@{

    EPChecks = [PSCustomObject]@{

        run = $true

    }

}   

}