@@ -8,114 +8,68 @@ import (
88
99 "github.com/mindersec/minder/internal/db"
1010 minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
11+ provifv1 "github.com/mindersec/minder/pkg/providers/v1"
1112)
1213
1314const (
1415 providerDocsBaseURL = "https://docs.mindersec.dev"
1516 providerDocsURL = providerDocsBaseURL + "/integrations/provider_integrations/github"
1617)
1718
18- // OAuthImplements is the list of provider types that the GitHub OAuth provider implements.
19- var OAuthImplements = []db.ProviderType {
20- db .ProviderTypeGithub ,
21- db .ProviderTypeGit ,
22- db .ProviderTypeRest ,
23- db .ProviderTypeRepoLister ,
24- }
25-
2619// OAuthAuthorizationFlows is the list of authorization flows that the GitHub OAuth provider supports.
2720var OAuthAuthorizationFlows = []db.AuthorizationFlow {
2821 db .AuthorizationFlowUserInput ,
2922 db .AuthorizationFlowOauth2AuthorizationCodeFlow ,
3023}
3124
32- // AppImplements is the list of provider types that the GitHub App provider implements.
33- var AppImplements = []db.ProviderType {
34- db .ProviderTypeGithub ,
35- db .ProviderTypeGit ,
36- db .ProviderTypeRest ,
37- db .ProviderTypeRepoLister ,
38- }
39-
4025// AppAuthorizationFlows is the list of authorization flows that the GitHub App provider supports.
4126var AppAuthorizationFlows = []db.AuthorizationFlow {
4227 db .AuthorizationFlowGithubAppFlow ,
4328}
4429
45- // ProviderClassInfo returns class metadata for GitHub-backed provider classes.
46- func ProviderClassInfo (class db.ProviderClass ) (* minderv1.ProviderClassInfo , error ) {
47- switch class {
30+ // ProviderClassInfo implements the Provider interface.
31+ func (c * GitHub ) ProviderClassInfo () * minderv1.ProviderClassInfo {
32+ supportedTypes := provifv1 .ProviderTypesFromImpl (c )
33+ supportedEntities := []minderv1.Entity {
34+ minderv1 .Entity_ENTITY_REPOSITORIES ,
35+ minderv1 .Entity_ENTITY_PULL_REQUESTS ,
36+ minderv1 .Entity_ENTITY_ARTIFACTS ,
37+ minderv1 .Entity_ENTITY_RELEASE ,
38+ }
39+ switch c .providerClass {
4840 case db .ProviderClassGithub :
4941 return & minderv1.ProviderClassInfo {
5042 Class : string (db .ProviderClassGithub ),
5143 DisplayName : "GitHub OAuth" ,
5244 Description : "GitHub provider using OAuth credentials." ,
53- SupportedProviderTypes : dbProviderTypesToPB ( OAuthImplements ) ,
45+ SupportedProviderTypes : supportedTypes ,
5446 SupportedAuthFlows : dbAuthFlowsToPB (OAuthAuthorizationFlows ),
55- SupportedEntities : []minderv1.Entity {
56- minderv1 .Entity_ENTITY_REPOSITORIES ,
57- minderv1 .Entity_ENTITY_PULL_REQUESTS ,
58- minderv1 .Entity_ENTITY_ARTIFACTS ,
59- minderv1 .Entity_ENTITY_RELEASE ,
60- },
61- DocumentationUrl : providerDocsURL ,
62- }, nil
47+ SupportedEntities : supportedEntities ,
48+ DocumentationUrl : providerDocsURL ,
49+ }
6350 case db .ProviderClassGithubApp :
6451 return & minderv1.ProviderClassInfo {
6552 Class : string (db .ProviderClassGithubApp ),
6653 DisplayName : "GitHub App" ,
6754 Description : "GitHub App-based provider with installation-based authorization." ,
68- SupportedProviderTypes : dbProviderTypesToPB ( AppImplements ) ,
55+ SupportedProviderTypes : supportedTypes ,
6956 SupportedAuthFlows : dbAuthFlowsToPB (AppAuthorizationFlows ),
70- SupportedEntities : []minderv1.Entity {
71- minderv1 .Entity_ENTITY_REPOSITORIES ,
72- minderv1 .Entity_ENTITY_PULL_REQUESTS ,
73- minderv1 .Entity_ENTITY_ARTIFACTS ,
74- minderv1 .Entity_ENTITY_RELEASE ,
75- },
76- DocumentationUrl : providerDocsURL ,
77- }, nil
78- case db .ProviderClassGhcr :
79- fallthrough
80- case db .ProviderClassDockerhub :
81- fallthrough
82- case db .ProviderClassGitlab :
83- return nil , fmt .Errorf ("unsupported GitHub provider class: %s" , class )
57+ SupportedEntities : supportedEntities ,
58+ DocumentationUrl : providerDocsURL ,
59+ }
8460 default :
85- return nil , fmt .Errorf ("unsupported GitHub provider class: %s" , class )
86- }
87- }
88-
89- // ProviderClassInfo implements the Provider interface.
90- func (c * GitHub ) ProviderClassInfo () * minderv1.ProviderClassInfo {
91- info , err := ProviderClassInfo (c .providerClass )
92- if err != nil {
9361 return nil
9462 }
95-
96- return info
9763}
9864
99- func dbProviderTypesToPB (types []db.ProviderType ) []minderv1.ProviderType {
100- out := make ([]minderv1.ProviderType , 0 , len (types ))
101- for _ , t := range types {
102- switch t {
103- case db .ProviderTypeGit :
104- out = append (out , minderv1 .ProviderType_PROVIDER_TYPE_GIT )
105- case db .ProviderTypeGithub :
106- out = append (out , minderv1 .ProviderType_PROVIDER_TYPE_GITHUB )
107- case db .ProviderTypeRest :
108- out = append (out , minderv1 .ProviderType_PROVIDER_TYPE_REST )
109- case db .ProviderTypeRepoLister :
110- out = append (out , minderv1 .ProviderType_PROVIDER_TYPE_REPO_LISTER )
111- case db .ProviderTypeOci :
112- out = append (out , minderv1 .ProviderType_PROVIDER_TYPE_OCI )
113- case db .ProviderTypeImageLister :
114- out = append (out , minderv1 .ProviderType_PROVIDER_TYPE_IMAGE_LISTER )
115- }
65+ // ProviderClassInfo returns class metadata for GitHub-backed provider classes.
66+ // It uses a nil-pointer receiver to avoid needing a live client instance.
67+ func ProviderClassInfo (class db.ProviderClass ) (* minderv1.ProviderClassInfo , error ) {
68+ info := (& GitHub {providerClass : class }).ProviderClassInfo ()
69+ if info == nil {
70+ return nil , fmt .Errorf ("unsupported GitHub provider class: %s" , class )
11671 }
117-
118- return out
72+ return info , nil
11973}
12074
12175func dbAuthFlowsToPB (flows []db.AuthorizationFlow ) []minderv1.AuthorizationFlow {
0 commit comments