internal static GooglePubSubAttribute GetAttributeByConfiguration(GooglePubSubAttribute googlePubSubAttribute) { if (string.IsNullOrWhiteSpace(googlePubSubAttribute.ConfigurationNodeName)) { return(googlePubSubAttribute); } var credentialsString = System.Environment.GetEnvironmentVariable($"{googlePubSubAttribute.ConfigurationNodeName}.Credentials", System.EnvironmentVariableTarget.Process); var credentialsFileName = System.Environment.GetEnvironmentVariable($"{googlePubSubAttribute.ConfigurationNodeName}.CredentialsFileName", System.EnvironmentVariableTarget.Process); var projectId = System.Environment.GetEnvironmentVariable($"{googlePubSubAttribute.ConfigurationNodeName}.ProjectId", System.EnvironmentVariableTarget.Process); var topicId = System.Environment.GetEnvironmentVariable($"{googlePubSubAttribute.ConfigurationNodeName}.TopicId", System.EnvironmentVariableTarget.Process); if (string.IsNullOrWhiteSpace(credentialsString) && string.IsNullOrEmpty(credentialsFileName)) { return(new GooglePubSubAttribute(projectId, topicId)); } else { if (string.IsNullOrWhiteSpace(credentialsString)) { return(new GooglePubSubAttribute(credentialsFileName, projectId, topicId)); } else { var credentials = System.Text.Encoding.UTF8.GetBytes(credentialsString); return(new GooglePubSubAttribute(credentials, projectId, topicId)); } } }
public AsyncCollector(GooglePubSubAttribute googlePubSubAttribute, Microsoft.Extensions.Logging.ILogger logger) { this.googlePubSubAttribute = GooglePubSubAttribute.GetAttributeByConfiguration(googlePubSubAttribute); this.logger = logger; }
internal static TransparentApiClient.Google.PubSub.V1.Resources.Topics GetTopicsClient(GooglePubSubAttribute googlePubSubAttribute) { var key = googlePubSubAttribute.GetHashCode(); if (publisherClientV2Cache.ContainsKey(key)) { return(publisherClientV2Cache[key]); } else { var credentials = CreatorService.GetCredentials(googlePubSubAttribute); var publisherClient = new TransparentApiClient.Google.PubSub.V1.Resources.Topics(credentials); publisherClientV2Cache.AddOrUpdate(key, publisherClient, (newkey, oldValue) => publisherClient); return(publisherClient); } }