<commit_before>exit unless Rails.env.development?
puts "You need to setup an Oauth client application to interact with the API."
puts "To do this you'll need a local admin user account, the following will setup both for you.\n\n"
puts "Please enter an password (min 8 chars) for the admin user, make it secure and you'll need to remember this!"
password = STDIN.noecho(&:gets).chomp
if password.length < 8
  abort("Failed: Password must be at least 8 characters long")
end

#setup an admin user
attrs = { display_name: 'Zooniverse Admin',
          password: password,
          login: 'zooniverse_admin',
          email: '<EMAIL>' }
admin = User.create(attrs) do |user|
  user.owner_name = OwnerName.new(name: user.login, resource: user)
end
puts "Admin details:"
puts "name: #{admin.login}"
puts "email: #{admin.email}"

#setup a doorkeeper first party oauth application with scopes for the client
app = Doorkeeper::Application.create do |da|
  da.owner = admin
  da.name = 'FigDevAppClient'
  #testing redirect URL
  da.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
  # zooniverse first-party app
  da.trust_level = 2
  #scoped resources this app has access to
  da.default_scope = ["public", "user", "project", "group", "collection", "classification"]
end
puts "Oauth Zooniverse first party app details:"
puts "client_id: #{app.uid}\n"
puts "Use the client ID above to interact with the api."
puts "You can reivew these settings via the Oauth Applications page at http(s)://<server_ip:port>//oauth/applications"
<commit_msg>add formatting to setup script<commit_after>exit unless Rails.env.development?

require 'io/console'

def colorize(text, color_code)
  "\e[#{color_code}m#{text}\e[0m"
end
def red(text); colorize(text, 31); end
def green(text); colorize(text, 32); end
def yellow(text); colorize(text, 33); end

panoptes = %{
______  ___   _   _ ___________ _____ _____ _____
| ___ \\/ _ \\ | \\ | |  _  | ___ \\_   _|  ___/  ___|
| |_/ / /_\\ \\|  \\| | | | | |_/ / | | | |__ \\ `--.
|  __/|  _  || . ` | | | |  __/  | | |  __| `--. \\
| |   | | | || |\\  \\ \\_/ / |     | | | |___/\\__/ /
\\_|   \\_| |_/\\_| \\_/\\___/\\_|     \\_/ \\____/\\____/
}

puts yellow("\n\n---------------------------------------------------------------------")
puts yellow(panoptes)
puts "\nYou need to setup an Oauth client application to interact with the API."
puts "In turn this requires a local admin user account."
puts "This script will setup both for you.\n\n"
puts yellow("Please enter an password (min 8 chars) for the admin user, make it secure and you'll need to remember this!")
password = STDIN.noecho(&:gets).chomp
if password.length < 8
  abort(red("Failed: Password must be at least 8 characters long\n"))
end

#setup an admin user
attrs = { display_name: '<NAME>',
          password: password,
          login: 'zooniverse_admin',
          email: '<EMAIL>' }
admin = User.create(attrs) do |user|
  user.owner_name = OwnerName.new(name: user.login, resource: user)
end
puts "\nAdmin details:"
puts "login: #{green(admin.login)}"
puts "email: #{green(admin.email)}\n"

#setup a doorkeeper first party oauth application with scopes for the client
app = Doorkeeper::Application.create do |da|
  da.owner = admin
  da.name = 'FigDevAppClient'
  #testing redirect URL
  da.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
  # zooniverse first-party app
  da.trust_level = 2
  #scoped resources this app has access to
  da.default_scope = ["public", "user", "project", "group", "collection", "classification"]
end
puts "\nOauth Zooniverse first party app details:"
puts "client_id: #{green(app.uid)}\n"
puts "Use the client ID above to interact with the api."
puts "You can review these settings via the Oauth Applications page on your server at:"
puts yellow("http(s)://<server_ip:port>//oauth/applications\n\n")

{'fraction_non_alphanumeric': 0.15717659406979795, 'fraction_numerical': 0.004985568092364209, 'mean_word_length': 3.386651323360184, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5988962', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1243, 'n_words': 400}