Home Reference Source Test
public class | source

Artifact

This class handles retrieving CodePipeline artifact files as well as accessing file contents in addition to attributes defined inside JSON files residing within the artifact.

As the artifacts passed to the function may reside within remote buckets which this function does not have sufficient permissions to access, credentials are used from the initial CodePipeline event object.

Static Method Summary

Static Public Methods
public static

toArtifact(artifact: *, credentials: {}): Artifact

Transform the properties received from CodePipeline into a new instance of this class.

public static

toArtifactMapEntry(artifact: *, credentials: *): Array[String, Artifact]

Returns an array which can be used to constuct a Map of artifacts.

Constructor Summary

Public Constructor
public

constructor(s3Location: Object)

Constructs a new Artifact instance.

Member Summary

Public Members
public

The AWS Access Key ID which will be used to retrieve the remote artifact.

public

The name of the S3 bucket which the remote artifact file resides in.

public get

client: S3

Returns a new S3 client with credentials pre-configured.

public

A fully resolved path to the directory storing the decompressed contents of the remote artifact in the /tmp directory.

public

A filename representing the name of the artifact once downloaded and stored locally.

public

A fully resolved Path to the local artifact when downloaded and written to the /tmp/ directory.

public

A local ID for this artifact.

public

Determines if this artifact has been retrieved, decompressed and written to local file storage.

public

The key for the remote artifact file.

public

The AWS Secret Access Key which will be used to retrieve the remote artifact.

public

The AWS Session Token which will be used to retrieve the remote artifact.

Method Summary

Public Methods
public

attribute(filename: *, key: *): *

Once Artifact#ready has resolved successfully, this function can be used to retrieve the value of a specific property key from within a JSON file residing inside the decompressed artifact.

public

get(filename: *): Buffer

Once Artifact#ready has resolved successfully, this function can be used to retrieve a specific file's contents from within the decompressed artifact.

public

async match(select: String, path: String): Array[File]

Returns an array of File instances which represent all matched files from inside the retrieved, decompressed artifact.

public

async ready(): Boolean

A utility function to ensure that this artifact has first retrived and decompressed the remote artifact file, before any attempts are made to retrieve artifact contents.

Private Methods
private

async fetch(): Buffer

private
private

async write(data: *): Boolean

Static Public Methods

public static toArtifact(artifact: *, credentials: {}): Artifact source

Transform the properties received from CodePipeline into a new instance of this class.

This function maps the required properties from the CodePipeline invocation event structure.

Params:

NameTypeAttributeDescription
artifact *
credentials {}
  • optional
  • default: {}

Return:

Artifact

a new artifact file with correctly mapped parameters.

public static toArtifactMapEntry(artifact: *, credentials: *): Array[String, Artifact] source

Returns an array which can be used to constuct a Map of artifacts.

Params:

NameTypeAttributeDescription
artifact *
credentials *

Return:

Array[String, Artifact]

Public Constructors

public constructor(s3Location: Object) source

Constructs a new Artifact instance.

Params:

NameTypeAttributeDescription
s3Location Object

object representing a remote S3 location

s3Location.bucketName String

the name of the S3 bucket.

s3Location.objectKey String

the key of the file inside the S3 bucket.

Public Members

public accessKeyId: String source

The AWS Access Key ID which will be used to retrieve the remote artifact.

public bucketName: String source

The name of the S3 bucket which the remote artifact file resides in.

public get client: S3 source

Returns a new S3 client with credentials pre-configured.

public dir: String source

A fully resolved path to the directory storing the decompressed contents of the remote artifact in the /tmp directory.

public filename: String source

A filename representing the name of the artifact once downloaded and stored locally.

public filepath: String source

A fully resolved Path to the local artifact when downloaded and written to the /tmp/ directory.

public id: String source

A local ID for this artifact.

public isReady: Boolean source

Determines if this artifact has been retrieved, decompressed and written to local file storage.

public objectKey: String source

The key for the remote artifact file.

public secretAccessKey: String source

The AWS Secret Access Key which will be used to retrieve the remote artifact.

public sessionToken: String source

The AWS Session Token which will be used to retrieve the remote artifact.

Public Methods

public attribute(filename: *, key: *): * source

Once Artifact#ready has resolved successfully, this function can be used to retrieve the value of a specific property key from within a JSON file residing inside the decompressed artifact.

Params:

NameTypeAttributeDescription
filename *
key *

Return:

*

[String] the value of the key from within a JSON file.

public get(filename: *): Buffer source

Once Artifact#ready has resolved successfully, this function can be used to retrieve a specific file's contents from within the decompressed artifact.

Params:

NameTypeAttributeDescription
filename *

Return:

Buffer

a utf-8 buffer of the file's contents.

public async match(select: String, path: String): Array[File] source

Returns an array of File instances which represent all matched files from inside the retrieved, decompressed artifact.

Params:

NameTypeAttributeDescription
select String

a linux-style file glob to match files with.

path String

a relative path used to match files

Return:

Array[File]

an array of all matched File instances.

public async ready(): Boolean source

A utility function to ensure that this artifact has first retrived and decompressed the remote artifact file, before any attempts are made to retrieve artifact contents.

Return:

Boolean

true if ready, false otherwise.

Private Methods

private async fetch(): Buffer source

Return:

Buffer

the buffer contents of the remote artifacts retrieved from S3.

private unzip(): Boolean source

Return:

Boolean

true once contents have been successfully decompressed.

private async write(data: *): Boolean source

Params:

NameTypeAttributeDescription
data *

Return:

Boolean

true once the file has been written.