5ecfc79e14
* Provisioning: Add Connection resource * adding some more integration tests * updating openapi snapshot, linting * generating FE code, fixing issue in unit tests * addressing comments * addressing comments * adding more integration tests * fixing rebase issues * removing linting exception * addressing comments: improving validation and tests * adding Connection URL at mutation time, updating tests accordingly * linting
29 lines
728 B
Go
29 lines
728 B
Go
package connection
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
provisioning "github.com/grafana/grafana/apps/provisioning/pkg/apis/provisioning/v0alpha1"
|
|
)
|
|
|
|
const (
|
|
githubInstallationURL = "https://github.com/settings/installations"
|
|
)
|
|
|
|
func MutateConnection(connection *provisioning.Connection) error {
|
|
switch connection.Spec.Type {
|
|
case provisioning.GithubConnectionType:
|
|
// Do nothing in case spec.Github is nil.
|
|
// If this field is required, we should fail at validation time.
|
|
if connection.Spec.GitHub == nil {
|
|
return nil
|
|
}
|
|
|
|
connection.Spec.URL = fmt.Sprintf("%s/%s", githubInstallationURL, connection.Spec.GitHub.InstallationID)
|
|
return nil
|
|
default:
|
|
// TODO: we need to setup the URL for bitbucket and gitlab.
|
|
return nil
|
|
}
|
|
}
|