private static ParsedCloudId ParseCloudId()

in src/Elastic.Transport/Components/NodePool/CloudNodePool.cs [64:93]


	private static ParsedCloudId ParseCloudId(string cloudId)
	{
		const string exceptionSuffix = "should be a string in the form of cluster_name:base_64_data";
		if (string.IsNullOrWhiteSpace(cloudId))
			throw new ArgumentException($"Parameter {nameof(cloudId)} was null or empty but {exceptionSuffix}", nameof(cloudId));

		var tokens = cloudId.Split(new[] { ':' }, 2);
		if (tokens.Length != 2)
			throw new ArgumentException($"Parameter {nameof(cloudId)} not in expected format, {exceptionSuffix}", nameof(cloudId));

		var clusterName = tokens[0];
		var encoded = tokens[1];
		if (string.IsNullOrWhiteSpace(encoded))
			throw new ArgumentException($"Parameter {nameof(cloudId)} base_64_data is empty, {exceptionSuffix}", nameof(cloudId));

		var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(encoded));
		var parts = decoded.Split(new[] { '$' });
		if (parts.Length < 2)
			throw new ArgumentException($"Parameter {nameof(cloudId)} decoded base_64_data contains less then 2 tokens, {exceptionSuffix}", nameof(cloudId));

		var domainName = parts[0].Trim();
		if (string.IsNullOrWhiteSpace(domainName))
			throw new ArgumentException($"Parameter {nameof(cloudId)} decoded base_64_data contains no domain name, {exceptionSuffix}", nameof(cloudId));

		var elasticsearchUuid = parts[1].Trim();
		if (string.IsNullOrWhiteSpace(elasticsearchUuid))
			throw new ArgumentException($"Parameter {nameof(cloudId)} decoded base_64_data contains no elasticsearch UUID, {exceptionSuffix}", nameof(cloudId));

		return new ParsedCloudId(clusterName, new Uri($"https://{elasticsearchUuid}.{domainName}"));
	}