Canada's prime minister has used Trump's attacks on allies and others to refocus Ottawa's foreign policy.