Class: Katello::OrganizationCreator

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/organization_creator.rb

Constant Summary collapse

DEFAULT_CONTENT_VIEW_NAME =
'Default Organization View'.freeze
DEFAULT_CONTENT_VIEW_LABEL =
'Default_Organization_View'.freeze
DEFAULT_LIFECYCLE_ENV_NAME =
'Library'.freeze
DEFAULT_LIFECYCLE_ENV_LABEL =
'Library'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organization, sca: true) ⇒ OrganizationCreator

Returns a new instance of OrganizationCreator.



30
31
32
33
# File 'app/services/katello/organization_creator.rb', line 30

def initialize(organization, sca: true)
  @organization = organization
  @content_access_mode = sca ? 'org_environment' : 'entitlement'
end

Instance Attribute Details

#anonymous_providerObject (readonly)

Returns the value of attribute anonymous_provider.



9
10
11
# File 'app/services/katello/organization_creator.rb', line 9

def anonymous_provider
  @anonymous_provider
end

#content_view_environmentObject (readonly)

Returns the value of attribute content_view_environment.



9
10
11
# File 'app/services/katello/organization_creator.rb', line 9

def content_view_environment
  @content_view_environment
end

#library_cvvObject (readonly)

Returns the value of attribute library_cvv.



9
10
11
# File 'app/services/katello/organization_creator.rb', line 9

def library_cvv
  @library_cvv
end

#library_environmentObject (readonly)

Returns the value of attribute library_environment.



9
10
11
# File 'app/services/katello/organization_creator.rb', line 9

def library_environment
  @library_environment
end

#library_viewObject (readonly)

Returns the value of attribute library_view.



9
10
11
# File 'app/services/katello/organization_creator.rb', line 9

def library_view
  @library_view
end

#redhat_providerObject (readonly)

Returns the value of attribute redhat_provider.



9
10
11
# File 'app/services/katello/organization_creator.rb', line 9

def redhat_provider
  @redhat_provider
end

Class Method Details

.create_all_organizations!Object



19
20
21
22
23
24
25
26
27
28
# File 'app/services/katello/organization_creator.rb', line 19

def self.create_all_organizations!
  Katello::Ping.ping!(services: [:candlepin])

  User.as_anonymous_admin do
    Organization.not_created_in_katello.each do |org|
      creator = self.new(org)
      creator.create!(raise_validation_errors: false)
    end
  end
end

.seed_all_organizations!Object



11
12
13
14
15
16
17
# File 'app/services/katello/organization_creator.rb', line 11

def self.seed_all_organizations!
  User.as_anonymous_admin do
    Organization.not_created_in_katello.each do |org|
      self.new(org).seed!
    end
  end
end

Instance Method Details

#create!(raise_validation_errors: true) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/services/katello/organization_creator.rb', line 52

def create!(raise_validation_errors: true)
  ActiveRecord::Base.transaction do
    seed!

    create_backend_objects!

    @organization.created_in_katello = true

    begin
      @organization.save!
    rescue => e
      raise e if raise_validation_errors
    end
  end
end

#create_backend_objects!Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/services/katello/organization_creator.rb', line 68

def create_backend_objects!
  Katello::Ping.ping!(services: [:candlepin])
  if needs_candlepin_organization?
    ::Katello::Resources::Candlepin::Owner.create(@organization.label, @organization.name, content_access_mode: @content_access_mode)
  end

  ::Katello::ContentViewManager.create_candlepin_environment(
    content_view_environment: @content_view_environment
  )

  @organization.debug_cert # trigger creation
end

#needs_candlepin_organization?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/services/katello/organization_creator.rb', line 81

def needs_candlepin_organization?
  !@organization.candlepin_owner_exists?
end

#seed!Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/katello/organization_creator.rb', line 35

def seed!
  ActiveRecord::Base.transaction do
    @organization.setup_label_from_name

    # existing validation errors are not resolvable here, so don't validate
    @organization.save(validate: false)

    create_library_environment
    create_library_view
    create_library_cvv
    create_content_view_environment
    create_anonymous_provider
    create_redhat_provider
    create_cdn_configuration
  end
end