# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true cs__scoped_require 'yaml' module Contrast # A Rake task to generate a contrast_security.yaml file with some basic settings module Config extend Rake::DSL include Contrast::Components::Interface DEFAULT_CONFIG = { 'api' => { 'url' => 'Enter your Contrast URL ex: https://app.contrastsecurity.com/Contrast', 'api_key' => 'Enter your Contrast api key', 'service_key' => 'Enter your Contrast service key', 'user_name' => 'Enter your Contrast user name' }, 'agent' => { 'service' => { 'logger' => { 'path' => 'contrast_service.log', 'level' => 'ERROR' # DEBUG | INFO | WARN | ERROR }, 'socket' => '/tmp/contrast_service.sock' }, 'logger' => { 'level' => 'ERROR', 'path' => 'contrast_agent.log' } } }.cs__freeze namespace :contrast do namespace :config do desc 'Create a contrast_security.yaml in the applications root directory' task :create do execution_directory = Dir.pwd target_path = File.join(execution_directory, 'contrast_security.yaml') if File.exist?(target_path) puts 'WARNING: contrast_security.yaml already exists' else File.open(target_path, 'w') do |f| f.write(YAML.dump(DEFAULT_CONFIG)) end puts "Created contrast_security.yaml at #{ target_path }" puts 'Open the file and enter your Contrast Security api keys or set them via environment variables' puts 'Visit our documentation site for more details: https://docs.contrastsecurity.com/installation-rubyconfig.html' end end end end end end