Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackagerUtils"/> class.
 /// </summary>
 /// <param name="pathResolver">The path resolver.</param>
 /// <param name="logger">Logging interface.</param>
 /// <param name="s3Util">S3 utility to use for pushing packaged objects.</param>
 /// <param name="platform">The operating system platform</param>
 // ReSharper disable once StyleCop.SA1305
 public PackagerUtils(IPathResolver pathResolver, ILogger logger, IPSS3Util s3Util, IOSInfo platform)
 {
     this.platform     = platform;
     this.s3Util       = s3Util;
     this.logger       = logger;
     this.pathResolver = pathResolver;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PythonVirtualEnv"/> class.
        /// </summary>
        /// <param name="platform">Abstraction of platform the module is running on (for unit tests).</param>
        /// <exception cref="PackagerException">Cannot find VIRTUAL_ENV environment variable. Activate your virtual env first, then run.</exception>
        public PythonVirtualEnv(IOSInfo platform)
        {
            this.platform = platform;
            if (string.IsNullOrEmpty(this.VirtualEnvDir))
            {
                throw new PackagerException(
                          "Cannot find VIRTUAL_ENV environment variable. Activate your virtual env first, then run.");
            }

            // Create PEP508 parser instance
            var parserInstance = new PEP508Parser();
            var builder        = new ParserBuilder <MetadataToken, IExpression>();
            var build          = builder.BuildParser(parserInstance, ParserType.LL_RECURSIVE_DESCENT, "logical_expression");

            if (build.IsError)
            {
                var errorMessage = string.Join(Environment.NewLine, build.Errors.Select(e => e.Message));
                throw new PackagerException($"Error building PEP508 parser:\n{errorMessage}");
            }

            this.parser = build.Result;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Factory method to create a runtime specific lambda packager.
        /// </summary>
        /// <param name="lambdaArtifact">The lambda artifact to package</param>
        /// <param name="s3">Interface to S3</param>
        /// <param name="logger">Interface to logger.</param>
        /// <param name="platform">Operating system platform</param>
        /// <returns>Runtime specific subclass of <see cref="LambdaPackager"/></returns>
        public static LambdaPackager CreatePackager(
            LambdaArtifact lambdaArtifact,
            IPSS3Util s3,
            ILogger logger,
            IOSInfo platform)
        {
            if (lambdaArtifact == null)
            {
                throw new ArgumentNullException(nameof(lambdaArtifact));
            }

            // To package dependencies, the lambda must be of a supported runtime.
            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault - Intentionally so.
            switch (lambdaArtifact.RuntimeInfo.RuntimeType)
            {
            case LambdaRuntimeType.Node:

                return(new LambdaNodePackager(lambdaArtifact, s3, logger));

            case LambdaRuntimeType.Python:

                // Python treats Linux and OSX the same so if not Windows, then Linux packager
                return(platform.OSPlatform == OSPlatform.Windows
                               ? (LambdaPythonPackager) new LambdaPythonPackagerWindows(lambdaArtifact, s3, logger)
                               : new LambdaPythonPackagerLinux(lambdaArtifact, s3, logger));

            case LambdaRuntimeType.Ruby:

                return(new LambdaRubyPackager(lambdaArtifact, s3, logger));

            default:

                logger.LogWarning(
                    $"Dependency packaging for lambda runtime '{lambdaArtifact.RuntimeInfo.RuntimeType}' is currently not supported.");
                return(new LambdaPlainPackager(lambdaArtifact, s3, logger));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LambdaArtifact"/> class.
        /// </summary>
        /// <param name="pathResolver">The path resolver.</param>
        /// <param name="lambdaResource">The lambda resource.</param>
        /// <param name="logger"></param>
        /// <param name="platform">The operating system platform</param>
        /// <param name="templatePath">Path to the template being processed.</param>
        public LambdaArtifact(
            IPathResolver pathResolver,
            IResource lambdaResource,
            ILogger logger,
            IOSInfo platform,
            string templatePath)
        {
            this.logger         = logger;
            this.templatePath   = templatePath;
            this.pathResolver   = pathResolver;
            this.lambdaResource = lambdaResource;
            this.platform       = platform;

            switch (lambdaResource.Type)
            {
            case "AWS::Lambda::Function":

                if (this.HasFileSystemReference("Code"))
                {
                    break;
                }

                this.InlineCode = this.GetScalarResourcePropertyValue("Code.ZipFile");

                if (this.InlineCode != null)
                {
                    this.ArtifactType = LambdaArtifactType.Inline;
                    break;
                }

                // At this point. either S3 or invalid
                this.ParseS3Location();
                break;

            case "AWS::Serverless::Function":

                // CodeUri or InlineCode
                this.InlineCode = this.GetScalarResourcePropertyValue("InlineCode");

                if (this.InlineCode != null)
                {
                    this.ArtifactType = LambdaArtifactType.Inline;
                    break;
                }

                if (this.HasFileSystemReference("CodeUri"))
                {
                    break;
                }

                // At this point. either S3 or invalid
                this.ParseS3Location();
                break;

            default:

                this.ArtifactType = LambdaArtifactType.NotLambda;
                return;
            }

            // Now get handler and runtime  info
            this.HandlerInfo = new LambdaHandlerInfo(this.lambdaResource);
            this.RuntimeInfo = new LambdaRuntimeInfo(this.lambdaResource);
        }