func updateWorkflowClientsIfneeded()

in cli_tools/common/utils/daisyutils/workflow_hook_workflow_properties.go [53:96]


func updateWorkflowClientsIfneeded(env EnvironmentSettings, wf *daisy.Workflow) error {

	// Create new context here as daisy clients shouldn't die if the main context is cancelled.
	// It will need to cleaned up resources before terminating the clients.
	ctx := context.Background()

	if env.EndpointsOverride.Compute != "" {
		daisyComputeClient, err := param.CreateComputeClient(&ctx, env.OAuth, env.EndpointsOverride.Compute)
		if err != nil {
			return err
		}
		wf.ComputeClient = daisyComputeClient
	}

	if env.EndpointsOverride.Storage != "" {
		storageOptions := []option.ClientOption{option.WithEndpoint(env.EndpointsOverride.Storage)}
		if env.OAuth != "" {
			storageOptions = append(storageOptions, option.WithCredentialsFile(env.OAuth))
		}

		storageClient, err := storage.NewClient(ctx, storageOptions...)
		if err != nil {
			return err
		}

		wf.StorageClient = storageClient
	}

	if env.EndpointsOverride.CloudLogging != "" {
		cloudLoggingOptions := []option.ClientOption{option.WithEndpoint(env.EndpointsOverride.CloudLogging)}
		if env.OAuth != "" {
			cloudLoggingOptions = append(cloudLoggingOptions, option.WithCredentialsFile(env.OAuth))
		}

		cloudLoggingClient, err := logging.NewClient(ctx, wf.Project, cloudLoggingOptions...)
		if err != nil {
			return err
		}

		wf.CloudLoggingClient = cloudLoggingClient
	}

	return nil
}