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
The next thing we have to take care of is hiding "secrets". Since the VCR YAML files will be committed to source control it is critical that private information like passwords do not make it into these files.
22
24
23
25
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
26
25
-
ManageIQ has a pattern to help you with this, simply create a `config/secrets.defaults.yml` file:
27
+
ManageIQ has a pattern to help you with this. By default, the generator created a file named `spec/config/secrets.defaults.yml` with a username and password.
28
+
```yaml
29
+
---
30
+
awesome_cloud:
31
+
username: AWESOME_CLOUD_USERNAME
32
+
password: AWESOME_CLOUD_PASSWORD
33
+
```
34
+
35
+
If your provider uses a different set of secrets, such as access_key and secret_key, you can change the file accordingly as follows:
26
36
```yaml
27
37
---
28
-
test:
29
-
awesome_cloud_defaults: &awesome_cloud_defaults
30
-
access_key: AWESOME_CLOUD_ACCESS_KEY
31
-
secret_key: AWESOME_CLOUD_SECRET_KEY
32
-
awesome_cloud:
33
-
<<: *awesome_cloud_defaults
38
+
awesome_cloud:
39
+
access_key: AWESOME_CLOUD_ACCESS_KEY
40
+
secret_key: AWESOME_CLOUD_SECRET_KEY
34
41
```
35
42
36
-
Then create a `config/secrets.yml` file (this file will not be committed and should be in your .gitignore):
43
+
Finally, create a `spec/config/secrets.yml` file with your real provider secrets. **NOTE**: This file must not be committed and should be in your .gitignore.
37
44
```yaml
38
45
---
39
-
test:
40
-
awesome_cloud:
41
-
access_key: "YOUR_REAL_ACCESS_KEY"
42
-
secret_key: "YOUR_REAL_SECRET_KEY"
46
+
awesome_cloud:
47
+
access_key: YOUR_REAL_ACCESS_KEY
48
+
secret_key: YOUR_REAL_SECRET_KEY
43
49
```
44
50
45
-
Then add the following to your `VCR.configure` block in `spec/spec_helper.rb` after setting the `config.cassette_library_dir`:
51
+
And that's all! The `VcrSecrets.define_all_cassette_placeholders` line in `spec/spec_helper.rb` automatically marks everything under the awesome_cloud key as sensitive data.
52
+
53
+
If you need to manually mark something as sensitive data, then you will need to call `config.define_cassette_placeholder`. To do so, you can add the following to your `VCR.configure` block in `spec/spec_helper.rb` after setting the `config.cassette_library_dir`. For example, if your provider Base64 encodes the access_key and secret_key into a header, you will want to include something like the following:
46
54
```ruby
47
-
secrets = Rails.application.secrets
48
-
secrets.awesome_cloud.each do |key, val|
49
-
config.define_cassette_placeholder(secrets.awesome_cloud_defaults[key]) { val }
55
+
config.define_cassette_placeholder("AWESOME_CLOUD_AUTHORIZATION") do
@@ -117,12 +125,12 @@ Now fill out the refresher_spec.rb file with more checks to ensure that inventor
117
125
118
126
### Updating the VCR cassettes
119
127
120
-
Now that you have your specs recorded, what happens if you want to collect something new? Like you now want to start fetching floating IPs or Cloud Volumes?
128
+
Now that you have your specs recorded, what happens if you want to collect something new? For example, if you now want to start fetching floating IPs or Cloud Volumes?
121
129
122
130
It is simple to re-record your VCR cassette, simply remove the file then rerun the specs against the same environment:
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.
136
+
Make sure that you have your `config/secrets.yml` file still present. Note that 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