feat: add more to repo model
This commit is contained in:
4 files changed
+92
-10
No files matched your search
@@ -1,6 +1,10 @@
|
||||
package v0alpha1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
@@ -16,20 +20,51 @@ type LocalRepository struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
func (r *LocalRepository) IsEmpty() bool {
|
||||
return r == nil || r.Path == ""
|
||||
}
|
||||
|
||||
type S3Repository struct {
|
||||
Bucket string `json:"bucket,omitempty"`
|
||||
|
||||
// TODO: Add ACL?
|
||||
// TODO: Encryption??
|
||||
// TODO: How do we define access? Secrets?
|
||||
}
|
||||
|
||||
func (r *S3Repository) IsEmpty() bool {
|
||||
return r == nil || r.Bucket == ""
|
||||
}
|
||||
|
||||
type GitHubRepository struct {
|
||||
Owner string `json:"owner,omitempty"`
|
||||
// The owner of the repository (e.g. example in `example/test` or `https://github.com/example/test`).
|
||||
Owner string `json:"owner,omitempty"`
|
||||
// The name of the repository (e.g. test in `example/test` or `https://github.com/example/test`).
|
||||
Repository string `json:"repository,omitempty"`
|
||||
|
||||
// TODO: Do we want an SSH url instead maybe?
|
||||
// TODO: On-prem GitHub Enterprise support?
|
||||
// TODO: How do we define access? Secrets?
|
||||
|
||||
// Whether we should commit to change branches and use a Pull Request flow to achieve this.
|
||||
// By default, this is false (i.e. we will commit straight to the main branch).
|
||||
BranchWorkflow bool `json:"branchWorkflow,omitempty"`
|
||||
|
||||
// Whether we should show dashboard previews in the pull requests caused by the BranchWorkflow option.
|
||||
// By default, this is false (i.e. we will not create previews).
|
||||
// This option is a no-op if BranchWorkflow is `false` or default.
|
||||
GenerateDashboardPreviews bool `json:"generateDashboardPreviews,omitempty"`
|
||||
}
|
||||
|
||||
func (r *GitHubRepository) IsEmpty() bool {
|
||||
// we don't need to check options here, just the most important stuff to actually connect.
|
||||
return r == nil || r.Owner == "" || r.Repository == ""
|
||||
}
|
||||
|
||||
type RepositorySpec struct {
|
||||
// The UID of the folder that is backed by the repository.
|
||||
FolderUID string `json:"folderUid,omitempty"`
|
||||
|
||||
// The repository on the local file system.
|
||||
// Mutually exclusive with s3 and github.
|
||||
Local LocalRepository `json:"local,omitempty"`
|
||||
@@ -39,7 +74,31 @@ type RepositorySpec struct {
|
||||
// The repository on GitHub.
|
||||
// Mutually exclusive with local and s3.
|
||||
// TODO: github or just 'git'??
|
||||
GitHubRepository GitHubRepository `json:"github,omitempty"`
|
||||
GitHub GitHubRepository `json:"github,omitempty"`
|
||||
}
|
||||
|
||||
func (s *RepositorySpec) UnmarshalJSON(data []byte) error {
|
||||
type Alias RepositorySpec
|
||||
real := struct {
|
||||
*Alias `json:",inline"`
|
||||
}{(*Alias)(s)}
|
||||
|
||||
if err := json.Unmarshal(data, &real); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nonEmpty := 0
|
||||
type IsEmptyer interface{ IsEmpty() bool }
|
||||
for _, it := range []IsEmptyer{&real.GitHub, &real.S3, &real.Local} {
|
||||
if !it.IsEmpty() {
|
||||
nonEmpty++
|
||||
}
|
||||
}
|
||||
if nonEmpty != 1 {
|
||||
return fmt.Errorf("%w (found %d)", errors.New("one (and exactly one) of github, s3, and local must be set"), nonEmpty)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
@@ -108,7 +108,7 @@ func (in *RepositorySpec) DeepCopyInto(out *RepositorySpec) {
|
||||
*out = *in
|
||||
out.Local = in.Local
|
||||
out.S3 = in.S3
|
||||
out.GitHubRepository = in.GitHubRepository
|
||||
out.GitHub = in.GitHub
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,30 @@ func schema_pkg_apis_provisioning_v0alpha1_GitHubRepository(ref common.Reference
|
||||
Properties: map[string]spec.Schema{
|
||||
"owner": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "The owner of the repository (e.g. example in `example/test` or `https://github.com/example/test`).",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"repository": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Description: "The name of the repository (e.g. test in `example/test` or `https://github.com/example/test`).",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"branchWorkflow": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Whether we should commit to change branches and use a Pull Request flow to achieve this. By default, this is false (i.e. we will commit straight to the main branch).",
|
||||
Type: []string{"boolean"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"generateDashboardPreviews": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Whether we should show dashboard previews in the pull requests caused by the BranchWorkflow option. By default, this is false (i.e. we will not create previews). This option is a no-op if BranchWorkflow is `false` or default.",
|
||||
Type: []string{"boolean"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -93,8 +109,7 @@ func schema_pkg_apis_provisioning_v0alpha1_Repository(ref common.ReferenceCallba
|
||||
},
|
||||
"spec": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: map[string]interface{}{},
|
||||
Ref: ref("github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositorySpec"),
|
||||
Ref: ref("github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositorySpec"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -158,6 +173,13 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositorySpec(ref common.ReferenceCa
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: []string{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"folderUid": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The UID of the folder that is backed by the repository.",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"local": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository on the local file system. Mutually exclusive with s3 and github.",
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,RepositorySpec,GitHubRepository
|
||||
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,RepositorySpec,FolderUID
|
||||
API rule violation: names_match,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,RepositorySpec,GitHub
|
||||
Reference in new issue
Block a user