Esempio n. 1
0
        private static async Task <Platform> LoadInstanceAsync()
        {
            // The order matters here:
            // * GAE runs on GCE, so do GAE before GCE.
            // * GKE runs on GCE, so do GKE before GCE.
            // * Cloud Run runs on GCE, so do Cloud Run before GCE.
            // * Metadata server access can take time, so do GAE first.
            GaePlatformDetails gaeDetails = LoadGaeDetails();

            if (gaeDetails != null)
            {
                return(new Platform(gaeDetails));
            }
            var metadataJson = await LoadMetadataAsync().ConfigureAwait(false);

            if (metadataJson != null)
            {
                var kubernetesData = await GkePlatformDetails.LoadKubernetesDataAsync().ConfigureAwait(false);

                if (kubernetesData != null)
                {
                    GkePlatformDetails gkeDetails = GkePlatformDetails.TryLoad(metadataJson, kubernetesData);
                    if (gkeDetails != null)
                    {
                        return(new Platform(gkeDetails));
                    }
                }
                CloudRunPlatformDetails cloudRunDetails = CloudRunPlatformDetails.TryLoad(metadataJson);
                if (cloudRunDetails != null)
                {
                    return(new Platform(cloudRunDetails));
                }
                GcePlatformDetails gceDetails = GcePlatformDetails.TryLoad(metadataJson);
                if (gceDetails != null)
                {
                    return(new Platform(gceDetails));
                }
            }
            return(new Platform());
        }
Esempio n. 2
0
 /// <summary>
 /// Construct with details of Google Cloud Run.
 /// </summary>
 /// <param name="cloudRunDetails">Details of Google Cloud Run.</param>
 public Platform(CloudRunPlatformDetails cloudRunDetails)
 {
     CloudRunDetails = GaxPreconditions.CheckNotNull(cloudRunDetails, nameof(cloudRunDetails));
 }