File: ses.rb

package info (click to toggle)
ruby-aws 2.10.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 748 kB
  • sloc: ruby: 7,748; makefile: 16
file content (123 lines) | stat: -rw-r--r-- 4,123 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require_relative "../awsbase/awsbase"
module Aws

  require 'xmlsimple'

  class Ses < AwsBase

    include AwsBaseInterface

    API_VERSION = "2010-12-01"
    DEFAULT_HOST = "email.us-east-1.amazonaws.com"
    DEFAULT_PATH = '/'
    DEFAULT_PROTOCOL = 'https'
    DEFAULT_PORT = 443

    def self.connection_name
      :ses_connection
    end

    @@bench = AwsBenchmarkingBlock.new

    def self.bench
      @@bench
    end

    def self.bench_xml
      @@bench.xml
    end

    def self.bench_ec2
      @@bench.service
    end

    # Current API version (sometimes we have to check it outside the GEM).
    @@api = ENV['SES_API_VERSION'] || API_VERSION

    def self.api
      @@api
    end


    def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
      init({:name => 'SES',
            :default_host => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).host : DEFAULT_HOST,
            :default_port => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).port : DEFAULT_PORT,
            :default_service => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).path : DEFAULT_PATH,
            :default_protocol => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).scheme : DEFAULT_PROTOCOL,
            :api_version => API_VERSION,
            :signature_version=>'3'},
           aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
           aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
           params)
    end

    def do_request(action, params, options={})
      link = generate_request(action, params)
      puts "request=" + link[:request].inspect
      resp = request_info_xml_simple3(self, link,
                                      :group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
                                                     "DBParameterGroups" =>"DBParameterGroup",
                                                     "DBSecurityGroups" =>"DBSecurityGroup",
                                                     "EC2SecurityGroups" =>"EC2SecurityGroup",
                                                     "IPRanges" =>"IPRange"},
                                      :force_array =>["DBInstances",
                                                      "DBParameterGroups",
                                                      "DBSecurityGroups",
                                                      "EC2SecurityGroups",
                                                      "IPRanges"],
                                      :pull_out_array =>options[:pull_out_array],
                                      :pull_out_single=>options[:pull_out_single],
                                      :wrapper =>options[:wrapper])
    end


    #-----------------------------------------------------------------
    #      REQUESTS
    #-----------------------------------------------------------------


    # options:
    #    :marker => value received from previous response if IsTruncated = true
    #    :max_items => number of items you want returned
    #    :path_previx => for filtering results, default is /
    def get_send_quota(options={})
      @logger.info("get_send_quota")

      resp = do_request("GetSendQuota", options)


    rescue Exception
      on_exception
    end

    #
    # name: name of certificate
    # public_key: public key certificate in PEM-encoded format
    # private_key: private key in PEM-encoded format
    # options:
    #    :path => specify a path you want it stored in
    #    :certificate_chain => contents of certificate chain
    def upload_server_certificate(name, public_key, private_key, options={})
      params = {}
      params['ServerCertificateName'] = name
      params['PrivateKey'] = private_key
      params['CertificateBody'] = public_key

      params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
      params['Path'] = options[:path] if options[:path]

      p params

      resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])


    rescue Exception
      on_exception
    end


  end


end