Class: AppCommand::Upload

Inherits:
Convoy::ActionCommand::Base
  • Object
show all
Defined in:
lib/routes/upload.rb

Constant Summary collapse

STACKS =
'Stacks'
PROJECTS =
'Projects'
TEMPLATES =
'Templates'

Instance Method Summary collapse

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/routes/upload.rb', line 9

def execute

    begin

        @opts    = command_options
        @args    = arguments
        @action  = determine_action
        @profile = App::AWSProfile::get_profile

        opts_validate
        opts_routing

    rescue => e

        Blufin::Terminal::print_exception(e)

    end

end

#opts_routingObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/routes/upload.rb', line 33

def opts_routing

    # Get the local path based on upload action.
    # @profile keys DO NOT need to be validated because we already check them in the awx.rb routing code.
    case @action
        when STACKS
            local_path = @profile[App::AWSProfile::STACKS]['Local']['File']
            s3_bucket  = @profile[App::AWSProfile::STACKS]['S3Bucket']['Name']
            s3_path    = @profile[App::AWSProfile::STACKS]['S3Bucket']['File']
            s3_region  = @profile[App::AWSProfile::STACKS]['S3Bucket']['Region']
        when PROJECTS
            local_path = @profile[App::AWSProfile::PROJECTS]['Local']['File']
            s3_bucket  = @profile[App::AWSProfile::PROJECTS]['S3Bucket']['Name']
            s3_path    = @profile[App::AWSProfile::PROJECTS]['S3Bucket']['File']
            s3_region  = @profile[App::AWSProfile::PROJECTS]['S3Bucket']['Region']
        when TEMPLATES
            local_path = @profile[App::AWSProfile::CLOUDFORMATION]['Templates']['Local']['Path']
            s3_bucket  = @profile[App::AWSProfile::CLOUDFORMATION]['Templates']['S3Bucket']['Name']
            s3_path    = @profile[App::AWSProfile::CLOUDFORMATION]['Templates']['S3Bucket']['Path']
            s3_region  = @profile[App::AWSProfile::CLOUDFORMATION]['Templates']['S3Bucket']['Region']
        else
            raise RuntimeError, "Unrecognized action: #{@action}"
    end

    # Check that path/file exists.
    if [TEMPLATES].include?(@action)
        Blufin::Terminal::error("Path not found: #{Blufin::Terminal::format_directory(local_path)}") unless Blufin::Files::path_exists(local_path)
        is_file = false
    else
        Blufin::Terminal::error("File not found: #{Blufin::Terminal::format_directory(local_path)}") unless Blufin::Files::file_exists(local_path)
        is_file = true
    end

    # Do a dryrun first.
    puts
    Blufin::AWS::upload_s3_data(s3_bucket, s3_path, local_path, profile: @profile[App::AWSProfile::PROFILE], region: s3_region, is_file: is_file, dryrun: true)
    puts

    if Blufin::Terminal::prompt_yes?('Sync these files to S3?')
        # Upload path to S3.
        s3_path = Blufin::AWS::upload_s3_data(s3_bucket, s3_path, local_path, profile: @profile[App::AWSProfile::PROFILE], region: s3_region, is_file: is_file)
        # Success Message.
        Blufin::Terminal::success('Files have been successfully uploaded to S3.', s3_path)
    end

end

#opts_validateObject



29
30
31
# File 'lib/routes/upload.rb', line 29

def opts_validate

end