@@ -2,6 +2,7 @@ package main
22
33import (
44 "encoding/json"
5+ "errors"
56 "fmt"
67 "os"
78 "strings"
@@ -56,10 +57,14 @@ func main() {
5657 }
5758 fmt .Printf ("Using Code Engine API endpoint: '%s'\n " , codeEngineApiEndpoint )
5859
60+ // Set version versioning url param
61+ versionDate := "2024-05-13"
62+
5963 // Setup a Code Engine client
6064 codeEngineServiceOptions := & codeenginev2.CodeEngineV2Options {
6165 Authenticator : authenticator ,
6266 URL : codeEngineApiEndpoint ,
67+ Version : & versionDate ,
6368 }
6469 codeEngineService , err := codeenginev2 .NewCodeEngineV2UsingExternalConfig (codeEngineServiceOptions )
6570 if err != nil {
@@ -450,6 +455,56 @@ func main() {
450455 }
451456 fmt .Printf ("Created app '%s'\n " , * createdApp .Name )
452457
458+ envVarValue := "TESTVALUE"
459+ envVarType := "literal"
460+ envVarName := "TESTNAME"
461+
462+ var jobEnvVariables = []codeenginev2.EnvVarPrototype {
463+ {
464+ Value : & envVarValue ,
465+ Type : & envVarType ,
466+ Name : & envVarName ,
467+ },
468+ }
469+
470+ // Create job
471+ createJobOpts := codeEngineService .NewCreateJobOptions (
472+ * createdProject .ID ,
473+ "icr.io/codeengine/helloworld" ,
474+ "job-1" ,
475+ )
476+
477+ createJobOpts .RunEnvVariables = jobEnvVariables
478+
479+ createdJob , _ , err := codeEngineService .CreateJob (createJobOpts )
480+ if err != nil {
481+ fmt .Printf ("CreateJob error: %s\n " , err .Error ())
482+ os .Exit (1 )
483+ return
484+ }
485+ fmt .Printf ("Created job '%s'\n " , * createdJob .Name )
486+ if createdJob .ComputedEnvVariables != nil {
487+ fmt .Printf ("Created job contains 'ComputedEnvVariables\n " )
488+ for _ , envVar := range createdJob .ComputedEnvVariables {
489+ fmt .Println (* envVar .Name + ":" + * envVar .Value )
490+ }
491+ } else {
492+ err := errors .New ("no computed environment variables found" )
493+ fmt .Printf ("CreateJob error: %s\n " , err .Error ())
494+ os .Exit (1 )
495+ return
496+ }
497+
498+ if createdJob .RunEnvVariables != nil {
499+ fmt .Printf ("Created job contains 'RunEnvVariables\n " )
500+ fmt .Println (* createdJob .RunEnvVariables [0 ].Name + " " + * createdJob .RunEnvVariables [0 ].Value )
501+ } else {
502+ err := errors .New ("no run environment variables found" )
503+ fmt .Printf ("CreateJob error: %s\n " , err .Error ())
504+ os .Exit (1 )
505+ return
506+ }
507+
453508 // Create tls secret
454509 createTLSSecretOpts := codeEngineService .NewCreateSecretOptions (
455510 * createdProject .ID ,
@@ -738,6 +793,41 @@ func main() {
738793 * createdProject .ID ,
739794 )
740795
796+ // Get job
797+ getJobOpts := codeEngineService .NewGetJobOptions (
798+ * createdProject .ID ,
799+ "job-1" ,
800+ )
801+
802+ obtainedJob , _ , err := codeEngineService .GetJob (getJobOpts )
803+ if err != nil {
804+ fmt .Printf ("GetJob error: %s\n " , err .Error ())
805+ os .Exit (1 )
806+ return
807+ }
808+ fmt .Printf ("Obtained job '%s'\n " , * obtainedJob .Name )
809+ if obtainedJob .ComputedEnvVariables != nil {
810+ fmt .Printf ("Obtained job contains 'ComputedEnvVariables\n " )
811+ for _ , envVar := range obtainedJob .ComputedEnvVariables {
812+ fmt .Println (* envVar .Name + ":" + * envVar .Value )
813+ }
814+ } else {
815+ err := errors .New ("no computed environment variables found" )
816+ fmt .Printf ("GetJob error: %s\n " , err .Error ())
817+ os .Exit (1 )
818+ return
819+ }
820+
821+ if obtainedJob .RunEnvVariables != nil {
822+ fmt .Printf ("Obtained job contains 'RunEnvVariables\n " )
823+ fmt .Println (* obtainedJob .RunEnvVariables [0 ].Name + " " + * obtainedJob .RunEnvVariables [0 ].Value )
824+ } else {
825+ err := errors .New ("no run environment variables found" )
826+ fmt .Printf ("Getjob error: %s\n " , err .Error ())
827+ os .Exit (1 )
828+ return
829+ }
830+
741831 resp , err = codeEngineService .DeleteProject (deleteProjectOptions )
742832 if err != nil {
743833 fmt .Printf ("DeleteProject error: %s (transaction-id: '%s')\n " , err .Error (), resp .Headers .Get ("X-Transaction-Id" ))
0 commit comments