Beispiel #1
0
        public static void Serialize(Utf8JsonWriter writer, SystemAssignedIdentity systemAssignedIdentity)
        {
            if (systemAssignedIdentity == null)
            {
                throw new ArgumentNullException(nameof(systemAssignedIdentity));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.WritePropertyName("principalId");
            if (!Optional.IsDefined(systemAssignedIdentity.PrincipalId))
            {
                writer.WriteStringValue("null");
            }
            else
            {
                writer.WriteStringValue(systemAssignedIdentity.PrincipalId.ToString());
            }

            writer.WritePropertyName("tenantId");
            if (!Optional.IsDefined(systemAssignedIdentity.TenantId))
            {
                writer.WriteStringValue("null");
            }
            else
            {
                writer.WriteStringValue(systemAssignedIdentity.TenantId.ToString());
            }

            writer.Flush();
        }
Beispiel #2
0
        public bool Equals(SystemAssignedIdentity other)
        {
            if (other == null)
            {
                return(false);
            }

            return(TenantId.Equals(other.TenantId) && PrincipalId.Equals(other.PrincipalId));
        }
Beispiel #3
0
        public static bool Equals(SystemAssignedIdentity original, SystemAssignedIdentity other)
        {
            if (original == null)
            {
                return(other == null);
            }

            return(original.Equals(other));
        }
Beispiel #4
0
 public Identity(SystemAssignedIdentity systemAssigned, IDictionary <ResourceIdentifier, UserAssignedIdentity> user) // TODO: remove this constructor later
 {
     SystemAssignedIdentity = systemAssigned;
     if (user == null)
     {
         UserAssignedIdentities = new Dictionary <ResourceIdentifier, UserAssignedIdentity>();
     }
     else
     {
         UserAssignedIdentities = user;
     }
 }
Beispiel #5
0
        public int CompareTo(SystemAssignedIdentity other)
        {
            if (other == null)
            {
                return(1);
            }

            int compareResult = 0;

            if ((compareResult = TenantId.GetValueOrDefault().CompareTo(other.TenantId.GetValueOrDefault())) == 0 &&
                (compareResult = PrincipalId.GetValueOrDefault().CompareTo(other.PrincipalId.GetValueOrDefault())) == 0)
            {
                return(0);
            }

            return(compareResult);
        }
Beispiel #6
0
        /// <summary>
        /// Converts an <see cref="Identity"/> object into a <see cref="JsonElement"/>.
        /// </summary>
        /// <param name="writer"> Utf8JsonWriter object to which the output is going to be written. </param>
        /// <param name="identity"> Identity object to be converted. </param>
        public static void Serialize(Utf8JsonWriter writer, Identity identity)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }

            writer.WriteStartObject();
            writer.WritePropertyName("identity");

            if (identity.SystemAssignedIdentity == null && identity.UserAssignedIdentities.Count == 0)
            {
                writer.WriteStringValue("null");
                writer.WriteEndObject();
                writer.Flush();
                return;
            }

            writer.WriteStartObject();
            if (identity.SystemAssignedIdentity != null && identity.UserAssignedIdentities.Count != 0)
            {
                SystemAssignedIdentity.Serialize(writer, identity.SystemAssignedIdentity);
                writer.WritePropertyName("kind");
                writer.WriteStringValue(SystemAndUserAssigned);
                writer.WritePropertyName("userAssignedIdentities");
                writer.WriteStartObject();
                foreach (var keyValuePair in identity.UserAssignedIdentities)
                {
                    writer.WritePropertyName(keyValuePair.Key);
                    UserAssignedIdentity.Serialize(writer, keyValuePair.Value);
                }

                writer.WriteEndObject();
            }
            else if (identity.SystemAssignedIdentity != null)
            {
                SystemAssignedIdentity.Serialize(writer, identity.SystemAssignedIdentity);
                writer.WritePropertyName("kind");
                writer.WriteStringValue(SystemAssigned);
            }
            else if (identity.UserAssignedIdentities.Count != 0)
            {
                writer.WritePropertyName("kind");
                writer.WriteStringValue(UserAssigned);
                writer.WritePropertyName("userAssignedIdentities");
                writer.WriteStartObject();
                foreach (var keyValuePair in identity.UserAssignedIdentities)
                {
                    writer.WritePropertyName(keyValuePair.Key);
                    UserAssignedIdentity.Serialize(writer, keyValuePair.Value);
                }

                writer.WriteEndObject();
            }

            writer.WriteEndObject();
            writer.WriteEndObject();
            writer.Flush();
        }