public static AuthCredentials FromNodeParameters(
     EnumValueObject authType,
     StringValueObject token,
     StringValueObject userName,
     StringValueObject password)
 {
     if (authType.HasValue && authType.Value == AuthType.BasicAuth.ToString())
     {
         return(new AuthCredentials
         {
             Type = AuthType.BasicAuth,
             Username = userName.HasValue ? userName.Value : string.Empty,
             Password = password.HasValue ? password.Value : string.Empty
         });
     }
     else if (authType.HasValue && authType.Value == AuthType.BearerToken.ToString())
     {
         return(new AuthCredentials
         {
             Type = AuthType.BearerToken,
             Token = token.HasValue ? token.Value : string.Empty
         });
     }
     else
     {
         return(new AuthCredentials
         {
             Type = AuthType.NoAuth
         });
     }
 }
Exemple #2
0
 /// <summary>
 /// Find the template index that corresponds to the given output type value object
 /// </summary>
 private int getTemplateIndex(EnumValueObject outputType)
 {
     for (int i = 0; i < mOutputTypes.Count; i++)
     {
         if (mOutputTypes[i] == outputType)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemple #3
0
        public override TEnumValueObject Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var jsonString = reader.GetString();
            var result     = EnumValueObject <TEnumValueObject> .Create(jsonString);

            if (result.IsFailure)
            {
                throw new ArgumentException($"Could not transform to type {typeof(TEnumValueObject).Name} from key: {jsonString}");
            }

            return(result.Value);
        }
Exemple #4
0
        public override TEnumValueObject ReadJson(JsonReader reader, Type objectType, TEnumValueObject existingValue, bool hasExistingValue,
                                                  JsonSerializer serializer)
        {
            var key = reader.Value as string;

            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            var result = EnumValueObject <TEnumValueObject> .Create(key);

            if (result.IsFailure)
            {
                throw new ArgumentException($"Could not transform to type {typeof(TEnumValueObject).Name} from key: {key}");
            }

            return(result.Value);
        }