Few options. You can create and engage a Sequence
to reject the message based on the Day or Time. Something similar to below. The following example will reject messages coming in on the weekend or after 5PM or before 8AM each day. But this will be an overhead on the service.
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="WeekEndChecker" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="get-property('SYSTEM_DATE', 'EEEEE')" name="day" scope="default" type="STRING"/>
<property expression="get-property('SYSTEM_DATE', 'HH')" name="hour" scope="default" type="STRING"/>
<filter xpath="$ctx:day != 'Saturday' and $ctx:day != 'Sunday' and 17 >= number($ctx:hour) and number($ctx:hour) >= 8">
<then>
<log>
<property name="MSG" value="Allowed to Access"/>
</log>
</then>
<else>
<property name="HTTP_SC" scope="axis2" type="STRING" value="401"/>
<payloadFactory media-type="xml">
<format>
<Error xmlns="">You are not allowed to access this service during the off hours.</Error>
</format>
<args/>
</payloadFactory>
<respond/>
</else>
</filter>
</sequence>
Another Option is, in API Manager you can change the State of the API to a state like blocked
during the off hours. You can probably automate this process using the apictl
, check this.
In the same way in MI you can deactivate Proxy services, you can use the mi CLI for this. Check here.