Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchitmehta committed Aug 19, 2019
2 parents 40a9909 + 1bb7575 commit f2d8346
Show file tree
Hide file tree
Showing 74 changed files with 2,899 additions and 176 deletions.
26 changes: 25 additions & 1 deletion Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ namespace Kudu
{
public static class Constants
{
//Scan functionality files
public const string ScanLockFile = "scan.lock";
public static string ScanStatusFile = "status.json";
public static string ScanLogFile = "scan_log.log";
public static string ScanFolderName = "Scan_";
public static string MaxScans = "2";
public static string ScanDir = "/home/site/wwwroot";
public static string ScriptPath = "/custom_scripts/daily_scan_script.sh";
public static string ScanCommand = ScriptPath+" "+ScanDir;
public static string ScanTimeOutMillSec = "1200000"; // 20 mins
public static string ScanManifest = "modified_times.json";
public static string AggregrateScanResults = "aggregrate_scans.log";
public static string TempScanFile = "temp_scan_monitor";

public const string WebRoot = "wwwroot";
public const string MappedSite = "/_app";
public const string RepositoryPath = "repository";
Expand Down Expand Up @@ -105,6 +119,8 @@ public static TimeSpan MaxAllowedExecutionTime
public const string SiteAuthEncryptionKey = "WEBSITE_AUTH_ENCRYPTION_KEY";
public const string HttpHost = "HTTP_HOST";
public const string WebSiteSwapSlotName = "WEBSITE_SWAP_SLOTNAME";
public const string AzureWebsiteInstanceId = "WEBSITE_INSTANCE_ID";
public const string ContainerName = "CONTAINER_NAME";

public const string Function = "function";
public const string Functions = "functions";
Expand All @@ -116,6 +132,7 @@ public static TimeSpan MaxAllowedExecutionTime
public const string FunctionsPortal = "FunctionsPortal";
public const string FunctionKeyNewFormat = "~0.7";
public const string FunctionRunTimeVersion = "FUNCTIONS_EXTENSION_VERSION";
public const string ScmRunFromPackage = "SCM_RUN_FROM_PACKAGE";
public const string WebSiteSku = "WEBSITE_SKU";
public const string WebSiteElasticScaleEnabled = "WEBSITE_ELASTIC_SCALING_ENABLED";
public const string DynamicSku = "Dynamic";
Expand All @@ -129,5 +146,12 @@ public static TimeSpan MaxAllowedExecutionTime
public const string SitePackages = "SitePackages";
public const string PackageNameTxt = "packagename.txt";
public const string KuduBuild = "1.0.0.6";

public const string WebSSHReverseProxyPortEnvVar = "KUDU_WEBSSH_PORT";
public const string WebSSHReverseProxyDefaultPort = "3000";

public const string LinuxLogEventStreamName = "MS_KUDU_LOGS";
public const string WebSiteHomeStampName = "WEBSITE_HOME_STAMPNAME";
public const string WebSiteStampDeploymentId = "WEBSITE_STAMP_DEPLOYMENT_ID";
}
}
}
1 change: 1 addition & 0 deletions Kudu.Contracts/IEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ public interface IEnvironment
string RequestId { get; } // e.g. x-arr-log-id or x-ms-request-id header value
string KuduConsoleFullPath { get; } // e.g. KuduConsole/kudu.dll
string SitePackagesPath { get; } // e.g. /data/SitePackages
bool IsOnLinuxConsumption { get; } // e.g. True on Linux Consumption. False on App Service.
}
}
29 changes: 29 additions & 0 deletions Kudu.Contracts/Scan/IScanManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Kudu.Contracts.Scan
{
public interface IScanManager
{
Task<ScanRequestResult> StartScan(
String timeout,
String mainScanDirPath,
String id,
String host,
Boolean checkModified);

Task<ScanStatusResult> GetScanStatus(
String scanId,
String mainScanDirPath);

Task<ScanReport> GetScanResultFile(
String scanId,
String mainScanDirPath);

IEnumerable<ScanOverviewResult> GetResults(String mainScanDir);

void StopScan(String mainScanDirPath);
}
}

22 changes: 22 additions & 0 deletions Kudu.Contracts/Scan/InfectedFileObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Kudu.Contracts.Scan
{
public class InfectedFileObject
{
[JsonProperty(PropertyName = "name")]
public String Name { get; set; }

[JsonProperty(PropertyName = "threat_detected")]
public String ThreatDetected { get; set; }

public InfectedFileObject(string name, string threat)
{
this.Name = name;
this.ThreatDetected = threat;
}
}
}
25 changes: 25 additions & 0 deletions Kudu.Contracts/Scan/ScanDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Kudu.Contracts.Scan
{
public class ScanDetail
{
[JsonProperty(PropertyName = "total_scanned")]
public String TotalScanned { get; set; }

[JsonProperty(PropertyName = "total_infected")]
public String TotalInfected { get; set; }

[JsonProperty(PropertyName = "time_taken")]
public String TimeTaken { get; set; }

[JsonProperty(PropertyName = "safe_files")]
public List<String> SafeFiles { get; set; }

[JsonProperty(PropertyName = "infected_files")]
public List<InfectedFileObject> InfectedFiles { get; set; }
}
}
24 changes: 24 additions & 0 deletions Kudu.Contracts/Scan/ScanOverviewResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Kudu.Contracts.Scan
{

public class ScanOverviewResult : INamedObject
{
[JsonProperty(PropertyName = "status_info")]
public ScanStatusResult Status { get; set; }

[JsonProperty(PropertyName = "scan_results_url")]
public String ScanResultsUrl { get; set; }

/* [JsonIgnore]
public DateTime ReceivedTime { get; set; }*/

[JsonIgnore]
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "to provide ARM spceific name")]
string INamedObject.Name { get { return Status.Id; } }
}
}
23 changes: 23 additions & 0 deletions Kudu.Contracts/Scan/ScanReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Kudu.Contracts.Scan
{
public class ScanReport : INamedObject
{
[JsonProperty(PropertyName = "report")]
public ScanDetail Report { get; set; }

[JsonIgnore]
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "to provide ARM spceific name")]
string INamedObject.Name { get { return Id; } }

[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }

[JsonIgnore]
public String Id { get; set; }
}
}
12 changes: 12 additions & 0 deletions Kudu.Contracts/Scan/ScanRequestResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Kudu.Contracts.Scan
{
public enum ScanRequestResult
{
RunningAynschronously,
RanSynchronously,
Pending,
AsyncScanFailed,
NoFileModifications,
ScanAlreadyInProgress
}
}
12 changes: 12 additions & 0 deletions Kudu.Contracts/Scan/ScanStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Kudu.Contracts.Scan
{
public enum ScanStatus
{
Starting,
Executing,
Failed,
TimeoutFailure,
Success,
ForceStopped
}
}
21 changes: 21 additions & 0 deletions Kudu.Contracts/Scan/ScanStatusResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Diagnostics.CodeAnalysis;

namespace Kudu.Contracts.Scan
{
public class ScanStatusResult : INamedObject
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

[JsonProperty(PropertyName = "status")]
[JsonConverter(typeof(StringEnumConverter))]
public ScanStatus Status { get; set; }

[JsonIgnore]
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "to provide ARM spceific name")]
string INamedObject.Name { get { return Id; } }
}
}
34 changes: 34 additions & 0 deletions Kudu.Contracts/Scan/ScanUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Kudu.Contracts.Scan
{
public class ScanUrl : INamedObject
{
[JsonProperty(PropertyName = "track_url")]
public String TrackingURL { get; set; }

[JsonProperty(PropertyName = "result_url")]
public String ResultURL { get; set; }

[JsonIgnore]
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "to provide ARM spceific name")]
string INamedObject.Name { get { return Id; } }

[JsonProperty(PropertyName = "id")]
public String Id { get; set; }

[JsonProperty(PropertyName = "message")]
public String Message { get; set; }

public ScanUrl(string trackingURL, string resultURL, string id, string msg)
{
TrackingURL = trackingURL;
ResultURL = resultURL;
Id = id;
Message = msg;
}
}
}
1 change: 1 addition & 0 deletions Kudu.Contracts/Settings/SettingsKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static class SettingsKeys
// Antares container specific settings
public const string PlaceholderMode = "WEBSITE_PLACEHOLDER_MODE";
public const string ContainerReady = "WEBSITE_CONTAINER_READY";
public const string WebsiteHostname = "WEBSITE_HOSTNAME";
public const string AuthEncryptionKey = "WEBSITE_AUTH_ENCRYPTION_KEY";
public const string ContainerEncryptionKey = "CONTAINER_ENCRYPTION_KEY";
}
Expand Down
23 changes: 21 additions & 2 deletions Kudu.Core/AllSafeLinuxLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class AllSafeLinuxLock :IOperationLock
private ITraceFactory _traceFactory;
private static readonly string locksPath = "/home/site/locks";
private const int lockTimeout = 1200; //in seconds
private string defaultMsg = Resources.DeploymentLockOccMsg;
private string Msg;
public AllSafeLinuxLock(string path, ITraceFactory traceFactory)
{
_traceFactory = traceFactory;
Expand Down Expand Up @@ -103,7 +105,7 @@ private static void CreateLockInfoFile(string operationName)
var lockInfo = new LinuxLockInfo();
lockInfo.heldByPID = Process.GetCurrentProcess().Id;
lockInfo.heldByTID = Thread.CurrentThread.ManagedThreadId;
lockInfo.heldByWorker = System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
lockInfo.heldByWorker = System.Environment.GetEnvironmentVariable(Constants.AzureWebsiteInstanceId);
lockInfo.heldByOp = operationName;
lockInfo.lockExpiry = DateTime.UtcNow.AddSeconds(lockTimeout);
//Console.WriteLine("CreatingLockDir - LockInfoObj : "+lockInfo);
Expand Down Expand Up @@ -157,7 +159,24 @@ public void Release()
Console.WriteLine("ReleasingLock - There is NO LOCK HELD | ERROR");
}
}


public string GetLockMsg()
{
//throw new NotImplementedException();
if(Msg == null || "".Equals(Msg))
{
return defaultMsg;
}

return Msg;
}

public void SetLockMsg(string msg)
{
this.Msg = msg;

}

private class LinuxLockInfo
{
public DateTime lockExpiry;
Expand Down
10 changes: 6 additions & 4 deletions Kudu.Core/Deployment/DeploymentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using Kudu.Contracts.Tracing;
using Kudu.Core.Deployment.Oryx;
using Kudu.Core.Infrastructure;
using Kudu.Core.SourceControl;
using Kudu.Core.Tracing;
Expand Down Expand Up @@ -52,13 +53,14 @@ public static bool IsDefaultWebRootContent(string webroot)
return false;
}

public static void PurgeZipsIfNecessary(string sitePackagesPath, ITracer tracer, int totalAllowedZips)
public static void PurgeBuildArtifactsIfNecessary(string sitePackagesPath, BuildArtifactType fileExtension, ITracer tracer, int totalAllowedFiles)
{
IEnumerable<string> zipFiles = FileSystemHelpers.GetFiles(sitePackagesPath, "*.zip");
if (zipFiles.Count() > totalAllowedZips)
string extension = fileExtension.ToString().ToLowerInvariant();
IEnumerable<string> fileNames = FileSystemHelpers.GetFiles(sitePackagesPath, $"*.{extension}");
if (fileNames.Count() > totalAllowedFiles)
{
// Order the files in descending order of the modified date and remove the last (N - allowed zip files).
var fileNamesToDelete = zipFiles.OrderByDescending(fileName => FileSystemHelpers.GetLastWriteTimeUtc(fileName)).Skip(totalAllowedZips);
var fileNamesToDelete = fileNames.OrderByDescending(fileName => FileSystemHelpers.GetLastWriteTimeUtc(fileName)).Skip(totalAllowedFiles);
foreach (var fileName in fileNamesToDelete)
{
using (tracer.Step("Deleting outdated zip file {0}", fileName))
Expand Down
1 change: 1 addition & 0 deletions Kudu.Core/Deployment/Generator/ExternalCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Kudu.Core.Deployment.Generator
//
// ExternalCommandBuilder
// CustomBuilder
// OryxBuilder
// GeneratorSiteBuilder
// BaseBasicBuilder
// BasicBuilder
Expand Down
Loading

0 comments on commit f2d8346

Please sign in to comment.