Repository navigation
Adds resource target commands - #460
Conversation
|
@laurenzlong this is ready for review, PTAL when you have a chance. Also includes tests for once 😄 |
laurenzlong
left a comment
There was a problem hiding this comment.
I think the word "target" is getting a bit overloaded. In partial deployments, "functions" or "hosting" or a particular function name is also called a "target" in command descriptions, error messages, and docs. They're related concepts to "target" in this PR but they're slightly different. Maybe those should be renamed to "components" instead?
| var utils = require('./utils'); | ||
|
|
||
| var TARGET_TYPES = { | ||
| storage: {resource: 'bucket', exclusive: true} |
There was a problem hiding this comment.
Can you write a comment to explain what "exclusive" means?
| if (!TARGET_TYPES[type]) { | ||
| throw new FirebaseError( | ||
| 'Unrecognized target type ' + chalk.bold(type) + | ||
| '. Must be ' + _.keys(TARGET_TYPES).join(', '), |
There was a problem hiding this comment.
Maybe revise message to "Must be one of ....", or "Valid targets are... ". It's a bit confusing currently.
| return this.get(['targets', project, type, name], []); | ||
| }, | ||
|
|
||
| applyTarget: function(project, type, name, resources) { |
There was a problem hiding this comment.
consider renaming "name" to "targetName" or "target", otherwise it's unclear what name it's referring to.
| * not persist the result. | ||
| */ | ||
| unsetTargetResource: function(project, type, name, resource) { | ||
| var tp = ['targets', project, type, name]; |
There was a problem hiding this comment.
can you name it something more descriptive than "tp"?
| expect(subject.hasProjects).to.be.true; | ||
| }); | ||
| }); | ||
|
|
There was a problem hiding this comment.
If i'm understanding these tests correctly, they actually do disk writes into the fixtures folder. It would be better to mock out RC.save() and RC.load() to use memory instead, or at the minimum an afterEach function that cleans things up.
There was a problem hiding this comment.
Actually, it doesn't -- the logic of save() is that it only persists to disk if a path is set in the constructor, which these tests don't do. save() just returns false otherwise.
mbleigh
left a comment
There was a problem hiding this comment.
The "target" name isn't perfect, but was carefully considered. "Component" isn't correct because a single target can apply to multiple resources.
I agree that this is a bit confusing and will do my best to make sure the docs are clear. We can adapt to user feedback once this goes live, as well.
| var utils = require('./utils'); | ||
|
|
||
| var TARGET_TYPES = { | ||
| storage: {resource: 'bucket', exclusive: true} |
| return this.get(['targets', project, type, name], []); | ||
| }, | ||
|
|
||
| applyTarget: function(project, type, name, resources) { |
| if (!TARGET_TYPES[type]) { | ||
| throw new FirebaseError( | ||
| 'Unrecognized target type ' + chalk.bold(type) + | ||
| '. Must be ' + _.keys(TARGET_TYPES).join(', '), |
| * not persist the result. | ||
| */ | ||
| unsetTargetResource: function(project, type, name, resource) { | ||
| var tp = ['targets', project, type, name]; |
| expect(subject.hasProjects).to.be.true; | ||
| }); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Actually, it doesn't -- the logic of save() is that it only persists to disk if a path is set in the constructor, which these tests don't do. save() just returns false otherwise.
|
Filed a follow-up internal bug to track docs/wording updates of existing usage of "target". |
Adds a set of commands for managing "resource targets", which will be used to coordinate e.g. rules deploys across multiple storage buckets.
This is the first part of the necessary changes (thus why it's being merged into a feature branch instead of master) -- up next will be changes to config file parsing and deployment to actually support the necessary rules deploys.
Internal design link:
firebase-cli-multiresource