You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use Rails credentials instead of deprecated and removed secrets
Rails 7.1 removes access to modifying secrets as we should be moved over to
rails credentials. Here we describe how to setup these rails crednetials for
the purpose of recording VCR cassettes.
See also: ManageIQ/manageiq-providers-autosde#253
Copy file name to clipboardexpand all lines: providers/writing_vcr_specs.md
+54-17
Original file line number
Diff line number
Diff line change
@@ -22,34 +22,71 @@ The next thing we have to take care of is hiding "secrets". Since the VCR YAML
22
22
23
23
VCR handles this with the `config.define_cassette_placeholder` option. You provide VCR with a string that you want to be replaced, and then what you want it to be replaced with. This allows for hostnames / passwords / etc... to be used when recording the cassette but the values will not be written to the resulting YAML files.
24
24
25
-
ManageIQ has a pattern to help you with this, simply create a `config/secrets.defaults.yml` file:
25
+
ManageIQ has a pattern to help you with this. We use rails credentials. Run the following command in the main application directory:
26
+
27
+
```
28
+
EDITOR=vi be rails credentials:edit --help
29
+
```
30
+
31
+
This will provide more information about rails credentials.
32
+
33
+
A sample workflow for VCR cassettes would be to edit the test environment's credentials and use them in test.
34
+
35
+
Run the prior command without the help option and with the 'test' environment:
36
+
37
+
```
38
+
EDITOR=vi be rails credentials:edit --environment test
39
+
```
40
+
41
+
You can use your preferred editor by specifying it on the command line.
42
+
43
+
In the editor, set your credentials, for example:
44
+
26
45
```yaml
27
46
---
28
-
test:
29
-
awesome_cloud_defaults: &awesome_cloud_defaults
47
+
awesome_cloud:
30
48
access_key: AWESOME_CLOUD_ACCESS_KEY
31
49
secret_key: AWESOME_CLOUD_SECRET_KEY
32
-
awesome_cloud:
33
-
<<: *awesome_cloud_defaults
34
50
```
35
51
36
-
Then create a `config/secrets.yml` file (this file will not be committed and should be in your .gitignore):
37
-
```yaml
38
-
---
39
-
test:
40
-
awesome_cloud:
41
-
access_key: "YOUR_REAL_ACCESS_KEY"
42
-
secret_key: "YOUR_REAL_SECRET_KEY"
52
+
After saving, this will create or update:
53
+
* a plain text key file if you haven't already created one: config/credentials/test.key
54
+
* an encrypted credentials file: config/credentials/test.yml.enc
55
+
56
+
Add memoized methods in spec/spec_helper.rb with the defaults you want to assumed when running from cassettes to avoid leaking actual credentials:
Now that we have VCR configured it is time to start writing your spec tests. First we will start with the Refresher to test the refresh process of your new provider.
@@ -62,7 +99,7 @@ describe ManageIQ::Providers::AwesomeCloud::CloudManager::Refresher do
Make sure that you have your `config/secrets.yml` file still present, you might have to update the expected counts as things in your environment have likely changed but you now should have an updated VCR cassette.
165
+
Make sure that you have your rails credentials still present. You might have to update the expected counts as things in your environment have likely changed but you now should have an updated VCR cassette.
0 commit comments