Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject secrets into the services [azuredevops bintray drone jenkins jira npm sonar symfony teamcity wheelmap] #3652

Merged
merged 36 commits into from Jul 10, 2019

Conversation

paulmelnikow
Copy link
Member

@paulmelnikow paulmelnikow commented Jul 6, 2019

This is a reworking of #3410 based on some feedback @calebcartwright left on that PR.

The goals of injecting the secrets are threefold:

  1. Simplify testing
  2. Be consistent with all of the other config (which is injected)
  3. Encapsulate the sensitive auth-related code in one place so it can be studied and tested thoroughly
  • Rather than add more code to BaseService to handle authorization logic, it delegates that to an AuthHelper class.
  • When the server starts, it fetches the credentials from config and injects them into BaseService.register() which passes them to invoke().
  • In invoke() the service's auth configuration is checked (static get auth(), much like static get route()).
  • If the auth config is present, an AuthHelper instance is created and attached to the new instance.
  • Then within the service, the password, basic auth config, or bearer authentication can be accessed via e.g. this.authHelper.basicAuth and passed to this._requestJson() and friends.
  • Everything is being done very explicitly, so it should be very clear where and how the configured secrets are being used.
  • Testing different configurations of services can now be done by injecting the config into invoke() in .spec files instead of mocking global state in the service tests as was done before. See the new Jira spec files for a good example of this.

Ref #3393

Need adding in this PR:

  • Nexus
  • Symfony

I've deferred a few odds and ends to a later PR:

@shields-cd shields-cd temporarily deployed to shields-staging-pr-3652 July 6, 2019 05:08 Inactive
@shields-ci
Copy link

shields-ci commented Jul 6, 2019

Warnings
⚠️ This PR modified the server but none of its tests.
That's okay so long as it's refactoring existing code.
⚠️

📚 Remember to ensure any changes to config.private in services/jenkins/jenkins-build.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/jira/jira-sprint.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/symfony/symfony-test-helpers.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/sonar/sonar-base.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/teamcity/teamcity-test-helpers.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/jira/jira-sprint.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/teamcity/teamcity-coverage.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/nexus/nexus.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/sonar/sonar-fortify-rating.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/npm/npm-base.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/teamcity/teamcity-base.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/jenkins/jenkins-base.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/teamcity/teamcity-build.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/wheelmap/wheelmap.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/nexus/nexus.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/drone/drone-build.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in core/base-service/base.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/azure-devops/azure-devops-helpers.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/jira/jira-issue.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/jira/jira-test-helpers.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/symfony/symfony-insight-base.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in server.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/wheelmap/wheelmap.tester.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/bintray/bintray.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/azure-devops/azure-devops-tests.service.js are reflected in the server secrets documentation

⚠️ This PR modified service code for bintray but not its test code.
That's okay so long as it's refactoring existing code.
⚠️

📚 Remember to ensure any changes to config.private in core/base-service/base.spec.js are reflected in the server secrets documentation

⚠️ This PR modified service code for azure-devops but not its test code.
That's okay so long as it's refactoring existing code.
⚠️

📚 Remember to ensure any changes to config.private in services/jira/jira-issue.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/azure-devops/azure-devops-coverage.service.js are reflected in the server secrets documentation

Messages
📖 ✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS against c9cebbc

@paulmelnikow paulmelnikow changed the title Inject server secrets Inject server secrets [azuredevops bintray drone wheelmap] Jul 6, 2019
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3652 July 6, 2019 05:11 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3652 July 6, 2019 15:21 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3652 July 6, 2019 15:25 Inactive
@calebcartwright
Copy link
Member

Know this is still a WIP, but I just finished a quick browse through the current set of changes and wanted to say it's looking good!

nock.enableNetConnect()
nock.activate()
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Co-Authored-By: Caleb Cartwright <calebcartwright@users.noreply.github.com>
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3652 July 10, 2019 00:53 Inactive
@calebcartwright calebcartwright changed the title Inject secrets into the services [azuredevops bintray drone jenkins jira npm sonar teamcity wheelmap] Inject secrets into the services [azuredevops bintray drone jenkins jira nexus npm sonar symfony teamcity wheelmap] Jul 10, 2019
@calebcartwright
Copy link
Member

I'm ready to approve and excited about this change! Are you working on those lint errors already? If not I'll fix and add a commit

@calebcartwright
Copy link
Member

That nexus test timeout is unrelated (it's one of more more notoriously slow tests), so i'm going to remove it from the title

@calebcartwright calebcartwright changed the title Inject secrets into the services [azuredevops bintray drone jenkins jira nexus npm sonar symfony teamcity wheelmap] Inject secrets into the services [azuredevops bintray drone jenkins jira npm sonar symfony teamcity wheelmap] Jul 10, 2019
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@paulmelnikow paulmelnikow merged commit ce0ddf9 into master Jul 10, 2019
@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

@paulmelnikow
Copy link
Member Author

Thanks for the review! This was a big one 😄

@paulmelnikow paulmelnikow deleted the inject-secrets-2 branch July 10, 2019 03:15
paulmelnikow added a commit that referenced this pull request Jul 11, 2019
Continues the work of #3652.

There’s more to do here with other parts of the GitHub config, though I’d rather merge this first and circle back to that.
paulmelnikow added a commit that referenced this pull request Jul 11, 2019
paulmelnikow added a commit that referenced this pull request Jul 11, 2019
Continues the work of #3652.

Since Bitbucket is the only service to use two sets of credentials like this, it seems to make the most sense to build a very local solution.
paulmelnikow added a commit that referenced this pull request Jul 11, 2019
paulmelnikow added a commit that referenced this pull request Jul 11, 2019
paulmelnikow added a commit that referenced this pull request Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker PRs and epics which block other work core Server, BaseService, GitHub auth service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants