Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
89 lines (75 loc) · 3.14 KB
/
Copy pathmain.go
File metadata and controls
89 lines (75 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: MIT
// Copyright 2024-2026 CloudSlash Contributors
package main
import (
"context"
"fmt"
"os"
"github.com/hashicorp/go-plugin"
"github.com/DrSkyle/cloudslash-plugin-github/internal/scan"
"github.com/DrSkyle/cloudslash-plugin-sdk/shared"
pb "github.com/DrSkyle/cloudslash-plugin-sdk/shared/proto"
)
// GitHubProvider is the local (v1) provider adapter. All GitHub API logic lives
// in internal/; the core sees only normalized nodes and edges.
type GitHubProvider struct {
pb.UnimplementedProviderServer
pb.UnimplementedRemediatorServer
}
const (
githubPluginName = "cloudslash-plugin-github"
githubPluginVersion = "1.0.0"
githubProviderName = "GitHub"
)
func (p *GitHubProvider) GetMetadata(context.Context, *pb.GetMetadataRequest) (*pb.GetMetadataResponse, error) {
return &pb.GetMetadataResponse{
PluginName: githubPluginName,
PluginVersion: githubPluginVersion,
ProviderName: githubProviderName,
Capabilities: []*pb.Capability{
{Name: "discovery", Version: githubPluginVersion, Available: true},
{Name: "remediation", Version: githubPluginVersion, Available: false},
{Name: "pricing", Version: githubPluginVersion, Available: false},
},
Health: &pb.HealthStatus{State: pb.HealthStatus_HEALTHY, Message: "GitHub plugin ready"},
Metadata: map[string]string{
"cloud_provider": "github",
"supported_services": "repositories,branches,workflows,secrets,webhooks,collaborators",
},
}, nil
}
func (p *GitHubProvider) Handshake(context.Context, *pb.HandshakeRequest) (*pb.HandshakeResponse, error) {
return &pb.HandshakeResponse{Compatible: true, PluginVersion: githubPluginVersion, Message: "GitHub plugin ready — read-only inventory"}, nil
}
func (p *GitHubProvider) Scan(req *pb.ScanRequest, stream pb.Provider_ScanServer) error {
return scan.Run(stream.Context(), req.Config, stream)
}
func (p *GitHubProvider) CheckReversibility(_ context.Context, req *pb.ReversibilityRequest) (*pb.ReversibilityProof, error) {
if req == nil || req.Crn == "" {
return &pb.ReversibilityProof{Safe: false, Reason: "missing CRN"}, nil
}
return &pb.ReversibilityProof{Safe: false, Reason: "GitHub plugin is read-only; no mutation is performed"}, nil
}
func (p *GitHubProvider) ApplyQuarantine(context.Context, *pb.QuarantineRequest) (*pb.QuarantineResponse, error) {
return &pb.QuarantineResponse{Success: false}, fmt.Errorf("GitHub plugin is read-only")
}
func (p *GitHubProvider) Remediate(context.Context, *pb.RemediateRequest) (*pb.RemediateResponse, error) {
return &pb.RemediateResponse{Success: false}, nil
}
func (p *GitHubProvider) RenderDetail(context.Context, *pb.RenderDetailRequest) (*pb.RenderDetailResponse, error) {
return &pb.RenderDetailResponse{}, nil
}
func main() {
if len(os.Args) > 1 && (os.Args[1] == "version" || os.Args[1] == "--version") {
fmt.Println("cloudslash-plugin-github v1.0.0")
return
}
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: shared.Handshake,
Plugins: map[string]plugin.Plugin{
"provider": &shared.ProviderPlugin{Impl: &GitHubProvider{}},
"remediator": &shared.RemediatorPlugin{Impl: &GitHubProvider{}},
},
GRPCServer: plugin.DefaultGRPCServer,
})
}