public string GetCredentialPassword()
 {
     ExceptionFactory.CheckArgumentIsNullOrEmpty(_local_logger, ComputeResource.Credential.password);
     ExceptionFactory.CheckArgumentIsNullOrEmpty(_local_logger, ComputeResource.Credential.seckey);
     ExceptionFactory.CheckArgumentIsNullOrEmpty(_local_logger, TerodoViewSettings.organization_encryption_key);
     byte[] data1 = Convert.FromBase64String(ComputeResource.Credential.password);
     return(new CryptLib().decrypt(data1, ComputeResource.Credential.seckey, TerodoViewSettings.organization_encryption_key));
 }
Exemple #2
0
 public TerodoViewApiClient(string _organization_id, string _username, string _password, string _ce_id = null)
 {
     TerodoViewApiBase.OrganizationID = ExceptionFactory.CheckArgumentIsNullOrEmpty(_organization_id);
     TerodoViewApiBase.Username       = ExceptionFactory.CheckArgumentIsNullOrEmpty(_username);
     TerodoViewApiBase.Password       = ExceptionFactory.CheckArgumentIsNullOrEmpty(_password);
     TerodoViewApiBase.CeId           = _ce_id;
     _token_object        = new TerodoViewApiToken();
     _organization_object = new TerodoViewOrganization();
 }
        public async Task <string> GetContactibleIPAsync(bool literal = false)
        {
            if (!String.IsNullOrEmpty(ComputeResource.Knownaddress))
            {
                return(ComputeResource.Knownaddress);
            }
            else
            {
                ExceptionFactory.CheckArgumentIsNullOrEmpty(_local_logger, ComputeResource.Addresslist);
                try
                {
                    foreach (string ip in ComputeResource.Addresslist.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        PingReply _test_ping_reply = null;
                        Ping      _test_ping       = new Ping();

                        int retry = 3;
                        while (retry-- > 0)
                        {
                            try
                            {
                                var         buffer  = new byte[32];
                                PingOptions options = new PingOptions(32, true);
                                _test_ping_reply = _test_ping.Send(ip, TerodoViewSettings.ping_timeout, buffer, options);
                                if (_test_ping_reply?.Status == IPStatus.Success)
                                {
                                    _contatible_ip = ip;
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(String.Format("Error during ping attempt : {0}", ex.GetBaseException().Message));
                            }
                        }
                        if (_test_ping_reply?.Status == IPStatus.Success)
                        {
                            break;
                        }
                    }
                    if (literal == true)
                    {
                        IPAddress _check_ip;
                        if (IPAddress.TryParse(_contatible_ip, out _check_ip))
                        {
                            if (_check_ip.AddressFamily.ToString() == AddressFamily.InterNetworkV6.ToString())
                            {
                                String _workingip = _contatible_ip;
                                _contatible_ip = _workingip.Replace(":", "-").Replace("%", "s") + ".ipv6-literal.net";
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"Unknown error trying to contact workload : {ex.GetBaseException().Message}");
                }
                finally
                {
                    if (_contatible_ip == null)
                    {
                        throw new Exception($"Does not respond to ping after 3 attempts : {ComputeResource.Addresslist}");
                    }
                }
                await TerodoViewServiceBase.TeredoViewApi.Organization.ComputeResource.UpdateKnownAddress(ComputeResource, _contatible_ip);

                return(_contatible_ip);
            }
        }
 public string GetCredentialUsername()
 {
     ExceptionFactory.CheckArgumentIsNullOrEmpty(_local_logger, ComputeResource.Credential.username);
     return(ComputeResource.Credential.username);
 }