When required by the governing body or any officer of the first and second class municipality, the city attorney shall furnish an opinion upon any matter relating to the affairs of the municipality or the official duties of such officer; conduct the prosecution of all actions or proceedings arising out of the violation of any ordinance; and perform such other professional services incident to his office as may be required by ordinance or directed by the governing body.
SDCL 9-14-22