Canada to buy pipeline to ensure it gets built