feat: block notifications, and cleanup of action/binding IDs
This commit is contained in:
parent
499bcdc827
commit
6493f7bee7
|
|
@ -50,7 +50,7 @@ actions:
|
||||||
popupOnStart: execution-button
|
popupOnStart: execution-button
|
||||||
maxRate:
|
maxRate:
|
||||||
- limit: 3
|
- limit: 3
|
||||||
duration: 5m
|
duration: 1m
|
||||||
|
|
||||||
# You are not limited to operating system commands, and of course you can run
|
# You are not limited to operating system commands, and of course you can run
|
||||||
# your own scripts. Here `maxConcurrent` stops the script running multiple
|
# your own scripts. Here `maxConcurrent` stops the script running multiple
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
import { buttonResults } from '../resources/vue/stores/buttonResults.js'
|
import { buttonResults } from '../resources/vue/stores/buttonResults.js'
|
||||||
|
import { rateLimits } from '../resources/vue/stores/rateLimits.js'
|
||||||
|
|
||||||
export function initWebsocket () {
|
export function initWebsocket () {
|
||||||
window.addEventListener('EventOutputChunk', onOutputChunk)
|
window.addEventListener('EventOutputChunk', onOutputChunk)
|
||||||
|
window.addEventListener('EventExecutionStarted', onExecutionChanged)
|
||||||
|
window.addEventListener('EventExecutionFinished', onExecutionChanged)
|
||||||
|
|
||||||
reconnectWebsocket()
|
reconnectWebsocket()
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +43,6 @@ function handleEvent (msg) {
|
||||||
break
|
break
|
||||||
case 'EventExecutionFinished':
|
case 'EventExecutionFinished':
|
||||||
case 'EventExecutionStarted':
|
case 'EventExecutionStarted':
|
||||||
buttonResults[msg.event.value.logEntry.executionTrackingId] = msg.event.value.logEntry
|
|
||||||
window.dispatchEvent(j)
|
window.dispatchEvent(j)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|
@ -59,3 +61,19 @@ function onOutputChunk (evt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onExecutionChanged (evt) {
|
||||||
|
buttonResults[evt.payload.logEntry.executionTrackingId] = evt.payload.logEntry
|
||||||
|
|
||||||
|
const logEntry = evt.payload.logEntry
|
||||||
|
|
||||||
|
// Update rate limit store from logEntry if rate limit expiry datetime is provided
|
||||||
|
if (logEntry && logEntry.datetimeRateLimitExpires && logEntry.bindingId) {
|
||||||
|
// Parse datetime string "2006-01-02 15:04:05" and convert to Unix timestamp
|
||||||
|
const date = new Date(logEntry.datetimeRateLimitExpires.replace(' ', 'T'))
|
||||||
|
rateLimits[logEntry.bindingId] = date.getTime() / 1000
|
||||||
|
} else if (logEntry && logEntry.bindingId) {
|
||||||
|
// Clear rate limit if not set
|
||||||
|
rateLimits[logEntry.bindingId] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -53,6 +53,13 @@ export declare type Action = Message<"olivetin.api.v1.Action"> & {
|
||||||
* @generated from field: int32 timeout = 8;
|
* @generated from field: int32 timeout = 8;
|
||||||
*/
|
*/
|
||||||
timeout: number;
|
timeout: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Datetime when rate limit expires (empty string if not rate limited), format: "2006-01-02 15:04:05"
|
||||||
|
*
|
||||||
|
* @generated from field: string datetime_rate_limit_expires = 9;
|
||||||
|
*/
|
||||||
|
datetimeRateLimitExpires: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -548,11 +555,6 @@ export declare type LogEntry = Message<"olivetin.api.v1.LogEntry"> & {
|
||||||
*/
|
*/
|
||||||
datetimeFinished: string;
|
datetimeFinished: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* @generated from field: string action_id = 13;
|
|
||||||
*/
|
|
||||||
actionId: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @generated from field: bool execution_started = 14;
|
* @generated from field: bool execution_started = 14;
|
||||||
*/
|
*/
|
||||||
|
|
@ -577,6 +579,20 @@ export declare type LogEntry = Message<"olivetin.api.v1.LogEntry"> & {
|
||||||
* @generated from field: bool can_kill = 18;
|
* @generated from field: bool can_kill = 18;
|
||||||
*/
|
*/
|
||||||
canKill: boolean;
|
canKill: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Datetime when rate limit expires (empty string if not rate limited), format: "2006-01-02 15:04:05"
|
||||||
|
*
|
||||||
|
* @generated from field: string datetime_rate_limit_expires = 19;
|
||||||
|
*/
|
||||||
|
datetimeRateLimitExpires: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binding ID for matching rate limits to action buttons
|
||||||
|
*
|
||||||
|
* @generated from field: string binding_id = 20;
|
||||||
|
*/
|
||||||
|
bindingId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -909,9 +925,9 @@ export declare type DumpVarsResponse = Message<"olivetin.api.v1.DumpVarsResponse
|
||||||
export declare const DumpVarsResponseSchema: GenMessage<DumpVarsResponse>;
|
export declare const DumpVarsResponseSchema: GenMessage<DumpVarsResponse>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @generated from message olivetin.api.v1.ActionEntityPair
|
* @generated from message olivetin.api.v1.DebugBinding
|
||||||
*/
|
*/
|
||||||
export declare type ActionEntityPair = Message<"olivetin.api.v1.ActionEntityPair"> & {
|
export declare type DebugBinding = Message<"olivetin.api.v1.DebugBinding"> & {
|
||||||
/**
|
/**
|
||||||
* @generated from field: string action_title = 1;
|
* @generated from field: string action_title = 1;
|
||||||
*/
|
*/
|
||||||
|
|
@ -924,10 +940,10 @@ export declare type ActionEntityPair = Message<"olivetin.api.v1.ActionEntityPair
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the message olivetin.api.v1.ActionEntityPair.
|
* Describes the message olivetin.api.v1.DebugBinding.
|
||||||
* Use `create(ActionEntityPairSchema)` to create a new message.
|
* Use `create(DebugBindingSchema)` to create a new message.
|
||||||
*/
|
*/
|
||||||
export declare const ActionEntityPairSchema: GenMessage<ActionEntityPair>;
|
export declare const DebugBindingSchema: GenMessage<DebugBinding>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @generated from message olivetin.api.v1.DumpPublicIdActionMapRequest
|
* @generated from message olivetin.api.v1.DumpPublicIdActionMapRequest
|
||||||
|
|
@ -951,9 +967,9 @@ export declare type DumpPublicIdActionMapResponse = Message<"olivetin.api.v1.Dum
|
||||||
alert: string;
|
alert: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @generated from field: map<string, olivetin.api.v1.ActionEntityPair> contents = 2;
|
* @generated from field: map<string, olivetin.api.v1.DebugBinding> contents = 2;
|
||||||
*/
|
*/
|
||||||
contents: { [key: string]: ActionEntityPair };
|
contents: { [key: string]: DebugBinding };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div :id="`actionButton-${actionId}`" role="none" class="action-button">
|
<div :id="`actionButton-${bindingId}`" role="none" class="action-button">
|
||||||
<button :id="`actionButtonInner-${actionId}`" :title="title" :disabled="!canExec || isDisabled"
|
<button :id="`actionButtonInner-${bindingId}`" :title="title" :disabled="!canExec || isDisabled"
|
||||||
:class="combinedClasses" @click="handleClick">
|
:class="combinedClasses" @click="handleClick">
|
||||||
|
|
||||||
<div class="navigate-on-start-container">
|
<div class="navigate-on-start-container">
|
||||||
|
|
@ -18,18 +18,19 @@
|
||||||
<span class="icon" v-html="unicodeIcon"></span>
|
<span class="icon" v-html="unicodeIcon"></span>
|
||||||
<span class="title" aria-live="polite">{{ displayTitle }}
|
<span class="title" aria-live="polite">{{ displayTitle }}
|
||||||
</span>
|
</span>
|
||||||
|
<span v-if="rateLimitMessage" class="rate-limit-message">{{ rateLimitMessage }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import ArgumentForm from './views/ArgumentForm.vue'
|
|
||||||
import { buttonResults } from './stores/buttonResults'
|
import { buttonResults } from './stores/buttonResults'
|
||||||
|
import { rateLimits } from './stores/rateLimits'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { HugeiconsIcon } from '@hugeicons/vue'
|
import { HugeiconsIcon } from '@hugeicons/vue'
|
||||||
import { WorkoutRunIcon, TypeCursorIcon, ComputerTerminal01Icon } from '@hugeicons/core-free-icons'
|
import { WorkoutRunIcon, TypeCursorIcon, ComputerTerminal01Icon } from '@hugeicons/core-free-icons'
|
||||||
|
|
||||||
import { ref, watch, onMounted, inject, computed } from 'vue'
|
import { ref, watch, onMounted, onUnmounted, inject, computed } from 'vue'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const navigateOnStart = ref('')
|
const navigateOnStart = ref('')
|
||||||
|
|
@ -46,7 +47,7 @@ const props = defineProps({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const actionId = ref('')
|
const bindingId = ref('')
|
||||||
const title = ref('')
|
const title = ref('')
|
||||||
const canExec = ref(true)
|
const canExec = ref(true)
|
||||||
const popupOnStart = ref('')
|
const popupOnStart = ref('')
|
||||||
|
|
@ -59,6 +60,12 @@ const displayTitle = ref('')
|
||||||
const isDisabled = ref(false)
|
const isDisabled = ref(false)
|
||||||
const showArgumentForm = ref(false)
|
const showArgumentForm = ref(false)
|
||||||
|
|
||||||
|
// Rate limiting
|
||||||
|
const rateLimitExpires = ref(0)
|
||||||
|
const isRateLimited = ref(false)
|
||||||
|
const rateLimitMessage = ref('')
|
||||||
|
let rateLimitInterval = null
|
||||||
|
|
||||||
// Animation classes
|
// Animation classes
|
||||||
const buttonClasses = ref([])
|
const buttonClasses = ref([])
|
||||||
|
|
||||||
|
|
@ -89,7 +96,7 @@ function constructFromJson(json) {
|
||||||
|
|
||||||
updateFromJson(json)
|
updateFromJson(json)
|
||||||
|
|
||||||
actionId.value = json.bindingId
|
bindingId.value = json.bindingId
|
||||||
title.value = json.title
|
title.value = json.title
|
||||||
canExec.value = json.canExec
|
canExec.value = json.canExec
|
||||||
popupOnStart.value = json.popupOnStart
|
popupOnStart.value = json.popupOnStart
|
||||||
|
|
@ -103,6 +110,19 @@ function constructFromJson(json) {
|
||||||
isDisabled.value = !json.canExec
|
isDisabled.value = !json.canExec
|
||||||
displayTitle.value = title.value
|
displayTitle.value = title.value
|
||||||
unicodeIcon.value = getUnicodeIcon(json.icon)
|
unicodeIcon.value = getUnicodeIcon(json.icon)
|
||||||
|
|
||||||
|
// Initialize rate limit from action data (parse datetime string)
|
||||||
|
if (json.datetimeRateLimitExpires) {
|
||||||
|
const date = new Date(json.datetimeRateLimitExpires.replace(' ', 'T'))
|
||||||
|
rateLimitExpires.value = date.getTime() / 1000
|
||||||
|
} else {
|
||||||
|
rateLimitExpires.value = 0
|
||||||
|
}
|
||||||
|
// Also initialize the store so the watch picks it up
|
||||||
|
if (bindingId.value) {
|
||||||
|
rateLimits[bindingId.value] = rateLimitExpires.value
|
||||||
|
}
|
||||||
|
updateRateLimitStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFromJson(json) {
|
function updateFromJson(json) {
|
||||||
|
|
@ -110,6 +130,55 @@ function updateFromJson(json) {
|
||||||
// title - as the callback URL relies on it
|
// title - as the callback URL relies on it
|
||||||
|
|
||||||
unicodeIcon.value = getUnicodeIcon(json.icon)
|
unicodeIcon.value = getUnicodeIcon(json.icon)
|
||||||
|
|
||||||
|
// Update rate limiting if changed (parse datetime string)
|
||||||
|
if (json.datetimeRateLimitExpires) {
|
||||||
|
const date = new Date(json.datetimeRateLimitExpires.replace(' ', 'T'))
|
||||||
|
rateLimitExpires.value = date.getTime() / 1000
|
||||||
|
updateRateLimitStatus()
|
||||||
|
} else if (json.datetimeRateLimitExpires === '') {
|
||||||
|
// Explicitly clear if empty string
|
||||||
|
rateLimitExpires.value = 0
|
||||||
|
updateRateLimitStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRateLimitStatus() {
|
||||||
|
if (rateLimitExpires.value === 0) {
|
||||||
|
isRateLimited.value = false
|
||||||
|
rateLimitMessage.value = ''
|
||||||
|
if (rateLimitInterval) {
|
||||||
|
clearInterval(rateLimitInterval)
|
||||||
|
rateLimitInterval = null
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = Math.floor(Date.now() / 1000)
|
||||||
|
const expires = rateLimitExpires.value
|
||||||
|
|
||||||
|
if (now >= expires) {
|
||||||
|
// Rate limit has expired
|
||||||
|
isRateLimited.value = false
|
||||||
|
rateLimitMessage.value = ''
|
||||||
|
rateLimitExpires.value = 0
|
||||||
|
if (rateLimitInterval) {
|
||||||
|
clearInterval(rateLimitInterval)
|
||||||
|
rateLimitInterval = null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Still rate limited
|
||||||
|
isRateLimited.value = true
|
||||||
|
const secondsRemaining = expires - now
|
||||||
|
rateLimitMessage.value = `Rate limited, available in ${secondsRemaining} second${secondsRemaining !== 1 ? 's' : ''}`
|
||||||
|
|
||||||
|
// Set up interval to update every second
|
||||||
|
if (!rateLimitInterval) {
|
||||||
|
rateLimitInterval = setInterval(() => {
|
||||||
|
updateRateLimitStatus()
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleClick() {
|
async function handleClick() {
|
||||||
|
|
@ -213,6 +282,30 @@ function onExecStatusChanged() {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
constructFromJson(props.actionData)
|
constructFromJson(props.actionData)
|
||||||
|
|
||||||
|
// Watch the central rate limit store for updates to this button's bindingId
|
||||||
|
// Watch the entire rateLimits object to ensure reactivity with dynamic keys
|
||||||
|
watch(
|
||||||
|
rateLimits,
|
||||||
|
() => {
|
||||||
|
const id = bindingId.value
|
||||||
|
if (id && rateLimits[id] !== undefined) {
|
||||||
|
const newExpires = rateLimits[id]
|
||||||
|
if (newExpires !== rateLimitExpires.value) {
|
||||||
|
rateLimitExpires.value = newExpires
|
||||||
|
updateRateLimitStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (rateLimitInterval) {
|
||||||
|
clearInterval(rateLimitInterval)
|
||||||
|
rateLimitInterval = null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -270,6 +363,13 @@ watch(
|
||||||
padding: 0.2em;
|
padding: 0.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.action-button button .rate-limit-message {
|
||||||
|
font-size: 0.75em;
|
||||||
|
color: #856404;
|
||||||
|
padding: 0.2em;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
/* Animation classes */
|
/* Animation classes */
|
||||||
.action-button button.action-timeout {
|
.action-button button.action-timeout {
|
||||||
background: #fff3cd;
|
background: #fff3cd;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
|
||||||
|
import { buttonResults } from '../stores/buttonResults'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
component: {
|
component: {
|
||||||
|
|
@ -23,7 +24,20 @@ const props = defineProps({
|
||||||
|
|
||||||
const output = ref('Waiting...')
|
const output = ref('Waiting...')
|
||||||
const executionTrackingId = ref(null)
|
const executionTrackingId = ref(null)
|
||||||
let eventListener = null
|
let unwatchButtonResults = null
|
||||||
|
|
||||||
|
function updateFromLogEntry(logEntry) {
|
||||||
|
if (logEntry) {
|
||||||
|
if (logEntry.output !== undefined) {
|
||||||
|
output.value = logEntry.output
|
||||||
|
} else {
|
||||||
|
output.value = 'No output available'
|
||||||
|
}
|
||||||
|
if (logEntry.executionTrackingId) {
|
||||||
|
executionTrackingId.value = logEntry.executionTrackingId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchMostRecentExecution() {
|
async function fetchMostRecentExecution() {
|
||||||
if (!props.component.title) {
|
if (!props.component.title) {
|
||||||
|
|
@ -46,14 +60,7 @@ async function fetchMostRecentExecution() {
|
||||||
const result = await window.client.executionStatus(executionStatusArgs)
|
const result = await window.client.executionStatus(executionStatusArgs)
|
||||||
|
|
||||||
if (result.logEntry) {
|
if (result.logEntry) {
|
||||||
if (result.logEntry.output !== undefined) {
|
updateFromLogEntry(result.logEntry)
|
||||||
output.value = result.logEntry.output
|
|
||||||
} else {
|
|
||||||
output.value = 'No output available'
|
|
||||||
}
|
|
||||||
if (result.logEntry.executionTrackingId) {
|
|
||||||
executionTrackingId.value = result.logEntry.executionTrackingId
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
output.value = 'No output available'
|
output.value = 'No output available'
|
||||||
executionTrackingId.value = null
|
executionTrackingId.value = null
|
||||||
|
|
@ -70,32 +77,39 @@ async function fetchMostRecentExecution() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExecutionFinished(event) {
|
|
||||||
// The dashboard component "title" field is used for lots of things
|
|
||||||
// and in this context for MreOutput it's just to refer to an actionId.
|
|
||||||
//
|
|
||||||
// So this is not a typo.
|
|
||||||
const logEntry = event.payload.logEntry
|
|
||||||
if (logEntry && logEntry.actionId === props.component.title) {
|
|
||||||
if (logEntry.output !== undefined) {
|
|
||||||
output.value = logEntry.output
|
|
||||||
}
|
|
||||||
if (logEntry.executionTrackingId) {
|
|
||||||
executionTrackingId.value = logEntry.executionTrackingId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchMostRecentExecution()
|
fetchMostRecentExecution()
|
||||||
|
|
||||||
eventListener = (event) => handleExecutionFinished(event)
|
unwatchButtonResults = watch(
|
||||||
window.addEventListener('EventExecutionFinished', eventListener)
|
buttonResults,
|
||||||
|
() => {
|
||||||
|
// Find the most recent finished execution for this bindingId
|
||||||
|
const bindingId = props.component.title
|
||||||
|
let mostRecent = null
|
||||||
|
let mostRecentTime = null
|
||||||
|
|
||||||
|
for (const trackingId in buttonResults) {
|
||||||
|
const logEntry = buttonResults[trackingId]
|
||||||
|
if (logEntry && logEntry.bindingId === bindingId && logEntry.executionFinished) {
|
||||||
|
const finishedTime = new Date(logEntry.datetimeFinished)
|
||||||
|
if (!mostRecent || finishedTime > mostRecentTime) {
|
||||||
|
mostRecent = logEntry
|
||||||
|
mostRecentTime = finishedTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mostRecent) {
|
||||||
|
updateFromLogEntry(mostRecent)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
if (eventListener) {
|
if (unwatchButtonResults) {
|
||||||
window.removeEventListener('EventExecutionFinished', eventListener)
|
unwatchButtonResults()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { reactive } from 'vue'
|
||||||
|
|
||||||
|
// Store rate limit expiry times by bindingId
|
||||||
|
// This allows all ActionButton components to reactively update when rate limits change
|
||||||
|
export const rateLimits = reactive({})
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
logLevel: debug
|
logLevel: debug
|
||||||
|
|
||||||
|
insecureAllowDumpActionMap: true
|
||||||
|
|
||||||
actions:
|
actions:
|
||||||
- title: Check status
|
- title: Check status
|
||||||
id: status_command
|
id: status_command
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,7 @@ describe('config: stdout-most-recent-execution', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stdout-most-recent-execution updates after action execution', async function () {
|
it('stdout-most-recent-execution updates after action execution', async function () {
|
||||||
this.timeout(30000) // Increase timeout for this test
|
this.timeout(45000)
|
||||||
|
|
||||||
await getRootAndWait()
|
await getRootAndWait()
|
||||||
|
|
||||||
// Wait for the mre-output element
|
// Wait for the mre-output element
|
||||||
|
|
@ -105,7 +104,7 @@ describe('config: stdout-most-recent-execution', function () {
|
||||||
await statusButton.click()
|
await statusButton.click()
|
||||||
|
|
||||||
// Wait a moment for the action to start
|
// Wait a moment for the action to start
|
||||||
await webdriver.sleep(500)
|
await webdriver.sleep(2000)
|
||||||
|
|
||||||
// Wait for the output to update (the component listens to EventExecutionFinished events)
|
// Wait for the output to update (the component listens to EventExecutionFinished events)
|
||||||
// We'll wait for the output to change from the initial state
|
// We'll wait for the output to change from the initial state
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ message Action {
|
||||||
string popup_on_start = 6;
|
string popup_on_start = 6;
|
||||||
int32 order = 7;
|
int32 order = 7;
|
||||||
int32 timeout = 8;
|
int32 timeout = 8;
|
||||||
|
string datetime_rate_limit_expires = 9; // Datetime when rate limit expires (empty string if not rate limited), format: "2006-01-02 15:04:05"
|
||||||
}
|
}
|
||||||
|
|
||||||
message ActionArgument {
|
message ActionArgument {
|
||||||
|
|
@ -133,12 +134,13 @@ message LogEntry {
|
||||||
repeated string tags = 10;
|
repeated string tags = 10;
|
||||||
string execution_tracking_id = 11;
|
string execution_tracking_id = 11;
|
||||||
string datetime_finished = 12;
|
string datetime_finished = 12;
|
||||||
string action_id = 13;
|
|
||||||
bool execution_started = 14;
|
bool execution_started = 14;
|
||||||
bool execution_finished = 15;
|
bool execution_finished = 15;
|
||||||
bool blocked = 16;
|
bool blocked = 16;
|
||||||
int64 datetime_index = 17;
|
int64 datetime_index = 17;
|
||||||
bool can_kill = 18;
|
bool can_kill = 18;
|
||||||
|
string datetime_rate_limit_expires = 19; // Datetime when rate limit expires (empty string if not rate limited), format: "2006-01-02 15:04:05"
|
||||||
|
string binding_id = 20; // Binding ID for matching rate limits to action buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetLogsResponse {
|
message GetLogsResponse {
|
||||||
|
|
@ -216,7 +218,7 @@ message DumpVarsResponse {
|
||||||
map<string, string> contents = 2;
|
map<string, string> contents = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ActionEntityPair {
|
message DebugBinding {
|
||||||
string action_title = 1;
|
string action_title = 1;
|
||||||
string entity_prefix = 2;
|
string entity_prefix = 2;
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +226,7 @@ message ActionEntityPair {
|
||||||
message DumpPublicIdActionMapRequest {}
|
message DumpPublicIdActionMapRequest {}
|
||||||
message DumpPublicIdActionMapResponse {
|
message DumpPublicIdActionMapResponse {
|
||||||
string alert = 1;
|
string alert = 1;
|
||||||
map<string, ActionEntityPair> contents = 2;
|
map<string, DebugBinding> contents = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetReadyzRequest {}
|
message GetReadyzRequest {}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ type Action struct {
|
||||||
PopupOnStart string `protobuf:"bytes,6,opt,name=popup_on_start,json=popupOnStart,proto3" json:"popup_on_start,omitempty"`
|
PopupOnStart string `protobuf:"bytes,6,opt,name=popup_on_start,json=popupOnStart,proto3" json:"popup_on_start,omitempty"`
|
||||||
Order int32 `protobuf:"varint,7,opt,name=order,proto3" json:"order,omitempty"`
|
Order int32 `protobuf:"varint,7,opt,name=order,proto3" json:"order,omitempty"`
|
||||||
Timeout int32 `protobuf:"varint,8,opt,name=timeout,proto3" json:"timeout,omitempty"`
|
Timeout int32 `protobuf:"varint,8,opt,name=timeout,proto3" json:"timeout,omitempty"`
|
||||||
|
DatetimeRateLimitExpires string `protobuf:"bytes,9,opt,name=datetime_rate_limit_expires,json=datetimeRateLimitExpires,proto3" json:"datetime_rate_limit_expires,omitempty"` // Datetime when rate limit expires (empty string if not rate limited), format: "2006-01-02 15:04:05"
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
@ -121,6 +122,13 @@ func (x *Action) GetTimeout() int32 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Action) GetDatetimeRateLimitExpires() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.DatetimeRateLimitExpires
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type ActionArgument struct {
|
type ActionArgument struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
|
@ -1150,12 +1158,13 @@ type LogEntry struct {
|
||||||
Tags []string `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty"`
|
Tags []string `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty"`
|
||||||
ExecutionTrackingId string `protobuf:"bytes,11,opt,name=execution_tracking_id,json=executionTrackingId,proto3" json:"execution_tracking_id,omitempty"`
|
ExecutionTrackingId string `protobuf:"bytes,11,opt,name=execution_tracking_id,json=executionTrackingId,proto3" json:"execution_tracking_id,omitempty"`
|
||||||
DatetimeFinished string `protobuf:"bytes,12,opt,name=datetime_finished,json=datetimeFinished,proto3" json:"datetime_finished,omitempty"`
|
DatetimeFinished string `protobuf:"bytes,12,opt,name=datetime_finished,json=datetimeFinished,proto3" json:"datetime_finished,omitempty"`
|
||||||
ActionId string `protobuf:"bytes,13,opt,name=action_id,json=actionId,proto3" json:"action_id,omitempty"`
|
|
||||||
ExecutionStarted bool `protobuf:"varint,14,opt,name=execution_started,json=executionStarted,proto3" json:"execution_started,omitempty"`
|
ExecutionStarted bool `protobuf:"varint,14,opt,name=execution_started,json=executionStarted,proto3" json:"execution_started,omitempty"`
|
||||||
ExecutionFinished bool `protobuf:"varint,15,opt,name=execution_finished,json=executionFinished,proto3" json:"execution_finished,omitempty"`
|
ExecutionFinished bool `protobuf:"varint,15,opt,name=execution_finished,json=executionFinished,proto3" json:"execution_finished,omitempty"`
|
||||||
Blocked bool `protobuf:"varint,16,opt,name=blocked,proto3" json:"blocked,omitempty"`
|
Blocked bool `protobuf:"varint,16,opt,name=blocked,proto3" json:"blocked,omitempty"`
|
||||||
DatetimeIndex int64 `protobuf:"varint,17,opt,name=datetime_index,json=datetimeIndex,proto3" json:"datetime_index,omitempty"`
|
DatetimeIndex int64 `protobuf:"varint,17,opt,name=datetime_index,json=datetimeIndex,proto3" json:"datetime_index,omitempty"`
|
||||||
CanKill bool `protobuf:"varint,18,opt,name=can_kill,json=canKill,proto3" json:"can_kill,omitempty"`
|
CanKill bool `protobuf:"varint,18,opt,name=can_kill,json=canKill,proto3" json:"can_kill,omitempty"`
|
||||||
|
DatetimeRateLimitExpires string `protobuf:"bytes,19,opt,name=datetime_rate_limit_expires,json=datetimeRateLimitExpires,proto3" json:"datetime_rate_limit_expires,omitempty"` // Datetime when rate limit expires (empty string if not rate limited), format: "2006-01-02 15:04:05"
|
||||||
|
BindingId string `protobuf:"bytes,20,opt,name=binding_id,json=bindingId,proto3" json:"binding_id,omitempty"` // Binding ID for matching rate limits to action buttons
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
@ -1267,13 +1276,6 @@ func (x *LogEntry) GetDatetimeFinished() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LogEntry) GetActionId() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.ActionId
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *LogEntry) GetExecutionStarted() bool {
|
func (x *LogEntry) GetExecutionStarted() bool {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.ExecutionStarted
|
return x.ExecutionStarted
|
||||||
|
|
@ -1309,6 +1311,20 @@ func (x *LogEntry) GetCanKill() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *LogEntry) GetDatetimeRateLimitExpires() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.DatetimeRateLimitExpires
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *LogEntry) GetBindingId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.BindingId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type GetLogsResponse struct {
|
type GetLogsResponse struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Logs []*LogEntry `protobuf:"bytes,1,rep,name=logs,proto3" json:"logs,omitempty"`
|
Logs []*LogEntry `protobuf:"bytes,1,rep,name=logs,proto3" json:"logs,omitempty"`
|
||||||
|
|
@ -2097,7 +2113,7 @@ func (x *DumpVarsResponse) GetContents() map[string]string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionEntityPair struct {
|
type DebugBinding struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
ActionTitle string `protobuf:"bytes,1,opt,name=action_title,json=actionTitle,proto3" json:"action_title,omitempty"`
|
ActionTitle string `protobuf:"bytes,1,opt,name=action_title,json=actionTitle,proto3" json:"action_title,omitempty"`
|
||||||
EntityPrefix string `protobuf:"bytes,2,opt,name=entity_prefix,json=entityPrefix,proto3" json:"entity_prefix,omitempty"`
|
EntityPrefix string `protobuf:"bytes,2,opt,name=entity_prefix,json=entityPrefix,proto3" json:"entity_prefix,omitempty"`
|
||||||
|
|
@ -2105,20 +2121,20 @@ type ActionEntityPair struct {
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionEntityPair) Reset() {
|
func (x *DebugBinding) Reset() {
|
||||||
*x = ActionEntityPair{}
|
*x = DebugBinding{}
|
||||||
mi := &file_olivetin_api_v1_olivetin_proto_msgTypes[35]
|
mi := &file_olivetin_api_v1_olivetin_proto_msgTypes[35]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionEntityPair) String() string {
|
func (x *DebugBinding) String() string {
|
||||||
return protoimpl.X.MessageStringOf(x)
|
return protoimpl.X.MessageStringOf(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ActionEntityPair) ProtoMessage() {}
|
func (*DebugBinding) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *ActionEntityPair) ProtoReflect() protoreflect.Message {
|
func (x *DebugBinding) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_olivetin_api_v1_olivetin_proto_msgTypes[35]
|
mi := &file_olivetin_api_v1_olivetin_proto_msgTypes[35]
|
||||||
if x != nil {
|
if x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
|
@ -2130,19 +2146,19 @@ func (x *ActionEntityPair) ProtoReflect() protoreflect.Message {
|
||||||
return mi.MessageOf(x)
|
return mi.MessageOf(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use ActionEntityPair.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DebugBinding.ProtoReflect.Descriptor instead.
|
||||||
func (*ActionEntityPair) Descriptor() ([]byte, []int) {
|
func (*DebugBinding) Descriptor() ([]byte, []int) {
|
||||||
return file_olivetin_api_v1_olivetin_proto_rawDescGZIP(), []int{35}
|
return file_olivetin_api_v1_olivetin_proto_rawDescGZIP(), []int{35}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionEntityPair) GetActionTitle() string {
|
func (x *DebugBinding) GetActionTitle() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.ActionTitle
|
return x.ActionTitle
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionEntityPair) GetEntityPrefix() string {
|
func (x *DebugBinding) GetEntityPrefix() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.EntityPrefix
|
return x.EntityPrefix
|
||||||
}
|
}
|
||||||
|
|
@ -2188,7 +2204,7 @@ func (*DumpPublicIdActionMapRequest) Descriptor() ([]byte, []int) {
|
||||||
type DumpPublicIdActionMapResponse struct {
|
type DumpPublicIdActionMapResponse struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Alert string `protobuf:"bytes,1,opt,name=alert,proto3" json:"alert,omitempty"`
|
Alert string `protobuf:"bytes,1,opt,name=alert,proto3" json:"alert,omitempty"`
|
||||||
Contents map[string]*ActionEntityPair `protobuf:"bytes,2,rep,name=contents,proto3" json:"contents,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
Contents map[string]*DebugBinding `protobuf:"bytes,2,rep,name=contents,proto3" json:"contents,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
@ -2230,7 +2246,7 @@ func (x *DumpPublicIdActionMapResponse) GetAlert() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DumpPublicIdActionMapResponse) GetContents() map[string]*ActionEntityPair {
|
func (x *DumpPublicIdActionMapResponse) GetContents() map[string]*DebugBinding {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Contents
|
return x.Contents
|
||||||
}
|
}
|
||||||
|
|
@ -3847,7 +3863,7 @@ var File_olivetin_api_v1_olivetin_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
const file_olivetin_api_v1_olivetin_proto_rawDesc = "" +
|
const file_olivetin_api_v1_olivetin_proto_rawDesc = "" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\x1eolivetin/api/v1/olivetin.proto\x12\x0folivetin.api.v1\"\x81\x02\n" +
|
"\x1eolivetin/api/v1/olivetin.proto\x12\x0folivetin.api.v1\"\xc0\x02\n" +
|
||||||
"\x06Action\x12\x1d\n" +
|
"\x06Action\x12\x1d\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"binding_id\x18\x01 \x01(\tR\tbindingId\x12\x14\n" +
|
"binding_id\x18\x01 \x01(\tR\tbindingId\x12\x14\n" +
|
||||||
|
|
@ -3857,7 +3873,8 @@ const file_olivetin_api_v1_olivetin_proto_rawDesc = "" +
|
||||||
"\targuments\x18\x05 \x03(\v2\x1f.olivetin.api.v1.ActionArgumentR\targuments\x12$\n" +
|
"\targuments\x18\x05 \x03(\v2\x1f.olivetin.api.v1.ActionArgumentR\targuments\x12$\n" +
|
||||||
"\x0epopup_on_start\x18\x06 \x01(\tR\fpopupOnStart\x12\x14\n" +
|
"\x0epopup_on_start\x18\x06 \x01(\tR\fpopupOnStart\x12\x14\n" +
|
||||||
"\x05order\x18\a \x01(\x05R\x05order\x12\x18\n" +
|
"\x05order\x18\a \x01(\x05R\x05order\x12\x18\n" +
|
||||||
"\atimeout\x18\b \x01(\x05R\atimeout\"\xa2\x03\n" +
|
"\atimeout\x18\b \x01(\x05R\atimeout\x12=\n" +
|
||||||
|
"\x1bdatetime_rate_limit_expires\x18\t \x01(\tR\x18datetimeRateLimitExpires\"\xa2\x03\n" +
|
||||||
"\x0eActionArgument\x12\x12\n" +
|
"\x0eActionArgument\x12\x12\n" +
|
||||||
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
|
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
|
||||||
"\x05title\x18\x02 \x01(\tR\x05title\x12\x12\n" +
|
"\x05title\x18\x02 \x01(\tR\x05title\x12\x12\n" +
|
||||||
|
|
@ -3933,7 +3950,7 @@ const file_olivetin_api_v1_olivetin_proto_rawDesc = "" +
|
||||||
"\x1fStartActionByGetAndWaitResponse\x126\n" +
|
"\x1fStartActionByGetAndWaitResponse\x126\n" +
|
||||||
"\tlog_entry\x18\x01 \x01(\v2\x19.olivetin.api.v1.LogEntryR\blogEntry\"3\n" +
|
"\tlog_entry\x18\x01 \x01(\v2\x19.olivetin.api.v1.LogEntryR\blogEntry\"3\n" +
|
||||||
"\x0eGetLogsRequest\x12!\n" +
|
"\x0eGetLogsRequest\x12!\n" +
|
||||||
"\fstart_offset\x18\x01 \x01(\x03R\vstartOffset\"\xc8\x04\n" +
|
"\fstart_offset\x18\x01 \x01(\x03R\vstartOffset\"\x89\x05\n" +
|
||||||
"\bLogEntry\x12)\n" +
|
"\bLogEntry\x12)\n" +
|
||||||
"\x10datetime_started\x18\x01 \x01(\tR\x0fdatetimeStarted\x12!\n" +
|
"\x10datetime_started\x18\x01 \x01(\tR\x0fdatetimeStarted\x12!\n" +
|
||||||
"\faction_title\x18\x02 \x01(\tR\vactionTitle\x12\x16\n" +
|
"\faction_title\x18\x02 \x01(\tR\vactionTitle\x12\x16\n" +
|
||||||
|
|
@ -3948,13 +3965,15 @@ const file_olivetin_api_v1_olivetin_proto_rawDesc = "" +
|
||||||
"\x04tags\x18\n" +
|
"\x04tags\x18\n" +
|
||||||
" \x03(\tR\x04tags\x122\n" +
|
" \x03(\tR\x04tags\x122\n" +
|
||||||
"\x15execution_tracking_id\x18\v \x01(\tR\x13executionTrackingId\x12+\n" +
|
"\x15execution_tracking_id\x18\v \x01(\tR\x13executionTrackingId\x12+\n" +
|
||||||
"\x11datetime_finished\x18\f \x01(\tR\x10datetimeFinished\x12\x1b\n" +
|
"\x11datetime_finished\x18\f \x01(\tR\x10datetimeFinished\x12+\n" +
|
||||||
"\taction_id\x18\r \x01(\tR\bactionId\x12+\n" +
|
|
||||||
"\x11execution_started\x18\x0e \x01(\bR\x10executionStarted\x12-\n" +
|
"\x11execution_started\x18\x0e \x01(\bR\x10executionStarted\x12-\n" +
|
||||||
"\x12execution_finished\x18\x0f \x01(\bR\x11executionFinished\x12\x18\n" +
|
"\x12execution_finished\x18\x0f \x01(\bR\x11executionFinished\x12\x18\n" +
|
||||||
"\ablocked\x18\x10 \x01(\bR\ablocked\x12%\n" +
|
"\ablocked\x18\x10 \x01(\bR\ablocked\x12%\n" +
|
||||||
"\x0edatetime_index\x18\x11 \x01(\x03R\rdatetimeIndex\x12\x19\n" +
|
"\x0edatetime_index\x18\x11 \x01(\x03R\rdatetimeIndex\x12\x19\n" +
|
||||||
"\bcan_kill\x18\x12 \x01(\bR\acanKill\"\xca\x01\n" +
|
"\bcan_kill\x18\x12 \x01(\bR\acanKill\x12=\n" +
|
||||||
|
"\x1bdatetime_rate_limit_expires\x18\x13 \x01(\tR\x18datetimeRateLimitExpires\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"binding_id\x18\x14 \x01(\tR\tbindingId\"\xca\x01\n" +
|
||||||
"\x0fGetLogsResponse\x12-\n" +
|
"\x0fGetLogsResponse\x12-\n" +
|
||||||
"\x04logs\x18\x01 \x03(\v2\x19.olivetin.api.v1.LogEntryR\x04logs\x12'\n" +
|
"\x04logs\x18\x01 \x03(\v2\x19.olivetin.api.v1.LogEntryR\x04logs\x12'\n" +
|
||||||
"\x0fcount_remaining\x18\x02 \x01(\x03R\x0ecountRemaining\x12\x1b\n" +
|
"\x0fcount_remaining\x18\x02 \x01(\x03R\x0ecountRemaining\x12\x1b\n" +
|
||||||
|
|
@ -4006,17 +4025,17 @@ const file_olivetin_api_v1_olivetin_proto_rawDesc = "" +
|
||||||
"\bcontents\x18\x02 \x03(\v2/.olivetin.api.v1.DumpVarsResponse.ContentsEntryR\bcontents\x1a;\n" +
|
"\bcontents\x18\x02 \x03(\v2/.olivetin.api.v1.DumpVarsResponse.ContentsEntryR\bcontents\x1a;\n" +
|
||||||
"\rContentsEntry\x12\x10\n" +
|
"\rContentsEntry\x12\x10\n" +
|
||||||
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
|
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
|
||||||
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"Z\n" +
|
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"V\n" +
|
||||||
"\x10ActionEntityPair\x12!\n" +
|
"\fDebugBinding\x12!\n" +
|
||||||
"\faction_title\x18\x01 \x01(\tR\vactionTitle\x12#\n" +
|
"\faction_title\x18\x01 \x01(\tR\vactionTitle\x12#\n" +
|
||||||
"\rentity_prefix\x18\x02 \x01(\tR\fentityPrefix\"\x1e\n" +
|
"\rentity_prefix\x18\x02 \x01(\tR\fentityPrefix\"\x1e\n" +
|
||||||
"\x1cDumpPublicIdActionMapRequest\"\xef\x01\n" +
|
"\x1cDumpPublicIdActionMapRequest\"\xeb\x01\n" +
|
||||||
"\x1dDumpPublicIdActionMapResponse\x12\x14\n" +
|
"\x1dDumpPublicIdActionMapResponse\x12\x14\n" +
|
||||||
"\x05alert\x18\x01 \x01(\tR\x05alert\x12X\n" +
|
"\x05alert\x18\x01 \x01(\tR\x05alert\x12X\n" +
|
||||||
"\bcontents\x18\x02 \x03(\v2<.olivetin.api.v1.DumpPublicIdActionMapResponse.ContentsEntryR\bcontents\x1a^\n" +
|
"\bcontents\x18\x02 \x03(\v2<.olivetin.api.v1.DumpPublicIdActionMapResponse.ContentsEntryR\bcontents\x1aZ\n" +
|
||||||
"\rContentsEntry\x12\x10\n" +
|
"\rContentsEntry\x12\x10\n" +
|
||||||
"\x03key\x18\x01 \x01(\tR\x03key\x127\n" +
|
"\x03key\x18\x01 \x01(\tR\x03key\x123\n" +
|
||||||
"\x05value\x18\x02 \x01(\v2!.olivetin.api.v1.ActionEntityPairR\x05value:\x028\x01\"\x12\n" +
|
"\x05value\x18\x02 \x01(\v2\x1d.olivetin.api.v1.DebugBindingR\x05value:\x028\x01\"\x12\n" +
|
||||||
"\x10GetReadyzRequest\"+\n" +
|
"\x10GetReadyzRequest\"+\n" +
|
||||||
"\x11GetReadyzResponse\x12\x16\n" +
|
"\x11GetReadyzResponse\x12\x16\n" +
|
||||||
"\x06status\x18\x01 \x01(\tR\x06status\"\x14\n" +
|
"\x06status\x18\x01 \x01(\tR\x06status\"\x14\n" +
|
||||||
|
|
@ -4190,7 +4209,7 @@ var file_olivetin_api_v1_olivetin_proto_goTypes = []any{
|
||||||
(*SosReportResponse)(nil), // 32: olivetin.api.v1.SosReportResponse
|
(*SosReportResponse)(nil), // 32: olivetin.api.v1.SosReportResponse
|
||||||
(*DumpVarsRequest)(nil), // 33: olivetin.api.v1.DumpVarsRequest
|
(*DumpVarsRequest)(nil), // 33: olivetin.api.v1.DumpVarsRequest
|
||||||
(*DumpVarsResponse)(nil), // 34: olivetin.api.v1.DumpVarsResponse
|
(*DumpVarsResponse)(nil), // 34: olivetin.api.v1.DumpVarsResponse
|
||||||
(*ActionEntityPair)(nil), // 35: olivetin.api.v1.ActionEntityPair
|
(*DebugBinding)(nil), // 35: olivetin.api.v1.DebugBinding
|
||||||
(*DumpPublicIdActionMapRequest)(nil), // 36: olivetin.api.v1.DumpPublicIdActionMapRequest
|
(*DumpPublicIdActionMapRequest)(nil), // 36: olivetin.api.v1.DumpPublicIdActionMapRequest
|
||||||
(*DumpPublicIdActionMapResponse)(nil), // 37: olivetin.api.v1.DumpPublicIdActionMapResponse
|
(*DumpPublicIdActionMapResponse)(nil), // 37: olivetin.api.v1.DumpPublicIdActionMapResponse
|
||||||
(*GetReadyzRequest)(nil), // 38: olivetin.api.v1.GetReadyzRequest
|
(*GetReadyzRequest)(nil), // 38: olivetin.api.v1.GetReadyzRequest
|
||||||
|
|
@ -4259,7 +4278,7 @@ var file_olivetin_api_v1_olivetin_proto_depIdxs = []int32{
|
||||||
0, // 27: olivetin.api.v1.GetActionBindingResponse.action:type_name -> olivetin.api.v1.Action
|
0, // 27: olivetin.api.v1.GetActionBindingResponse.action:type_name -> olivetin.api.v1.Action
|
||||||
65, // 28: olivetin.api.v1.GetEntitiesResponse.entity_definitions:type_name -> olivetin.api.v1.EntityDefinition
|
65, // 28: olivetin.api.v1.GetEntitiesResponse.entity_definitions:type_name -> olivetin.api.v1.EntityDefinition
|
||||||
3, // 29: olivetin.api.v1.EntityDefinition.instances:type_name -> olivetin.api.v1.Entity
|
3, // 29: olivetin.api.v1.EntityDefinition.instances:type_name -> olivetin.api.v1.Entity
|
||||||
35, // 30: olivetin.api.v1.DumpPublicIdActionMapResponse.ContentsEntry.value:type_name -> olivetin.api.v1.ActionEntityPair
|
35, // 30: olivetin.api.v1.DumpPublicIdActionMapResponse.ContentsEntry.value:type_name -> olivetin.api.v1.DebugBinding
|
||||||
6, // 31: olivetin.api.v1.OliveTinApiService.GetDashboard:input_type -> olivetin.api.v1.GetDashboardRequest
|
6, // 31: olivetin.api.v1.OliveTinApiService.GetDashboard:input_type -> olivetin.api.v1.GetDashboardRequest
|
||||||
9, // 32: olivetin.api.v1.OliveTinApiService.StartAction:input_type -> olivetin.api.v1.StartActionRequest
|
9, // 32: olivetin.api.v1.OliveTinApiService.StartAction:input_type -> olivetin.api.v1.StartActionRequest
|
||||||
12, // 33: olivetin.api.v1.OliveTinApiService.StartActionAndWait:input_type -> olivetin.api.v1.StartActionAndWaitRequest
|
12, // 33: olivetin.api.v1.OliveTinApiService.StartActionAndWait:input_type -> olivetin.api.v1.StartActionAndWaitRequest
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
acl "github.com/OliveTin/OliveTin/internal/acl"
|
acl "github.com/OliveTin/OliveTin/internal/acl"
|
||||||
auth "github.com/OliveTin/OliveTin/internal/auth"
|
auth "github.com/OliveTin/OliveTin/internal/auth"
|
||||||
|
|
@ -279,7 +280,6 @@ func (api *oliveTinAPI) internalLogEntryToPb(logEntry *executor.InternalLogEntry
|
||||||
pble := &apiv1.LogEntry{
|
pble := &apiv1.LogEntry{
|
||||||
ActionTitle: logEntry.ActionTitle,
|
ActionTitle: logEntry.ActionTitle,
|
||||||
ActionIcon: logEntry.ActionIcon,
|
ActionIcon: logEntry.ActionIcon,
|
||||||
ActionId: logEntry.ActionId,
|
|
||||||
DatetimeStarted: logEntry.DatetimeStarted.Format("2006-01-02 15:04:05"),
|
DatetimeStarted: logEntry.DatetimeStarted.Format("2006-01-02 15:04:05"),
|
||||||
DatetimeFinished: logEntry.DatetimeFinished.Format("2006-01-02 15:04:05"),
|
DatetimeFinished: logEntry.DatetimeFinished.Format("2006-01-02 15:04:05"),
|
||||||
DatetimeIndex: logEntry.Index,
|
DatetimeIndex: logEntry.Index,
|
||||||
|
|
@ -298,6 +298,19 @@ func (api *oliveTinAPI) internalLogEntryToPb(logEntry *executor.InternalLogEntry
|
||||||
pble.CanKill = acl.IsAllowedKill(api.cfg, authenticatedUser, logEntry.Binding.Action)
|
pble.CanKill = acl.IsAllowedKill(api.cfg, authenticatedUser, logEntry.Binding.Action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate rate limit expiry for the action
|
||||||
|
if logEntry.Binding != nil && logEntry.Binding.Action != nil {
|
||||||
|
pble.BindingId = logEntry.Binding.ID
|
||||||
|
|
||||||
|
expiryUnix := api.executor.GetTimeUntilAvailable(logEntry.Binding)
|
||||||
|
|
||||||
|
if expiryUnix > 0 {
|
||||||
|
pble.DatetimeRateLimitExpires = time.Unix(expiryUnix, 0).Format("2006-01-02 15:04:05")
|
||||||
|
} else {
|
||||||
|
pble.DatetimeRateLimitExpires = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return pble
|
return pble
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,10 +324,20 @@ func getExecutionStatusByTrackingID(api *oliveTinAPI, executionTrackingId string
|
||||||
return logEntry
|
return logEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMostRecentExecutionStatusById(api *oliveTinAPI, actionId string) *executor.InternalLogEntry {
|
// This is the actual action ID, not the binding ID.
|
||||||
|
func getMostRecentExecutionStatusByActionId(api *oliveTinAPI, actionId string) *executor.InternalLogEntry {
|
||||||
var ile *executor.InternalLogEntry
|
var ile *executor.InternalLogEntry
|
||||||
|
|
||||||
logs := api.executor.GetLogsByActionId(actionId)
|
binding := api.executor.FindBindingByID(actionId)
|
||||||
|
if binding == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
logs := api.executor.GetLogsByBindingId(binding.ID)
|
||||||
|
|
||||||
|
if len(logs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(logs) == 0 {
|
if len(logs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -341,7 +364,7 @@ func (api *oliveTinAPI) ExecutionStatus(ctx ctx.Context, req *connect.Request[ap
|
||||||
ile = getExecutionStatusByTrackingID(api, req.Msg.ExecutionTrackingId)
|
ile = getExecutionStatusByTrackingID(api, req.Msg.ExecutionTrackingId)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ile = getMostRecentExecutionStatusById(api, req.Msg.ActionId)
|
ile = getMostRecentExecutionStatusByActionId(api, req.Msg.ActionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ile == nil {
|
if ile == nil {
|
||||||
|
|
@ -539,7 +562,7 @@ func (api *oliveTinAPI) GetActionLogs(ctx ctx.Context, req *connect.Request[apiv
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
filtered := api.filterLogsByACL(api.executor.GetLogsByActionId(req.Msg.ActionId), user)
|
filtered := api.filterLogsByACL(api.executor.GetLogsByBindingId(req.Msg.ActionId), user)
|
||||||
page := paginate(int64(len(filtered)), api.cfg.LogHistoryPageSize, req.Msg.StartOffset)
|
page := paginate(int64(len(filtered)), api.cfg.LogHistoryPageSize, req.Msg.StartOffset)
|
||||||
if page.empty {
|
if page.empty {
|
||||||
return connect.NewResponse(buildEmptyPageResponse(page)), nil
|
return connect.NewResponse(buildEmptyPageResponse(page)), nil
|
||||||
|
|
@ -688,7 +711,7 @@ func (api *oliveTinAPI) DumpVars(ctx ctx.Context, req *connect.Request[apiv1.Dum
|
||||||
|
|
||||||
func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *connect.Request[apiv1.DumpPublicIdActionMapRequest]) (*connect.Response[apiv1.DumpPublicIdActionMapResponse], error) {
|
func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *connect.Request[apiv1.DumpPublicIdActionMapRequest]) (*connect.Response[apiv1.DumpPublicIdActionMapResponse], error) {
|
||||||
res := &apiv1.DumpPublicIdActionMapResponse{}
|
res := &apiv1.DumpPublicIdActionMapResponse{}
|
||||||
res.Contents = make(map[string]*apiv1.ActionEntityPair)
|
res.Contents = make(map[string]*apiv1.DebugBinding)
|
||||||
|
|
||||||
if !api.cfg.InsecureAllowDumpActionMap {
|
if !api.cfg.InsecureAllowDumpActionMap {
|
||||||
res.Alert = "Dumping Public IDs is disallowed."
|
res.Alert = "Dumping Public IDs is disallowed."
|
||||||
|
|
@ -696,16 +719,15 @@ func (api *oliveTinAPI) DumpPublicIdActionMap(ctx ctx.Context, req *connect.Requ
|
||||||
return connect.NewResponse(res), nil
|
return connect.NewResponse(res), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
api.executor.MapActionIdToBindingLock.RLock()
|
api.executor.MapActionBindingsLock.RLock()
|
||||||
|
|
||||||
for k, v := range api.executor.MapActionIdToBinding {
|
for k, v := range api.executor.MapActionBindings {
|
||||||
res.Contents[k] = &apiv1.ActionEntityPair{
|
res.Contents[k] = &apiv1.DebugBinding{
|
||||||
ActionTitle: v.Action.Title,
|
ActionTitle: v.Action.Title,
|
||||||
EntityPrefix: "?",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api.executor.MapActionIdToBindingLock.RUnlock()
|
api.executor.MapActionBindingsLock.RUnlock()
|
||||||
|
|
||||||
res.Alert = "Dumping variables has been enabled in the configuration. Please set InsecureAllowDumpActionMap = false again after you don't need it anymore"
|
res.Alert = "Dumping variables has been enabled in the configuration. Please set InsecureAllowDumpActionMap = false again after you don't need it anymore"
|
||||||
|
|
||||||
|
|
@ -813,7 +835,7 @@ func (api *oliveTinAPI) OnExecutionStarted(ex *executor.InternalLogEntry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *oliveTinAPI) OnExecutionFinished(ex *executor.InternalLogEntry) {
|
func (api *oliveTinAPI) OnExecutionFinished(ile *executor.InternalLogEntry) {
|
||||||
toRemove := []*streamingClient{}
|
toRemove := []*streamingClient{}
|
||||||
|
|
||||||
for _, client := range api.copyOfStreamingClients() {
|
for _, client := range api.copyOfStreamingClients() {
|
||||||
|
|
@ -821,7 +843,7 @@ func (api *oliveTinAPI) OnExecutionFinished(ex *executor.InternalLogEntry) {
|
||||||
case client.channel <- &apiv1.EventStreamResponse{
|
case client.channel <- &apiv1.EventStreamResponse{
|
||||||
Event: &apiv1.EventStreamResponse_ExecutionFinished{
|
Event: &apiv1.EventStreamResponse_ExecutionFinished{
|
||||||
ExecutionFinished: &apiv1.EventExecutionFinished{
|
ExecutionFinished: &apiv1.EventExecutionFinished{
|
||||||
LogEntry: api.internalLogEntryToPb(ex, client.AuthenticatedUser),
|
LogEntry: api.internalLogEntryToPb(ile, client.AuthenticatedUser),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}:
|
}:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package api
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
|
@ -27,10 +28,10 @@ func (rr *DashboardRenderRequest) findAction(title string) *apiv1.Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *DashboardRenderRequest) findActionForEntity(title string, entity *entities.Entity) *apiv1.Action {
|
func (rr *DashboardRenderRequest) findActionForEntity(title string, entity *entities.Entity) *apiv1.Action {
|
||||||
rr.ex.MapActionIdToBindingLock.RLock()
|
rr.ex.MapActionBindingsLock.RLock()
|
||||||
defer rr.ex.MapActionIdToBindingLock.RUnlock()
|
defer rr.ex.MapActionBindingsLock.RUnlock()
|
||||||
|
|
||||||
for _, binding := range rr.ex.MapActionIdToBinding {
|
for _, binding := range rr.ex.MapActionBindings {
|
||||||
if binding.Action.Title != title {
|
if binding.Action.Title != title {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +111,13 @@ func buildAction(actionBinding *executor.ActionBinding, rr *DashboardRenderReque
|
||||||
aclCanExec := acl.IsAllowedExec(rr.cfg, rr.AuthenticatedUser, action)
|
aclCanExec := acl.IsAllowedExec(rr.cfg, rr.AuthenticatedUser, action)
|
||||||
enabledExprCanExec := evaluateEnabledExpression(action, actionBinding.Entity)
|
enabledExprCanExec := evaluateEnabledExpression(action, actionBinding.Entity)
|
||||||
|
|
||||||
|
// Calculate rate limit expiry time
|
||||||
|
expiryUnix := rr.ex.GetTimeUntilAvailable(actionBinding)
|
||||||
|
datetimeRateLimitExpires := ""
|
||||||
|
if expiryUnix > 0 {
|
||||||
|
datetimeRateLimitExpires = time.Unix(expiryUnix, 0).Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
|
||||||
btn := apiv1.Action{
|
btn := apiv1.Action{
|
||||||
BindingId: actionBinding.ID,
|
BindingId: actionBinding.ID,
|
||||||
Title: entities.ParseTemplateWith(action.Title, actionBinding.Entity),
|
Title: entities.ParseTemplateWith(action.Title, actionBinding.Entity),
|
||||||
|
|
@ -118,6 +126,7 @@ func buildAction(actionBinding *executor.ActionBinding, rr *DashboardRenderReque
|
||||||
PopupOnStart: action.PopupOnStart,
|
PopupOnStart: action.PopupOnStart,
|
||||||
Order: int32(actionBinding.ConfigOrder),
|
Order: int32(actionBinding.ConfigOrder),
|
||||||
Timeout: int32(action.Timeout),
|
Timeout: int32(action.Timeout),
|
||||||
|
DatetimeRateLimitExpires: datetimeRateLimitExpires,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cfgArg := range action.Arguments {
|
for _, cfgArg := range action.Arguments {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getNewTestServerAndClient(t *testing.T, injectedConfig *config.Config) (*httptest.Server, apiv1connect.OliveTinApiServiceClient) {
|
func getNewTestServerAndClient(injectedConfig *config.Config) (*httptest.Server, apiv1connect.OliveTinApiServiceClient) {
|
||||||
ex := executor.DefaultExecutor(injectedConfig)
|
ex := executor.DefaultExecutor(injectedConfig)
|
||||||
ex.RebuildActionMap()
|
ex.RebuildActionMap()
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ func TestGetActionsAndStart(t *testing.T) {
|
||||||
ex := executor.DefaultExecutor(cfg)
|
ex := executor.DefaultExecutor(cfg)
|
||||||
ex.RebuildActionMap()
|
ex.RebuildActionMap()
|
||||||
|
|
||||||
conn, client := getNewTestServerAndClient(t, cfg)
|
conn, client := getNewTestServerAndClient(cfg)
|
||||||
|
|
||||||
respInit, errInit := client.Init(context.Background(), connect.NewRequest(&apiv1.InitRequest{}))
|
respInit, errInit := client.Init(context.Background(), connect.NewRequest(&apiv1.InitRequest{}))
|
||||||
respGetReady, errReady := client.GetReadyz(context.Background(), connect.NewRequest(&apiv1.GetReadyzRequest{}))
|
respGetReady, errReady := client.GetReadyz(context.Background(), connect.NewRequest(&apiv1.GetReadyzRequest{}))
|
||||||
|
|
@ -99,7 +99,7 @@ func TestGetActionsAndStart(t *testing.T) {
|
||||||
func TestGetEntities(t *testing.T) {
|
func TestGetEntities(t *testing.T) {
|
||||||
cfg := config.DefaultConfig()
|
cfg := config.DefaultConfig()
|
||||||
|
|
||||||
ts, client := getNewTestServerAndClient(t, cfg)
|
ts, client := getNewTestServerAndClient(cfg)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
setupTestEntities()
|
setupTestEntities()
|
||||||
|
|
@ -315,10 +315,10 @@ func TestBuildActionWithEnabledExpression(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func findBindingByTitle(ex *executor.Executor, title string) *executor.ActionBinding {
|
func findBindingByTitle(ex *executor.Executor, title string) *executor.ActionBinding {
|
||||||
ex.MapActionIdToBindingLock.RLock()
|
ex.MapActionBindingsLock.RLock()
|
||||||
defer ex.MapActionIdToBindingLock.RUnlock()
|
defer ex.MapActionBindingsLock.RUnlock()
|
||||||
|
|
||||||
for _, b := range ex.MapActionIdToBinding {
|
for _, b := range ex.MapActionBindings {
|
||||||
if b.Action.Title == title {
|
if b.Action.Title == title {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func buildDefaultDashboard(rr *DashboardRenderRequest) *apiv1.Dashboard {
|
||||||
Contents: make([]*apiv1.DashboardComponent, 0),
|
Contents: make([]*apiv1.DashboardComponent, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, binding := range rr.ex.MapActionIdToBinding {
|
for _, binding := range rr.ex.MapActionBindings {
|
||||||
if binding.Action.Hidden {
|
if binding.Action.Hidden {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,12 @@ type ActionBinding struct {
|
||||||
type Executor struct {
|
type Executor struct {
|
||||||
logs map[string]*InternalLogEntry
|
logs map[string]*InternalLogEntry
|
||||||
logsTrackingIdsByDate []string
|
logsTrackingIdsByDate []string
|
||||||
LogsByActionId map[string][]*InternalLogEntry
|
LogsByBindingId map[string][]*InternalLogEntry
|
||||||
|
|
||||||
logmutex sync.RWMutex
|
logmutex sync.RWMutex
|
||||||
|
|
||||||
MapActionIdToBinding map[string]*ActionBinding
|
MapActionBindings map[string]*ActionBinding
|
||||||
MapActionIdToBindingLock sync.RWMutex
|
MapActionBindingsLock sync.RWMutex
|
||||||
|
|
||||||
Cfg *config.Config
|
Cfg *config.Config
|
||||||
|
|
||||||
|
|
@ -86,7 +86,6 @@ type ExecutionRequest struct {
|
||||||
// easily serializable.
|
// easily serializable.
|
||||||
type InternalLogEntry struct {
|
type InternalLogEntry struct {
|
||||||
Binding *ActionBinding
|
Binding *ActionBinding
|
||||||
BindingID string
|
|
||||||
DatetimeStarted time.Time
|
DatetimeStarted time.Time
|
||||||
DatetimeFinished time.Time
|
DatetimeFinished time.Time
|
||||||
Output string
|
Output string
|
||||||
|
|
@ -110,7 +109,6 @@ type InternalLogEntry struct {
|
||||||
*/
|
*/
|
||||||
ActionTitle string
|
ActionTitle string
|
||||||
ActionIcon string
|
ActionIcon string
|
||||||
ActionId string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type executorStepFunc func(*ExecutionRequest) bool
|
type executorStepFunc func(*ExecutionRequest) bool
|
||||||
|
|
@ -122,8 +120,8 @@ func DefaultExecutor(cfg *config.Config) *Executor {
|
||||||
e.Cfg = cfg
|
e.Cfg = cfg
|
||||||
e.logs = make(map[string]*InternalLogEntry)
|
e.logs = make(map[string]*InternalLogEntry)
|
||||||
e.logsTrackingIdsByDate = make([]string, 0)
|
e.logsTrackingIdsByDate = make([]string, 0)
|
||||||
e.LogsByActionId = make(map[string][]*InternalLogEntry)
|
e.LogsByBindingId = make(map[string][]*InternalLogEntry)
|
||||||
e.MapActionIdToBinding = make(map[string]*ActionBinding)
|
e.MapActionBindings = make(map[string]*ActionBinding)
|
||||||
|
|
||||||
e.chainOfCommand = []executorStepFunc{
|
e.chainOfCommand = []executorStepFunc{
|
||||||
stepRequestAction,
|
stepRequestAction,
|
||||||
|
|
@ -297,10 +295,10 @@ func (e *Executor) GetLog(trackingID string) (*InternalLogEntry, bool) {
|
||||||
return entry, found
|
return entry, found
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) GetLogsByActionId(actionId string) []*InternalLogEntry {
|
func (e *Executor) GetLogsByBindingId(bindingId string) []*InternalLogEntry {
|
||||||
e.logmutex.RLock()
|
e.logmutex.RLock()
|
||||||
|
|
||||||
logs, found := e.LogsByActionId[actionId]
|
logs, found := e.LogsByBindingId[bindingId]
|
||||||
|
|
||||||
e.logmutex.RUnlock()
|
e.logmutex.RUnlock()
|
||||||
|
|
||||||
|
|
@ -311,6 +309,66 @@ func (e *Executor) GetLogsByActionId(actionId string) []*InternalLogEntry {
|
||||||
return logs
|
return logs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTimeUntilAvailable calculates when an action will be available again based on rate limits.
|
||||||
|
// Returns the Unix timestamp in seconds when the rate limit expires, or 0 if the action is available now.
|
||||||
|
func (e *Executor) GetTimeUntilAvailable(binding *ActionBinding) int64 {
|
||||||
|
if len(binding.Action.MaxRate) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
e.logmutex.RLock()
|
||||||
|
defer e.logmutex.RUnlock()
|
||||||
|
|
||||||
|
logs, found := e.LogsByBindingId[binding.ID]
|
||||||
|
if !found || len(logs) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
var maxExpiryTime time.Time
|
||||||
|
|
||||||
|
for _, rate := range binding.Action.MaxRate {
|
||||||
|
duration := parseDuration(rate)
|
||||||
|
if duration <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
then := now.Add(-duration)
|
||||||
|
executions := 0
|
||||||
|
var oldestExecutionTime *time.Time
|
||||||
|
|
||||||
|
for _, logEntry := range logs {
|
||||||
|
if logEntry.Blocked {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if logEntry.DatetimeStarted.After(then) {
|
||||||
|
executions++
|
||||||
|
if oldestExecutionTime == nil || logEntry.DatetimeStarted.Before(*oldestExecutionTime) {
|
||||||
|
oldestExecutionTime = &logEntry.DatetimeStarted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're at or over the limit, calculate when the oldest execution will fall outside the window
|
||||||
|
// Note: getExecutionsCount uses -1 because it counts the current execution, but we're checking
|
||||||
|
// availability before execution, so we compare directly to rate.Limit
|
||||||
|
if executions >= rate.Limit && oldestExecutionTime != nil {
|
||||||
|
// The oldest execution will fall outside the window at: oldestExecutionTime + duration
|
||||||
|
expiryTime := oldestExecutionTime.Add(duration)
|
||||||
|
if expiryTime.After(now) && (maxExpiryTime.IsZero() || expiryTime.After(maxExpiryTime)) {
|
||||||
|
maxExpiryTime = expiryTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if maxExpiryTime.IsZero() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxExpiryTime.Unix()
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Executor) SetLog(trackingID string, entry *InternalLogEntry) {
|
func (e *Executor) SetLog(trackingID string, entry *InternalLogEntry) {
|
||||||
e.logmutex.Lock()
|
e.logmutex.Lock()
|
||||||
|
|
||||||
|
|
@ -337,7 +395,6 @@ func (e *Executor) ExecRequest(req *ExecutionRequest) (*sync.WaitGroup, string)
|
||||||
ExitCode: DefaultExitCodeNotExecuted,
|
ExitCode: DefaultExitCodeNotExecuted,
|
||||||
ExecutionStarted: false,
|
ExecutionStarted: false,
|
||||||
ExecutionFinished: false,
|
ExecutionFinished: false,
|
||||||
ActionId: "",
|
|
||||||
ActionTitle: "notfound",
|
ActionTitle: "notfound",
|
||||||
ActionIcon: "💩",
|
ActionIcon: "💩",
|
||||||
Username: req.AuthenticatedUser.Username,
|
Username: req.AuthenticatedUser.Username,
|
||||||
|
|
@ -374,6 +431,11 @@ func (e *Executor) execChain(req *ExecutionRequest) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure DatetimeFinished is set even if execution was blocked early
|
||||||
|
if req.logEntry.DatetimeFinished.IsZero() {
|
||||||
|
req.logEntry.DatetimeFinished = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
req.logEntry.ExecutionFinished = true
|
req.logEntry.ExecutionFinished = true
|
||||||
|
|
||||||
// This isn't a step, because we want to notify all listeners, irrespective
|
// This isn't a step, because we want to notify all listeners, irrespective
|
||||||
|
|
@ -386,7 +448,7 @@ func getConcurrentCount(req *ExecutionRequest) int {
|
||||||
|
|
||||||
req.executor.logmutex.RLock()
|
req.executor.logmutex.RLock()
|
||||||
|
|
||||||
for _, log := range req.executor.GetLogsByActionId(req.Binding.Action.ID) {
|
for _, log := range req.executor.GetLogsByBindingId(req.Binding.ID) {
|
||||||
if !log.ExecutionFinished {
|
if !log.ExecutionFinished {
|
||||||
concurrentCount += 1
|
concurrentCount += 1
|
||||||
}
|
}
|
||||||
|
|
@ -436,7 +498,7 @@ func getExecutionsCount(rate config.RateSpec, req *ExecutionRequest) int {
|
||||||
|
|
||||||
then := time.Now().Add(-duration)
|
then := time.Now().Add(-duration)
|
||||||
|
|
||||||
for _, logEntry := range req.executor.GetLogsByActionId(req.Binding.Action.ID) {
|
for _, logEntry := range req.executor.GetLogsByBindingId(req.Binding.ID) {
|
||||||
// FIXME
|
// FIXME
|
||||||
/*
|
/*
|
||||||
if logEntry.EntityPrefix != req.EntityPrefix {
|
if logEntry.EntityPrefix != req.EntityPrefix {
|
||||||
|
|
@ -573,16 +635,15 @@ func stepRequestAction(req *ExecutionRequest) bool {
|
||||||
req.logEntry.ActionConfigTitle = req.Binding.Action.Title
|
req.logEntry.ActionConfigTitle = req.Binding.Action.Title
|
||||||
req.logEntry.ActionTitle = entities.ParseTemplateWith(req.Binding.Action.Title, req.Binding.Entity)
|
req.logEntry.ActionTitle = entities.ParseTemplateWith(req.Binding.Action.Title, req.Binding.Entity)
|
||||||
req.logEntry.ActionIcon = req.Binding.Action.Icon
|
req.logEntry.ActionIcon = req.Binding.Action.Icon
|
||||||
req.logEntry.ActionId = req.Binding.Action.ID
|
|
||||||
req.logEntry.Tags = req.Tags
|
req.logEntry.Tags = req.Tags
|
||||||
|
|
||||||
req.executor.logmutex.Lock()
|
req.executor.logmutex.Lock()
|
||||||
|
|
||||||
if _, containsKey := req.executor.LogsByActionId[req.Binding.Action.ID]; !containsKey {
|
if _, containsKey := req.executor.LogsByBindingId[req.Binding.ID]; !containsKey {
|
||||||
req.executor.LogsByActionId[req.Binding.Action.ID] = make([]*InternalLogEntry, 0)
|
req.executor.LogsByBindingId[req.Binding.ID] = make([]*InternalLogEntry, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.executor.LogsByActionId[req.Binding.Action.ID] = append(req.executor.LogsByActionId[req.Binding.Action.ID], req.logEntry)
|
req.executor.LogsByBindingId[req.Binding.ID] = append(req.executor.LogsByBindingId[req.Binding.ID], req.logEntry)
|
||||||
|
|
||||||
req.executor.logmutex.Unlock()
|
req.executor.logmutex.Unlock()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *Executor) FindBindingByID(id string) *ActionBinding {
|
func (e *Executor) FindBindingByID(id string) *ActionBinding {
|
||||||
e.MapActionIdToBindingLock.RLock()
|
e.MapActionBindingsLock.RLock()
|
||||||
pair, found := e.MapActionIdToBinding[id]
|
pair, found := e.MapActionBindings[id]
|
||||||
e.MapActionIdToBindingLock.RUnlock()
|
e.MapActionBindingsLock.RUnlock()
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -23,11 +23,11 @@ func (e *Executor) FindBindingByID(id string) *ActionBinding {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) FindBindingWithNoEntity(action *config.Action) *ActionBinding {
|
func (e *Executor) FindBindingWithNoEntity(action *config.Action) *ActionBinding {
|
||||||
e.MapActionIdToBindingLock.RLock()
|
e.MapActionBindingsLock.RLock()
|
||||||
|
|
||||||
defer e.MapActionIdToBindingLock.RUnlock()
|
defer e.MapActionBindingsLock.RUnlock()
|
||||||
|
|
||||||
for _, binding := range e.MapActionIdToBinding {
|
for _, binding := range e.MapActionBindings {
|
||||||
if binding.Action == action && binding.Entity == nil {
|
if binding.Action == action && binding.Entity == nil {
|
||||||
return binding
|
return binding
|
||||||
}
|
}
|
||||||
|
|
@ -42,9 +42,9 @@ type RebuildActionMapRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) RebuildActionMap() {
|
func (e *Executor) RebuildActionMap() {
|
||||||
e.MapActionIdToBindingLock.Lock()
|
e.MapActionBindingsLock.Lock()
|
||||||
|
|
||||||
clear(e.MapActionIdToBinding)
|
clear(e.MapActionBindings)
|
||||||
|
|
||||||
req := &RebuildActionMapRequest{
|
req := &RebuildActionMapRequest{
|
||||||
Cfg: e.Cfg,
|
Cfg: e.Cfg,
|
||||||
|
|
@ -65,7 +65,7 @@ func (e *Executor) RebuildActionMap() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.MapActionIdToBindingLock.Unlock()
|
e.MapActionBindingsLock.Unlock()
|
||||||
|
|
||||||
for _, l := range e.listeners {
|
for _, l := range e.listeners {
|
||||||
l.OnActionMapRebuilt()
|
l.OnActionMapRebuilt()
|
||||||
|
|
@ -100,10 +100,10 @@ func recurseDashboardForActionTitles(component *config.DashboardComponent, req *
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerAction(e *Executor, configOrder int, action *config.Action, req *RebuildActionMapRequest) {
|
func registerAction(e *Executor, configOrder int, action *config.Action, req *RebuildActionMapRequest) {
|
||||||
actionId := hashActionToID(action, "")
|
bindingId := generateActionBindingId(action, "")
|
||||||
|
|
||||||
e.MapActionIdToBinding[actionId] = &ActionBinding{
|
e.MapActionBindings[bindingId] = &ActionBinding{
|
||||||
ID: actionId,
|
ID: bindingId,
|
||||||
Action: action,
|
Action: action,
|
||||||
Entity: nil,
|
Entity: nil,
|
||||||
ConfigOrder: configOrder,
|
ConfigOrder: configOrder,
|
||||||
|
|
@ -118,9 +118,9 @@ func registerActionsFromEntities(e *Executor, configOrder int, entityTitle strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerActionFromEntity(e *Executor, configOrder int, tpl *config.Action, ent *entities.Entity, req *RebuildActionMapRequest) {
|
func registerActionFromEntity(e *Executor, configOrder int, tpl *config.Action, ent *entities.Entity, req *RebuildActionMapRequest) {
|
||||||
virtualActionId := hashActionToID(tpl, ent.UniqueKey)
|
virtualActionId := generateActionBindingId(tpl, ent.UniqueKey)
|
||||||
|
|
||||||
e.MapActionIdToBinding[virtualActionId] = &ActionBinding{
|
e.MapActionBindings[virtualActionId] = &ActionBinding{
|
||||||
ID: virtualActionId,
|
ID: virtualActionId,
|
||||||
Action: tpl,
|
Action: tpl,
|
||||||
Entity: ent,
|
Entity: ent,
|
||||||
|
|
@ -129,7 +129,7 @@ func registerActionFromEntity(e *Executor, configOrder int, tpl *config.Action,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashActionToID(action *config.Action, entityPrefix string) string {
|
func generateActionBindingId(action *config.Action, entityPrefix string) string {
|
||||||
if action.ID != "" && entityPrefix == "" {
|
if action.ID != "" && entityPrefix == "" {
|
||||||
return action.ID
|
return action.ID
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue