It was held in place by a removable nut. From the photo, I can't tell if the nut had come off or if it has pushed through the hole. If you remove the screws holding the light plate in place, you will discover a hole, maybe an inch or two in diameter. Hopefully, you can get a finger in there and push it back through and see which is the case. (Nut gone or pushed through.) If nut is missing, measure dia of threads and try auto oarts. You'll have to buy a switch to get the nut. It doesn't have to be the same kind of switch, just the least expensive with same diameter nut. Metal nut, not plastic.
It should have also had a weatherproof rubber cover over it. You may be able to find that at auto parts as well, but amazon would be a good source for a new weather proof switch, if you decode to go that way. Ours has been missing the rubber cover for 10 years. I have been waiting for the switch to die before I replace it. So far, so good.
Remember, only 12 volts here. No death shocks, but also don't stick a ringed finger in there or you could get a burn. Better yet, use the battery disconnect before you do it. Good luck. Nut should be similar to one of these. Sorry about long links. Broken screen limits my abilities.
https://www.bing.com/images/search?v...hist=0&first=1
OR
https://www.bing.com/images/search?v...=10&ajaxhist=0