@@ -710,7 +710,19 @@ def set_definition(self, env):
710710 """
711711 return self .client ._perform_json (
712712 "PUT" , "/admin/code-envs/%s/%s" % (self .env_lang , self .env_name ), body = env )
713-
713+
714+ def get_version_for_project (self , project_key ):
715+ """
716+ Resolve the code env version for a given project
717+
718+ Note: version will only be non-empty for versioned code envs actually used by the project
719+
720+ :returns: the code env reference, with a version field
721+ """
722+ return self .client ._perform_json (
723+ "GET" , "/admin/code-envs/%s/%s/%s/version" % (self .env_lang , self .env_name , project_key ))
724+
725+
714726 ########################################################
715727 # Code env actions
716728 ########################################################
@@ -747,6 +759,52 @@ def update_packages(self, force_rebuild_env=False):
747759 raise Exception ('Env update failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
748760 return resp
749761
762+ def update_images (self , env_version = None ):
763+ """
764+ Rebuild the docker image of the code env
765+
766+ Note: this call requires an API key with admin rights
767+ """
768+ resp = self .client ._perform_json (
769+ "POST" , "/admin/code-envs/%s/%s/images" % (self .env_lang , self .env_name ),
770+ params = {"envVersion" : env_version })
771+ if resp is None :
772+ raise Exception ('Env image build returned no data' )
773+ if resp .get ('messages' , {}).get ('error' , False ):
774+ raise Exception ('Env image build failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
775+ return resp
776+
777+ def list_usages (self , env_version = None ):
778+ """
779+ List usages of the code env in the instance
780+
781+ :return: a list of objects where the code env is used
782+ """
783+ return self .client ._perform_json (
784+ "GET" , "/admin/code-envs/%s/%s/usages" % (self .env_lang , self .env_name ), params = {"envVersion" : env_version })
785+
786+ def list_logs (self , env_version = None ):
787+ """
788+ List logs of the code env in the instance
789+
790+ :return: a list of log descriptions
791+ """
792+ return self .client ._perform_json (
793+ "GET" , "/admin/code-envs/%s/%s/logs" % (self .env_lang , self .env_name ), params = {"envVersion" : env_version })
794+
795+ def get_log (self , log_name ):
796+ """
797+ Get the logs of the code env
798+
799+ Args:
800+ log_name: name of the log to fetch
801+
802+ Returns:
803+ the log, as a string
804+ """
805+ return self .client ._perform_text (
806+ "GET" , "/admin/code-envs/%s/%s/logs/%s" % (self .env_lang , self .env_name , log_name ))
807+
750808
751809class DSSGlobalApiKey (object ):
752810 """
0 commit comments