Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
moklidia committed Jun 6, 2022
2 parents 013c560 + 4dac218 commit cb6ac41
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 11 deletions.
2 changes: 1 addition & 1 deletion charts/uffizzi-app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: uffizzi-app
version: 1.1.3
version: 1.2.0
kubeVersion: ">= 1.21.0-0" # https://issuetracker.google.com/issues/77503699
description: "Uffizzi is an open-source engine for creating lightweight, ephemeral test environments for APIs and full-stack applications. Uffizzi enables teams to preview new features before merging."
type: application
Expand Down
9 changes: 7 additions & 2 deletions charts/uffizzi-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ global:
redis:
password: ChangeMeNow
uffizzi:
firstUser:
email: [email protected]
password: ChangeMeNow
controller:
password: ChangeMeNow
app_url: https://uffizzi.example.com
Expand Down Expand Up @@ -103,9 +106,11 @@ kubectl get ingress --namespace uffizzi
Be sure to add a "wildcard" record for the domain specified in `managed_dns_zone_dns_name`. In the above example, that's `*.uffizzi.example.com`.
### Creating the first user
### Provisioning users
You'll need to create at least one User Account to access your Uffizzi installation. The easiest way to do this is specify values for `global.uffizzi.firstUser` as shown in the example values file above. Uffizzi will attempt to provision this User each time it starts.
After installation, you'll need to create at least one User to access your Uffizzi installation. For now, the best way to do this is executing an interactive `rake` task within the application server container:
If you did not specify a `firstUser`, or if you want to provision additional Users, you may execute an interactive `rake` task within the application server container:
```
kubectl exec -it deploy/my-uffizzi-app-web --namespace uffizzi -- rake uffizzi_core:create_user
Expand Down
3 changes: 3 additions & 0 deletions charts/uffizzi-app/templates/configmap-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ data:
CONTROLLER_URL: {{ default (print "http://" .Release.Name "-controller:8080") .Values.controller_url }}
EMAIL_DELIVERY_ENABLED: {{ .Values.feature_email_delivery | quote }}
MANAGED_DNS_ZONE_DNS_NAME: {{ .Values.managed_dns_zone_dns_name | quote }}
UFFIZZI_USER_EMAIL: {{ .Values.global.uffizzi.firstUser.email }}
UFFIZZI_USER_PASSWORD: {{ .Values.global.uffizzi.firstUser.password | quote }}
UFFIZZI_PROJECT_NAME: {{ .Values.global.uffizzi.firstUser.projectName | quote }}
2 changes: 1 addition & 1 deletion charts/uffizzi-app/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- /bin/bash
- -c
args:
- bundle exec rails db:create db:migrate && bundle exec puma -C config/puma.rb
- bundle exec rails db:create db:migrate && bundle exec rake uffizzi_core:create_user && bundle exec puma -C config/puma.rb
envFrom:
- secretRef:
name: uffizzi-web-secret-envs
Expand Down
4 changes: 4 additions & 0 deletions charts/uffizzi-app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ global:
redis:
password: ChangeMeNow
uffizzi:
firstUser:
email: ""
password: ""
projectName: default
controller:
username: username
password: ChangeMeNow
Expand Down
16 changes: 11 additions & 5 deletions core/app/services/uffizzi_core/user_generator_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class UffizziCore::UserGeneratorService
DEFAULT_ACCOUNT_NAME = 'default'

class << self
def safe_generate(email, password, project_name)
generate(email, password, project_name)
rescue ActiveRecord::RecordInvalid => e
puts e.message
end

def generate(email, password, project_name)
user_attributes = build_user_attributes(email, password)
project_attributes = build_project_attributes(project_name)
Expand All @@ -31,19 +37,17 @@ def build_user_attributes(email, password)

if email.present?
user_attributes[:email] = email
else
elsif IO::console.present?
IO::console.write("Enter User Email (default: #{DEFAULT_USER_EMAIL}): ")
user_attributes[:email] = IO::console.gets.strip.presence || DEFAULT_USER_EMAIL
end

user_attributes[:password] = if password.present?
password
else
elsif IO::console.present?
IO::console.getpass('Enter Password: ')
end

abort('password can\'t be blank') if user_attributes[:password].blank?

user_attributes
end

Expand All @@ -53,9 +57,11 @@ def build_project_attributes(project_name)
}
if project_name.present?
project_attributes[:name] = project_name
else
elsif IO::console.present?
IO::console.write("Enter Project Name (default: #{DEFAULT_PROJECT_NAME}): ")
project_attributes[:name] = IO::console.gets.strip.presence || DEFAULT_PROJECT_NAME
else
project_attributes[:name] = DEFAULT_PROJECT_NAME
end

project_attributes[:slug] = prepare_project_slug(project_attributes[:name])
Expand Down
2 changes: 1 addition & 1 deletion core/lib/tasks/uffizzi_core_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ namespace :uffizzi_core do

desc 'Create a new user'
task create_user: :environment do
UffizziCore::UserGeneratorService.generate(ENV['UFFIZZI_USER_EMAIL'], ENV['UFFIZZI_USER_PASSWORD'], ENV['UFFIZZI_PROJECT_NAME'])
UffizziCore::UserGeneratorService.safe_generate(ENV['UFFIZZI_USER_EMAIL'], ENV['UFFIZZI_USER_PASSWORD'], ENV['UFFIZZI_PROJECT_NAME'])
end
end
93 changes: 92 additions & 1 deletion core/test/services/user_generator_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class UffizziCore::UserGeneratorServiceTest < ActiveSupport::TestCase
console_mock.stubs(:getpass).returns('')
IO.stubs(:console).returns(console_mock)

assert_raises SystemExit do
assert_raises StandardError do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end
Expand Down Expand Up @@ -150,4 +150,95 @@ class UffizziCore::UserGeneratorServiceTest < ActiveSupport::TestCase
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end

test '#generate if a user already exists' do
email = generate(:email)
password = generate(:password)
project_name = generate(:string)

create(:user, :with_organizational_account, email: email)

assert_raises ActiveRecord::RecordInvalid do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end

test '#generate if a user already exists and email gets by user' do
email = generate(:email)
password = generate(:password)
project_name = generate(:string)

create(:user, :with_organizational_account, email: email)

console_mock = mock('console_mock')
console_mock.stubs(:write)
console_mock.stubs(:gets).returns(email)
IO.stubs(:console).returns(console_mock)

assert_raises ActiveRecord::RecordInvalid do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end

test '#generate if have data but no console' do
email = generate(:email)
password = generate(:password)
project_name = generate(:string)

IO.stubs(:console).returns(nil)

differences = {
-> { UffizziCore::User.count } => 1,
-> { UffizziCore::Account.count } => 1,
-> { UffizziCore::Membership.count } => 1,
-> { UffizziCore::Project.count } => 1,
}

assert_difference differences do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end

test '#generate if no email and no console' do
email = nil
password = generate(:password)
project_name = generate(:string)

IO.stubs(:console).returns(nil)

assert_raises ActiveRecord::RecordInvalid do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end

test '#generate if no password and no console' do
email = generate(:email)
password = nil
project_name = generate(:string)

IO.stubs(:console).returns(nil)

assert_raises ActiveRecord::RecordInvalid do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end

test '#generate if no project_name and no console' do
email = generate(:email)
password = generate(:password)
project_name = nil

IO.stubs(:console).returns(nil)

differences = {
-> { UffizziCore::User.count } => 1,
-> { UffizziCore::Account.count } => 1,
-> { UffizziCore::Membership.count } => 1,
-> { UffizziCore::Project.count } => 1,
}

assert_difference differences do
UffizziCore::UserGeneratorService.generate(email, password, project_name)
end
end
end

0 comments on commit cb6ac41

Please sign in to comment.