Sha256: d2eb243add22c813c656177f0e48e1787cf3a8274115883976b96a8418011950

Contents?: true

Size: 927 Bytes

Versions: 2

Compression:

Stored size: 927 Bytes

Contents

require "ostruct"

module Rancher
  module ManagementApi
    class Project < OpenStruct
      def self.create(conn, name)
        env_response = conn.post do |req|
          req.url "/v1/project"
          req.body = {
            name: name,
          }.to_json
        end

        data = JSON.parse(env_response.body)

        # reload until the project is ready
        while data["state"] == "registering"
          sleep 0.5
          url = data["links"]["self"]
          response = conn.get do |req|
            req.url url
          end

          data = JSON.parse(response.body)
        end

        new(conn, data)
      end

      attr_reader :conn

      def initialize(conn, data)
        @conn = conn
        super(data)
      end

      def create_api_key(name)
        ApiKey.create(self, name)
      end

      def create_registration_token
        RegistrationToken.create(self)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rancher-management_api-0.3.2 lib/rancher/management_api/project.rb
rancher-management_api-0.3.0 lib/rancher/management_api/project.rb