1. Christian Specht
  2. Bitbucket Backup

Commits

Christian Specht  committed 1fd693a

build credentials right before the request is executed

(doing it in the constructor doesn't work anymore - user name and password may
not be known yet when the class is initialized on startup)

  • Participants
  • Parent commits 7879e20
  • Branches default

Comments (0)

Files changed (1)

File src/BitbucketBackup/BitbucketRequest.cs

View file
         /// Base URI for all API calls
         /// </summary>
         private Uri baseuri;
-        
-        /// <summary>
-        /// login credentials (Base64 encoded string)
-        /// </summary>
-        private string credentials;
 
         private IConfig config;
 
         public BitbucketRequest(IConfig config)
         {
             this.baseuri = new Uri("https://api.bitbucket.org/1.0/");
-            this.credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(config.UserName + ":" + config.PassWord));
             this.config = config;
         }
 
         /// <returns>Response (as JSON string)</returns>
         public string Execute(string requestUri)
         {
+
             var uri = new Uri(baseuri, requestUri);
             var request = WebRequest.Create(uri.ToString()) as HttpWebRequest;
-            request.Headers.Add("Authorization", "Basic " + this.credentials);
+            request.Headers.Add("Authorization", "Basic " + this.GetCredentials());
 
             try
             {
                 }
             }
         }
+
+        /// <summary>
+        /// convert user name and password to credentials for request
+        /// </summary>
+        /// <returns>encrypted credentials</returns>
+        private string GetCredentials()
+        {
+            return Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(this.config.UserName + ":" + this.config.PassWord));
+        }
     }
 }