renuo-cli 4.16.0 → 4.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7d2be942a488e9f935ad409f20fa275aea27af14713c6b98b155718208fbbbe
4
- data.tar.gz: 8b854cf2514442624fe57d6f25e6540575140f14b2ece1ecda41ad2f5ef767cb
3
+ metadata.gz: d001b3727b2158e75b84057e5520246f4a4983ebc9008a97802134a07a7fe9a1
4
+ data.tar.gz: d258158583a1659efea53a52cfb1e29569753e55e4c30d62c95984fed5498813
5
5
  SHA512:
6
- metadata.gz: 2b3b6acf9f8c2899d818ab72a1429835fc3f94ad003d8d6974c2bbee8d39819aeec07e5c947dd814f0626d1151fc007dff8d78664b7f84bd63d3d1ef2c6b68cc
7
- data.tar.gz: 612d0f7b4f197079cbb8e48c0cf7262a9d07f175e03c2318a7cc7a803451bc0c39c812ecebf13cd07b0c666090c0c21b1eedfecba3105ba6758fc616436349de
6
+ metadata.gz: cea757ec3ba510fbec394fe7d313edac2ef4db8e7d31f53e0c9cf83af0ef8d8225e53fa68a3f3c4beea206ef55e022774ef2cd342a1545aa4af925016b936bb1
7
+ data.tar.gz: 38a9b4a0b037a9ec087fd39060b7b154fbb5ce77533e80f9d977246c62f25fc3dee99e88f36ac7cdf96ec7eb01f7651ef6a89eac22bcb43dbf8c2a95ae1a35bd
data/README.md CHANGED
@@ -32,7 +32,8 @@ To release a new version, update the version number in `version.rb`, and then ru
32
32
 
33
33
  ## Release
34
34
 
35
- * Bump the version number in `lib/renuo/cli/version.rb` and commit to `main`
35
+ * Bump the version number in `lib/renuo/cli/version.rb`, run `bundle install`
36
+ to update the `Gemfile.lock` and commit to `main`
36
37
 
37
38
  ### Automatic
38
39
 
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+
5
+ class Renuo::Cli::Commands::CreateDeploioObjectStorage
6
+ include CommandHelper
7
+
8
+ command "create-deploio-object-storage" do |c|
9
+ c.syntax = "renuo create-deploio-object-storage"
10
+ c.summary = "Generates the script necessary to setup object storage on Deploio."
11
+ c.description = <<~DESCRIPTION
12
+ This creates commands for creating buckets and bucket users.
13
+ It also guides you to set up ActiveStorage correctly, by setting the required ENV variables and config/storage.yml setting.
14
+
15
+ You will be asked for:
16
+ - project name so that the script can respect our naming conventions
17
+
18
+ The generated commands do the following:
19
+ - create a bucket user for each environment (main, develop)
20
+ - create buckets for each user who owns it
21
+ - enable versioning for main buckets
22
+ DESCRIPTION
23
+ c.example "Setup Deploio object storage (you will be asked for details)", "renuo create-deploio-object-storage"
24
+ c.example "renuo create-deploio-object-storage",
25
+ "Prompts the user for the necessary information and generates the commands " \
26
+ "to setup object storage on Deploio."
27
+ c.action { new.run }
28
+ end
29
+
30
+ def initialize
31
+ @project_name = ask('Project name (eg: "renuo-mtextur"): ') { |q| q.validate = /.+/ }
32
+ @location = ask('Location (Default: "nine-es34"): ') { |q| q.default = "nine-es34" }
33
+ end
34
+
35
+ BRANCHES = %w[main develop].freeze
36
+
37
+ def run
38
+ BRANCHES.each do |branch|
39
+ print_setup_commands(branch)
40
+ end
41
+ print_active_storage_config
42
+ end
43
+
44
+ private
45
+
46
+ def project_name_without_organisation
47
+ @project_name_without_organisation ||= @project_name.split("-")[1..].join("-")
48
+ end
49
+
50
+ def print_setup_commands(branch)
51
+ say "\n# Commands to create #{branch} bucket user and bucket\n".bold
52
+ versioning_flag = branch == "main" ? " --versioning" : ""
53
+ bucket_name = "#{project_name_without_organisation}-#{branch}"
54
+ say "nctl create bucketuser #{branch} --project #{@project_name} --location #{@location}\n"
55
+ say "nctl create bucket #{bucket_name} --project #{@project_name} --location #{@location}" \
56
+ "#{versioning_flag} --permissions reader=#{branch} --permissions writer=#{branch}\n"
57
+ end
58
+
59
+ def print_active_storage_config
60
+ say "\n# ActiveStorage Configuration".bold
61
+ print_storage_yml_config
62
+ print_retrieve_credentials
63
+ print_env_variables_config
64
+ print_active_storage_service_config
65
+ end
66
+
67
+ def print_storage_yml_config
68
+ puts <<~OUTPUT
69
+ Add the following service configuration to your "config/storage.yml" file:
70
+
71
+ deploio:
72
+ service: S3
73
+ access_key_id: <%= ENV["DEPLOIO_ACCESS_KEY"] %>
74
+ secret_access_key: <%= ENV["DEPLOIO_SECRET_KEY"] %>
75
+ endpoint: <%= ENV["DEPLOIO_ENDPOINT"] %>
76
+ region: us-east-1 # running in Switzerland, operated by Nine.
77
+ bucket: <%= ENV["DEPLOIO_BUCKET"] %>
78
+
79
+ INFO: For S3, a region must be specified. Deploio uses the S3 default value of us-east-1,
80
+ even though the servers are in Switzerland, operated by Nine.
81
+ OUTPUT
82
+ end
83
+
84
+ def print_retrieve_credentials
85
+ say "\n# Retrieve credentials from the bucket user".bold
86
+ say "After running the bucket user creation commands above, retrieve your credentials:\n\n"
87
+
88
+ BRANCHES.each do |branch|
89
+ say <<~OUTPUT
90
+ ## #{branch} environment credentials:
91
+ nctl get bucketuser #{branch} --project #{@project_name} --print-credentials
92
+
93
+ OUTPUT
94
+ end
95
+ end
96
+
97
+ def print_env_variables_config
98
+ say "\n# Set environment variables on your Deploio application".bold
99
+ say "Replace the placeholders with the values retrieved above:\n"
100
+
101
+ BRANCHES.each do |branch|
102
+ bucket_name = "#{project_name_without_organisation}-#{branch}"
103
+ say <<~OUTPUT
104
+
105
+ # #{branch} environment:
106
+ nctl update app #{branch} \\
107
+ --project #{@project_name} \\
108
+ --env="DEPLOIO_ACCESS_KEY={ACCESS_KEY}" \\
109
+ --env="DEPLOIO_SECRET_KEY={SECRET_KEY}" \\
110
+ --env="DEPLOIO_ENDPOINT=https://#{@location}.objects.nineapis.ch" \\
111
+ --env="DEPLOIO_BUCKET=#{bucket_name}"
112
+ OUTPUT
113
+ end
114
+ end
115
+
116
+ def print_active_storage_service_config
117
+ say "\n# Configure ActiveStorage in your Rails application".bold
118
+ say <<~OUTPUT
119
+ Set the ActiveStorage service in your production environment ("config/environments/production.rb"):
120
+
121
+ config.active_storage.service = :deploio
122
+ OUTPUT
123
+ end
124
+ end
@@ -51,7 +51,8 @@ class Renuo::Cli::Commands::FetchSecrets # rubocop:disable Metrics/ClassLength
51
51
  end
52
52
 
53
53
  item_id = extract_item_id(private_link)
54
- item_json = get_item(item_id)
54
+ account_id = extract_account_id(private_link)
55
+ item_json = get_item(item_id, account_id)
55
56
  return if item_json.nil?
56
57
 
57
58
  item[:env_variables]&.each do |env_variable|
@@ -67,8 +68,15 @@ class Renuo::Cli::Commands::FetchSecrets # rubocop:disable Metrics/ClassLength
67
68
  /&i=([^&]+)/.match(private_link)[1]
68
69
  end
69
70
 
70
- def get_item(item_id)
71
- output = execute_command(command: "op item get #{item_id} --format json",
71
+ def extract_account_id(private_link)
72
+ /&h=([^&]+)/.match(private_link)&.[](1)
73
+ end
74
+
75
+ def get_item(item_id, account_id = nil)
76
+ command = "op item get #{item_id} --format json"
77
+ command += " --account #{account_id}" if account_id
78
+
79
+ output = execute_command(command: command,
72
80
  success_message: "",
73
81
  error_message: "Error fetching item #{item_id}." \
74
82
  "Check `private_link` in your #{CONFIG_FILE} file.")
@@ -3,7 +3,7 @@
3
3
  # :nocov:
4
4
  module Renuo
5
5
  class Cli
6
- VERSION = "4.16.0"
6
+ VERSION = "4.17.1"
7
7
  NAME = "renuo-cli"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renuo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.16.0
4
+ version: 4.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
@@ -85,6 +85,7 @@ files:
85
85
  - lib/renuo/cli/commands/configure_sentry.rb
86
86
  - lib/renuo/cli/commands/create_aws_project.rb
87
87
  - lib/renuo/cli/commands/create_deploio_app.rb
88
+ - lib/renuo/cli/commands/create_deploio_object_storage.rb
88
89
  - lib/renuo/cli/commands/create_heroku_app.rb
89
90
  - lib/renuo/cli/commands/create_new_logins.rb
90
91
  - lib/renuo/cli/commands/create_pr.rb