All depends on the setup. Some use floating caliper, some use floating disc. Given that the disc does not appear to have set screws, (though perhaps they're on the other side), I would say cut the key shorter (about 1/4" longer than the hub is thick) and put a lock collar on both sides. That will capture the key and hold it in place, and still allow the disc to float and compensate for pad wear.
If the disc does have set screws and the caliper floats, do as suggested before. Cut the key to exact length, and add lock collars to hold everything right in place.