File: target_https_proxy.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (105 lines) | stat: -rw-r--r-- 3,263 bytes parent folder | download | duplicates (4)
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
module Fog
  module Compute
    class Google
      class TargetHttpsProxy < Fog::Model
        identity :name

        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :description, :aliases => "description"
        attribute :id, :aliases => "id"
        attribute :kind, :aliases => "kind"
        attribute :self_link, :aliases => "selfLink"
        attribute :url_map, :aliases => "urlMap"
        # Array of SSL Certificates
        # @example
        #
        #   [cert_one.self_link', cert_two.self_link]
        #
        # , where 'cert_one' and 'cert_two' are instances of
        # Fog::Compute::Google::SslCertificate
        #
        # @return [Array<String>]
        attribute :ssl_certificates, :aliases => "sslCertificates"

        def save
          requires :identity, :url_map, :ssl_certificates

          unless ssl_certificates.is_a?(Array)
            raise Fog::Errors::Error.new("ssl_certificates attribute must be an array")
          end

          data = service.insert_target_https_proxy(
            identity,
            :description => description,
            :url_map => url_map,
            :ssl_certificates => ssl_certificates
          )
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? }
          reload
        end

        def destroy(async = true)
          requires :identity

          data = service.delete_target_https_proxy(identity)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? } unless async
          operation
        end

        def set_url_map(url_map, async = true)
          requires :identity

          data = service.set_target_https_proxy_url_map(
            identity, url_map
          )
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? } unless async
          reload
        end

        def set_ssl_certificates(ssl_certificates, async = true)
          requires :identity

          data = service.set_target_https_proxy_ssl_certificates(
            identity, ssl_certificates
          )
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name)
          operation.wait_for { ready? } unless async
          reload
        end

        def ready?
          requires :identity

          service.get_target_https_proxy(identity)
          true
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404
          false
        end

        def reload
          requires :identity

          return unless data = begin
            collection.get(identity)
          rescue Excon::Errors::SocketError
            nil
          end

          new_attributes = data.attributes
          merge_attributes(new_attributes)
          self
        end

        RUNNING_STATE = "READY".freeze
      end
    end
  end
end