Class: Etna::Clients::Magma::CreateProjectWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::CreateProjectWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/create_project_workflow.rb
Instance Attribute Summary collapse
-
#janus_client ⇒ Object
Returns the value of attribute janus_client.
-
#magma_client ⇒ Object
Returns the value of attribute magma_client.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#project_name_full ⇒ Object
Returns the value of attribute project_name_full.
Instance Method Summary collapse
- #add_janus_user(email, name, role) ⇒ Object
- #create! ⇒ Object
- #create_janus_project! ⇒ Object
- #create_magma_project! ⇒ Object
- #create_magma_project_record! ⇒ Object
- #promote_to_administrator(email) ⇒ Object
- #refreshed_token ⇒ Object
- #setup_janus_project! ⇒ Object
- #setup_magma_project! ⇒ Object
- #update_magma_client_token! ⇒ Object
- #user ⇒ Object
Instance Attribute Details
#janus_client ⇒ Object
Returns the value of attribute janus_client
18 19 20 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 18 def janus_client @janus_client end |
#magma_client ⇒ Object
Returns the value of attribute magma_client
18 19 20 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 18 def magma_client @magma_client end |
#project_name ⇒ Object
Returns the value of attribute project_name
18 19 20 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 18 def project_name @project_name end |
#project_name_full ⇒ Object
Returns the value of attribute project_name_full
18 19 20 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 18 def project_name_full @project_name_full end |
Instance Method Details
#add_janus_user(email, name, role) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 26 def add_janus_user(email, name, role) janus_client.add_user(Etna::Clients::Janus::AddUserRequest.new( project_name: project_name, email: email, name: name, role: role, )) end |
#create! ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 87 def create! setup_janus_project! setup_magma_project! while true puts "Add more users? Y/n" break unless STDIN.gets.chomp == 'Y' puts "User name?" name = STDIN.gets.chomp puts "Email?" email = STDIN.gets.chomp puts "Role? (editor/viewer/administrator)" role = STDIN.gets.chomp puts "Adding #{name} (#{email}) as a #{role}." puts "Confirm? Y/n" break unless STDIN.gets.chomp == 'Y' if role == 'administrator' add_janus_user(email, name, 'editor') promote_to_administrator(email) else add_janus_user(email, name, role) end end puts "All complete!" puts "You need to visit Janus to refresh your token." puts "You can now log into any app to manage your data." end |
#create_janus_project! ⇒ Object
19 20 21 22 23 24 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 19 def create_janus_project! janus_client.add_project(Etna::Clients::Janus::AddProjectRequest.new( project_name: project_name, project_name_full: project_name_full )) end |
#create_magma_project! ⇒ Object
55 56 57 58 59 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 55 def create_magma_project! magma_client.update_model(Etna::Clients::Magma::UpdateModelRequest.new( project_name: project_name, actions: [Etna::Clients::Magma::AddProjectAction.new])) end |
#create_magma_project_record! ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 61 def create_magma_project_record! magma_client.update_json(Etna::Clients::Magma::UpdateRequest.new( project_name: project_name, revisions: { 'project' => { project_name => { name: project_name } }, })) end |
#promote_to_administrator(email) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 35 def promote_to_administrator(email) janus_client.(Etna::Clients::Janus::UpdatePermissionRequest.new( project_name: project_name, # email: user['email'], email: email, role: 'administrator', )) end |
#refreshed_token ⇒ Object
44 45 46 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 44 def refreshed_token janus_client.refresh_token(Etna::Clients::Janus::RefreshTokenRequest.new).token end |
#setup_janus_project! ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 69 def setup_janus_project! puts "Creating Janus project." create_janus_project! puts "Done! Adding you as an administrator on the project." add_janus_user(user['email'], "#{user['name']}", 'editor') promote_to_administrator(user['email']) update_magma_client_token! puts "Done with setting up the project in Janus!" end |
#setup_magma_project! ⇒ Object
80 81 82 83 84 85 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 80 def setup_magma_project! puts "Creating the project in Magma." create_magma_project! puts "Done! Adding your new project record." create_magma_project_record! end |
#update_magma_client_token! ⇒ Object
48 49 50 51 52 53 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 48 def update_magma_client_token! self.magma_client = Etna::Clients::Magma.new( host: self.magma_client.host, token: refreshed_token, ignore_ssl: self.magma_client.ignore_ssl) end |
#user ⇒ Object
117 118 119 |
# File 'lib/etna/clients/magma/workflows/create_project_workflow.rb', line 117 def user @user ||= JSON.parse(Base64.urlsafe_decode64(magma_client.token.split('.')[1])) end |