Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 3d2d88f

Browse files
author
Alex Evanczuk
authored
Remove visibility protection (#43)
1 parent 5e71768 commit 3d2d88f

10 files changed

+8
-639
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
package_protections (3.2.0)
4+
package_protections (4.0.0)
55
activesupport
66
parse_packwerk
77
rubocop

README.md

-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ This gem ships with the following checks
1010
2) Other packages are not using the private API of your package (via `packwerk` `enforce_privacy`)
1111
3) Your package has a typed public API (via the `rubocop` `PackageProtections/TypedPublicApi` cop)
1212
4) Your package only creates a single namespace (via the `rubocop` `PackageProtections/NamespacedUnderPackageName` cop)
13-
4) Your package is only visible to a select number of packages (via the `packwerk` `enforce_privacy` cop)
1413

1514
## Initial Configuration
1615
Package protections first requires that your application is using [`packwerk`](https://github.com/Shopify/packwerk), [`rubocop`](https://github.com/rubocop/rubocop), and [`rubocop-sorbet`](https://github.com/Shopify/rubocop-sorbet). Follow the regular setup instructions for those tools before proceeding.
@@ -63,25 +62,6 @@ end
6362

6463
If you've worked through all of the TODOs for this cop and are able to set the value to `fail_on_any`, you can also set `automatic_pack_namespace` which will support your pack having one global namespace without extra subdirectories. That is, instead of `packs/foo/app/services/foo/bar.rb`, you can use `packs/foo/app/services/bar.rb` and still have it define `Foo::Bar`. [See the `stimpack` README.md](https://github.com/rubyatscale/stimpack#readme) for more information.
6564

66-
### `prevent_other_packages_from_using_this_package_without_explicit_visibility`
67-
*This is only available if your package has `enforce_privacy` set to `true`!*
68-
This protection exists to help packages have control over who their clients are. When turning on this protection, only clients who are listed in your `visible_to` metadata will be allowed to consume your package. Here is an example in `packs/apples/package.yml`:
69-
```yml
70-
enforce_privacy: true
71-
enforce_dependencies: true
72-
metadata:
73-
protections:
74-
prevent_other_packages_from_using_this_package_without_explicit_visibility: fail_on_new
75-
# ... other protections are the same
76-
visible_to:
77-
- packs/other_pack
78-
- packs/another_pack
79-
```
80-
In this package, only `packs/other_pack` and `packs/another_pack` can use `packs/apples`. With both the `fail_on_new` and `fail_on_any` setting, only those packs can state a dependency on `packs/apples` in their `package.yml`. If any other packs state a dependency on `packs/apples`, the build will fail, even with violations. With the `fail_on_new` setting, a pack can create a dependency or privacy violation on `packs/apples` even if it's not listed. With `fail_on_any`, no violations are allowed.
81-
If `visible_to` is not set and the protection is turned on, then the package cannot be consumed by any package (a top-level package might be a good candidate for this).
82-
83-
Note that this protection's default behavior is `fail_never`, so it can remain unset in the `package.yml`.
84-
8565
## Violation Behaviors
8666
#### `fail_on_any`
8767
If this behavior is selected, the build will fail if there is *any* issue, new or old.

lib/package_protections/private.rb

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'package_protections/private/incoming_privacy_protection'
77
require 'package_protections/private/outgoing_dependency_protection'
88
require 'package_protections/private/metadata_modifiers'
9-
require 'package_protections/private/visibility_protection'
109
require 'package_protections/private/configuration'
1110

1211
module PackageProtections

lib/package_protections/private/configuration.rb

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def default_protections
3434
Private::IncomingPrivacyProtection.new,
3535
RuboCop::Cop::PackageProtections::TypedPublicApi.new,
3636
RuboCop::Cop::PackageProtections::NamespacedUnderPackageName.new,
37-
Private::VisibilityProtection.new,
3837
RuboCop::Cop::PackageProtections::OnlyClassMethods.new,
3938
RuboCop::Cop::PackageProtections::RequireDocumentedPublicApis.new
4039
]

lib/package_protections/private/visibility_protection.rb

-186
This file was deleted.

lib/package_protections/protected_package.rb

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ def dependencies
6666
original_package.dependencies
6767
end
6868

69-
sig { returns(T::Set[String]) }
70-
def visible_to
71-
Set.new(metadata['visible_to'] || [])
72-
end
73-
7469
sig { returns(T::Array[ParsePackwerk::Violation]) }
7570
def violations
7671
deprecated_references.violations

lib/package_protections/rspec/application_fixture_helper.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,17 @@ def write_package_yml(
1616
dependencies: [],
1717
enforce_dependencies: true,
1818
enforce_privacy: true,
19-
protections: {},
20-
visible_to: []
19+
protections: {}
2120
)
2221
defaults = {
2322
'prevent_this_package_from_violating_its_stated_dependencies' => 'fail_on_new',
2423
'prevent_other_packages_from_using_this_packages_internals' => 'fail_on_new',
2524
'prevent_this_package_from_exposing_an_untyped_api' => 'fail_on_new',
2625
'prevent_this_package_from_creating_other_namespaces' => 'fail_on_new',
27-
'prevent_other_packages_from_using_this_package_without_explicit_visibility' => 'fail_never',
2826
'prevent_this_package_from_exposing_instance_method_public_apis' => 'fail_never'
2927
}
3028
protections_with_defaults = defaults.merge(protections)
3129
metadata = { 'protections' => protections_with_defaults }
32-
if visible_to.any?
33-
metadata.merge!('visible_to' => visible_to)
34-
end
35-
3630
package = ParsePackwerk::Package.new(
3731
name: pack_name,
3832
dependencies: dependencies,

package_protections.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'package_protections'
3-
spec.version = '3.2.0'
3+
spec.version = '4.0.0'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['stephan.hagemann@gusto.com']
66
spec.summary = 'Package protections for Rails apps'

spec/package_protections/protected_package_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
someprotection: true
4646
YML
4747

48-
expect(PackageProtections.validate!).to include 'Invalid configuration for package `.`. The metadata keys ["someprotection"] are not a valid behavior under the `protection` metadata namespace. Valid keys are ["prevent_this_package_from_violating_its_stated_dependencies", "prevent_other_packages_from_using_this_packages_internals", "prevent_this_package_from_exposing_an_untyped_api", "prevent_this_package_from_creating_other_namespaces", "prevent_other_packages_from_using_this_package_without_explicit_visibility", "prevent_this_package_from_exposing_instance_method_public_apis", "prevent_this_package_from_exposing_undocumented_public_apis"]. See https://github.com/rubyatscale/package_protections#readme for more info'
48+
expect(PackageProtections.validate!).to include 'Invalid configuration for package `.`. The metadata keys ["someprotection"] are not a valid behavior under the `protection` metadata namespace. Valid keys are ["prevent_this_package_from_violating_its_stated_dependencies", "prevent_other_packages_from_using_this_packages_internals", "prevent_this_package_from_exposing_an_untyped_api", "prevent_this_package_from_creating_other_namespaces", "prevent_this_package_from_exposing_instance_method_public_apis", "prevent_this_package_from_exposing_undocumented_public_apis"]. See https://github.com/rubyatscale/package_protections#readme for more info'
4949
end
5050
end
5151

0 commit comments

Comments
 (0)