class Sambot::Tasks::Create

Constants

DESCRIPTION_REQUEST
IDENTIFIER_REQUEST
NAME_REQUEST
PLATFORM_OPTIONS
PLATFORM_REQUEST

Public Instance Methods

check_cookbook_name(name) click to toggle source
# File lib/sambot/tasks/create.rb, line 37
def check_cookbook_name(name)
  unless is_valid_name?(name)
    UI.error('The cookbook name you have provided is invalid')
    exit 1
  end
end
is_valid_name?(name) click to toggle source
# File lib/sambot/tasks/create.rb, line 48
def is_valid_name?(name)
  is_valid_role_name?(name)|| name.start_with?('as-')
end
is_valid_role_name?(name) click to toggle source
# File lib/sambot/tasks/create.rb, line 44
def is_valid_role_name?(name)
  name.start_with?('as-role-') || name.start_with?('as-app-role-')
end
normalize_platforms(platforms) click to toggle source
# File lib/sambot/tasks/create.rb, line 33
def normalize_platforms(platforms)
  platforms == 'both' ? PLATFORM_OPTIONS - ['both']: [platforms]
end
run(options) click to toggle source
# File lib/sambot/tasks/create.rb, line 21
def run(options)
  opts = {
    'name' => ask(NAME_REQUEST),
    'platforms' => ask(PLATFORM_REQUEST, limited_to: PLATFORM_OPTIONS),
    'description' => ask(DESCRIPTION_REQUEST)
  }
  check_cookbook_name(opts['name'])
  opts['identifier'] = ask(IDENTIFIER_REQUEST) if is_valid_role_name?(opts['name'])
  opts['platforms'] = normalize_platforms(opts['platforms'])
  Chef::Cookbook.create(Config.new(opts))
end