diff --git a/API.md b/API.md
index 2453293..62cbd37 100644
--- a/API.md
+++ b/API.md
@@ -64,4 +64,12 @@ curl -X POST
--form "file1=@my.vsix"
--form "file1=@your.vsix"
http://VSGALLERY_SERVER:5100/api/upload
+```
+
+To upload a file to the gallery server that requires an upload key
+
+```
+curl -X POST
+ --form "file=@my.vsix;filename=renamed.vsix"
+ http://VSGALLERY_SERVER:5100/api/upload/API_KEY
```
\ No newline at end of file
diff --git a/SETUP IIS.md b/SETUP IIS.md
index c1c25b7..b023877 100644
--- a/SETUP IIS.md
+++ b/SETUP IIS.md
@@ -83,6 +83,14 @@ The Gallery Settings like Storage location and some Gallery Configuration can be
the `~` in the derectory configuration means Web Application root directory.
+To require a key to upload packages set the `UploadKey` for the gallery
+
+```
+
+
+
+
+```
The default local physical structure
`.vsix` files, along with their download counts and ratings data are stored in a subfolder of the main service executable `VsixStorage/` (this subfolder is configurable). This makes taking backups and moving the service between machines super easy as the root folder contains the entire Microservice state and data.
diff --git a/VsGallery.Core/IConfiguration.cs b/VsGallery.Core/IConfiguration.cs
index 4b71558..ade9e38 100644
--- a/VsGallery.Core/IConfiguration.cs
+++ b/VsGallery.Core/IConfiguration.cs
@@ -15,5 +15,6 @@ public interface IGalleryConfiguration
string Description { get; }
bool TrackDownloads { get; }
bool TrackRatings { get; }
+ string UploadKey { get; }
}
}
diff --git a/VsGallery.WebService/Configuration.cs b/VsGallery.WebService/Configuration.cs
index 6c648cc..9cbccee 100644
--- a/VsGallery.WebService/Configuration.cs
+++ b/VsGallery.WebService/Configuration.cs
@@ -132,6 +132,20 @@ public bool TrackRatings
this[trackRatingsPropertyName] = value;
}
}
+
+ const string uploadKeyPropertyName = "UploadKey";
+ [ConfigurationProperty(uploadKeyPropertyName, DefaultValue = "", IsRequired = false)]
+ public string UploadKey
+ {
+ get
+ {
+ return this[uploadKeyPropertyName] as string;
+ }
+ set
+ {
+ this[uploadKeyPropertyName] = value;
+ }
+ }
}
public class Configuration : ConfigurationSection, IConfiguration
diff --git a/VsGallery.WebService/Controllers/UploadController.cs b/VsGallery.WebService/Controllers/UploadController.cs
index e2aa07f..086b5d3 100644
--- a/VsGallery.WebService/Controllers/UploadController.cs
+++ b/VsGallery.WebService/Controllers/UploadController.cs
@@ -13,11 +13,13 @@ namespace VsGallery.WebService.Controllers
{
public class UploadController : ApiController
{
- private IStorageConfiguration _configuration;
+ private IStorageConfiguration _storage;
+ private IGalleryConfiguration _gallery;
public UploadController()
{
- _configuration = WebService.Configuration.Instance.Storage;
+ _storage = WebService.Configuration.Instance.Storage;
+ _gallery = WebService.Configuration.Instance.Gallery;
}
@@ -26,8 +28,12 @@ public UploadController()
///
[HttpPost]
[HttpPut]
- public IHttpActionResult AddOrUpdateVsix()
+ [Route("api/upload/{*key}")]
+ public IHttpActionResult AddOrUpdateVsix(string key)
{
+ if (!string.IsNullOrEmpty(_gallery.UploadKey) && key != _gallery.UploadKey)
+ return BadRequest("Invalid Key");
+
// Get the uploaded image from the Files collection
var requestFiles = HttpContext.Current.Request.Files;
var httpFiles = Enumerable.Range(0, requestFiles.Count).Select(i => requestFiles[i]).ToList();
@@ -43,13 +49,13 @@ public IHttpActionResult AddOrUpdateVsix()
// Get the complete file path
foreach(var httpFile in httpFiles)
{
- var fileSavePath = Path.Combine(_configuration.UploadDirectory, httpFile.FileName);
+ var fileSavePath = Path.Combine(_storage.UploadDirectory, httpFile.FileName);
// Save the uploaded file to "UploadedFiles" folder
httpFile.SaveAs(fileSavePath);
// Now move all the files uploaded to the main storage directory
- File.Move(fileSavePath, Path.Combine(_configuration.VsixStorageDirectory, httpFile.FileName));
+ File.Move(fileSavePath, Path.Combine(_storage.VsixStorageDirectory, httpFile.FileName));
}
return Ok();
diff --git a/VsGallery.WebService/Web.config b/VsGallery.WebService/Web.config
index 508f2af..3c126ff 100644
--- a/VsGallery.WebService/Web.config
+++ b/VsGallery.WebService/Web.config
@@ -12,6 +12,7 @@
+
diff --git a/vsgallery/Configuration.cs b/vsgallery/Configuration.cs
index 59ee5c7..b5a559b 100644
--- a/vsgallery/Configuration.cs
+++ b/vsgallery/Configuration.cs
@@ -82,6 +82,7 @@ public GalleryConfiguration(KeyDataCollection data) : base(data){}
public string Description => Get(nameof(Description));
public bool TrackDownloads => Get(nameof(TrackDownloads));
public bool TrackRatings => Get(nameof(TrackRatings));
+ public string UploadKey => Get(nameof(UploadKey));
}