Multienvironment for Autotask Functions? Dynamically loading secrets

I'd like to use the same source code, but load different secrets based on which autotask is running.

Autotask_Development loads CONTRACT_ADDRESS_DEVELOPMENT secret for contract interactions
Autotask_Staging loads CONTRACT_ADDRESS_STAGING secret for contract interactions

This would make development much easier since we are merging up environments and having to change the secret manually each time

How can I detect which autotask is running?

Hi @flaco_jones

Currently we don't support multi-environment tags for Defender components(Admin, Relay, Autotask, Sentinel) but it is something we have on our roadmap and it is definitely a useful feature.

Just thinking, would it be helpful for you to read autotaskName and autotaskId from function handler arguments? We don't support this yet but it could be useful for your use case.

exports.handler = async function(event) {
  const autotaskName= event.autotaskName;
  const autotaskId = event.autotaskId;
}

Best regards,
Zeljko

That would be incredibly useful.

Either name or ID. It's just that I have a development, staging, and production environment and separate secrets/address/config for each, but the code is ideally identical and able to be pull requested up environments without overwriting things like event.secrets.CONRACT_ADDRESS_DEVELOPMENT

So yup! +100 on that feature. Thanks for your help.

Hi @flaco_jones

I am happy to inform you that latest release includes changes proposed above.

Handler argument now contains autotaskName and autotaskId fields.

exports.handler = async function(event) {
  const autotaskName= event.autotaskName;
  const autotaskId = event.autotaskId;
}

Best regards,
Zeljko

Ya'll rule. USING THIS! thank you.