Exemplo n.º 1
0
        internal static DatastoreSecrets DeserializeDatastoreSecrets(JsonElement element)
        {
            if (element.TryGetProperty("secretsType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Certificate": return(CertificateDatastoreSecrets.DeserializeCertificateDatastoreSecrets(element));

                case "KerberosKeytab": return(KerberosKeytabSecrets.DeserializeKerberosKeytabSecrets(element));

                case "KerberosPassword": return(KerberosPasswordSecrets.DeserializeKerberosPasswordSecrets(element));

                case "Sas": return(SasDatastoreSecrets.DeserializeSasDatastoreSecrets(element));

                case "ServicePrincipal": return(ServicePrincipalDatastoreSecrets.DeserializeServicePrincipalDatastoreSecrets(element));

                case "AccountKey": return(AccountKeyDatastoreSecrets.DeserializeAccountKeyDatastoreSecrets(element));
                }
            }
            SecretsType secretsType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("secretsType"))
                {
                    secretsType = new SecretsType(property.Value.GetString());
                    continue;
                }
            }
            return(new DatastoreSecrets(secretsType));
        }
Exemplo n.º 2
0
        internal static ServicePrincipalDatastoreCredentials DeserializeServicePrincipalDatastoreCredentials(JsonElement element)
        {
            Optional <Uri> authorityUrl = default;
            Guid           clientId     = default;
            Optional <Uri> resourceUrl  = default;
            ServicePrincipalDatastoreSecrets secrets = default;
            Guid            tenantId        = default;
            CredentialsType credentialsType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("authorityUrl"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        authorityUrl = null;
                        continue;
                    }
                    authorityUrl = new Uri(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("clientId"))
                {
                    clientId = property.Value.GetGuid();
                    continue;
                }
                if (property.NameEquals("resourceUrl"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        resourceUrl = null;
                        continue;
                    }
                    resourceUrl = new Uri(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("secrets"))
                {
                    secrets = ServicePrincipalDatastoreSecrets.DeserializeServicePrincipalDatastoreSecrets(property.Value);
                    continue;
                }
                if (property.NameEquals("tenantId"))
                {
                    tenantId = property.Value.GetGuid();
                    continue;
                }
                if (property.NameEquals("credentialsType"))
                {
                    credentialsType = new CredentialsType(property.Value.GetString());
                    continue;
                }
            }
            return(new ServicePrincipalDatastoreCredentials(credentialsType, authorityUrl.Value, clientId, resourceUrl.Value, secrets, tenantId));
        }