Skip to content

Commit 062c2e2

Browse files
committed
[minor] Decline ISLE-shaped Drupal projects
Teach the Drupal plugin project detector to reject Compose projects that contain ISLE services such as alpaca, fcrepo, blazegraph, milliner, triplet, cantaloupe, or activemq. This allows sitectl-isle to own isle-site-template checkouts and keeps commands like sitectl set bot-mitigation on from being routed to the generic Drupal plugin.
1 parent aef0c78 commit 062c2e2

2 files changed

Lines changed: 94 additions & 3 deletions

File tree

cmd/root.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
)
77

88
var (
9-
drupalServiceName = func() *string { s := "drupal"; return &s }()
10-
sdk *plugin.SDK
9+
drupalServiceName = func() *string { s := "drupal"; return &s }()
10+
drupalForbiddenISLEProjectServices = []string{"activemq", "alpaca", "blazegraph", "cantaloupe", "fcrepo", "milliner", "triplet"}
11+
sdk *plugin.SDK
1112
)
1213

1314
func init() {
@@ -19,8 +20,9 @@ func RegisterCommands(s *plugin.SDK) error {
1920
sdk = s
2021
sdk.SetComposeProjectDiscovery(plugin.ComposeProjectDiscovery{
2122
RequiredServices: []string{"drupal"},
23+
ForbiddenServices: drupalForbiddenISLEProjectServices,
2224
ForbiddenComposerPackages: []string{"drupal/islandora"},
23-
Reason: "drupal service without drupal/islandora in composer.json",
25+
Reason: "drupal service without drupal/islandora in composer.json or ISLE services",
2426
})
2527
pluginjobs.Register(s)
2628
if err := registerDrupalComponents(s); err != nil {

cmd/root_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"os"
7+
"path/filepath"
8+
"testing"
9+
10+
"github.com/libops/sitectl/pkg/plugin"
11+
)
12+
13+
func TestProjectDetectClaimsPlainDrupalProject(t *testing.T) {
14+
projectDir := t.TempDir()
15+
writeFileForTest(t, filepath.Join(projectDir, "docker-compose.yml"), "services:\n drupal:\n image: drupal:latest\n")
16+
writeFileForTest(t, filepath.Join(projectDir, "composer.json"), `{"require": {}}`)
17+
18+
result := runDrupalProjectDetectForTest(t, projectDir)
19+
if !result.Claimed {
20+
t.Fatalf("expected Drupal project detection to claim %s", projectDir)
21+
}
22+
if result.Plugin != "drupal" {
23+
t.Fatalf("expected drupal claim, got %#v", result)
24+
}
25+
}
26+
27+
func TestProjectDetectDeclinesISLEServices(t *testing.T) {
28+
projectDir := t.TempDir()
29+
writeFileForTest(t, filepath.Join(projectDir, "docker-compose.yml"), "services:\n alpaca:\n image: libops/alpaca:2\n drupal:\n image: islandora/drupal:main\n")
30+
writeFileForTest(t, filepath.Join(projectDir, "composer.json"), `{"require": {}}`)
31+
32+
result := runDrupalProjectDetectForTest(t, projectDir)
33+
if result.Claimed {
34+
t.Fatalf("expected Drupal project detection to decline ISLE services, got %#v", result)
35+
}
36+
}
37+
38+
func runDrupalProjectDetectForTest(t *testing.T, projectDir string) projectDetectResultForTest {
39+
t.Helper()
40+
41+
sdk := plugin.NewSDK(plugin.Metadata{Name: "drupal"})
42+
if err := RegisterCommands(sdk); err != nil {
43+
t.Fatalf("RegisterCommands() error = %v", err)
44+
}
45+
46+
req, err := plugin.NewProjectDetectRequest(projectDir)
47+
if err != nil {
48+
t.Fatalf("NewProjectDetectRequest() error = %v", err)
49+
}
50+
requestData, err := json.Marshal(req)
51+
if err != nil {
52+
t.Fatalf("Marshal(RPCRequest) error = %v", err)
53+
}
54+
55+
cmd := sdk.GetRPCCommand()
56+
var stdout bytes.Buffer
57+
cmd.SetIn(bytes.NewReader(requestData))
58+
cmd.SetOut(&stdout)
59+
if err := cmd.Execute(); err != nil {
60+
t.Fatalf("Execute() error = %v", err)
61+
}
62+
63+
var resp plugin.RPCResponse
64+
if err := json.Unmarshal(stdout.Bytes(), &resp); err != nil {
65+
t.Fatalf("Unmarshal(RPCResponse) error = %v: %s", err, stdout.String())
66+
}
67+
if !resp.OK {
68+
t.Fatalf("project.detect failed: %+v", resp.Error)
69+
}
70+
var result projectDetectResultForTest
71+
if err := json.Unmarshal(resp.Result, &result); err != nil {
72+
t.Fatalf("Unmarshal(project detect result) error = %v", err)
73+
}
74+
return result
75+
}
76+
77+
type projectDetectResultForTest struct {
78+
Claimed bool `json:"claimed"`
79+
Plugin string `json:"plugin"`
80+
ProjectDir string `json:"project_dir"`
81+
Reason string `json:"reason"`
82+
}
83+
84+
func writeFileForTest(t *testing.T, path, contents string) {
85+
t.Helper()
86+
if err := os.WriteFile(path, []byte(contents), 0o644); err != nil {
87+
t.Fatalf("WriteFile(%s) error = %v", path, err)
88+
}
89+
}

0 commit comments

Comments
 (0)