3

I've created a yaml file to import Twitter timeline items (not super simple since documentation on the migrate_plus OAuth plugin seems to be few and far between); this migration naturally requires the use of ostensibly-secret API information. I'd like to keep this out of the yaml and I've seen answers (like this one) that talk about setting things in code, but I'm wondering if there's another customer-serviceable way. For example, here's my config file, called migrate_plus.migration.migrate_sample_twitter:

id: migrate_sample_twitter
label: Sample Twitter Migration
dependencies:
  - migrate
  - migrate_plus
status: true

source:
  plugin: url
  data_fetcher_plugin: http
  authentication:
    plugin: oauth2
    base_uri: 'https://api.twitter.com'
    token_url: /oauth2/token
    grant_type: client_credentials
    client_id: <twitter app consumer key>
    client_secret: <twitter app consumer secret>

  urls: https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=tmountjr

  fields:
    -
      name: id
      label: Tweet ID
      selector: id_str

destination:
  plugin: table
  table_name: twitter_import
  id_fields:
    id:
      type: string

Now, running drush cget migrate_plus.migration.migrate_sample_twitter drops all that information on the console, which is fine. BUT, I'm unable to retrieve any information deeper than that. What I was hoping to do was, in my settings.local.php, specify this:

$conf['migrate_plus.migration.migrate_sample_twitter.source.authentication.client_id'] = 'consumer key here'
$conf['migrate_plus.migration.migrate_sample_twitter.source.authentication.client_secret'] = 'consumer secret here'

...and then just omit the client_id and client_secret keys from the yaml file. But that doesn't seem to work; when I make those changes and run drush migrate-status I get an error: The config is missing the following key: "client_id".

So short version of this question: is there any way to omit values from an exported yaml file and instead have those values stored in a user-editable settings file that can be .gitignored from the repo?

3 Answers 3

3

In Drupal 8, If the migration is one that is a config entity (shows up in /config rather than in migrations/) values can be overridden in settings.php or environment specific settings.

// Set migration settings from environment variables.
$config['migrate_plus.migration.node_article']['source']['urls'] = [getenv('CMS_ARTICLE_API_URL') . '/services/articles/facilities/all'];
$config['migrate_plus.migration.node_article']['source']['headers']['apikey'] = getenv('CMS_ARTICLE_API_KEY');
1

I'm not entirely sure if this will work in your use case, but I know the key module is designed to keep secret keys outside of any config files. Then you just ask the key service for whatever key you need and it returns it to you. It can store the key in several different formats.

2
  • Doesn't look like that module ties in (at least not directly) with config files, though I suppose it would be possible to write a plugin for migrate that would read from that service, but at that point, might as well just point at settings.php to keep things lean.
    – tmountjr
    Commented Jul 19, 2017 at 18:50
  • Maybe it didn't at the time of posting, but the Key module definitely can be used to override config now. "The Drupal 8 version of Key provides the ability to override any configuration value with a key. This allows site administrators to store configuration values in a more secure method than in the database or in settings.php."
    – mbomb007
    Commented May 15 at 19:34
0

$conf is 7.x, Drupal 8 uses $config for configuration overrides and the syntax is `$config['config_object']['property.path.key'].

In your case, should be something like:

$config['migrate_plus.migration.migrate_sample_twitter']['source.authentication.client_id'] = 'consumer key here';

That should work but keep in mind that migrations are cached unless you disable the cache by setting the bin to null, so don't forget to clear caches.

1
  • Not working for this module, but it could be a handful of things. I'll try modifying a system configuration file, not a contrib module file, and see if that process works.
    – tmountjr
    Commented Jul 20, 2017 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.