harness-drone/cmd/drone-server/inject_plugin.go
2019-03-13 16:12:54 -07:00

103 lines
3.1 KiB
Go

// Copyright 2019 Drone IO, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
spec "github.com/drone/drone/cmd/drone-server/config"
"github.com/drone/drone/core"
"github.com/drone/drone/plugin/admission"
"github.com/drone/drone/plugin/config"
"github.com/drone/drone/plugin/registry"
"github.com/drone/drone/plugin/secret"
"github.com/drone/drone/plugin/webhook"
"github.com/drone/go-scm/scm"
"github.com/google/wire"
)
// wire set for loading plugins.
var pluginSet = wire.NewSet(
provideAdmissionPlugin,
provideConfigPlugin,
provideRegistryPlugin,
provideSecretPlugin,
provideWebhookPlugin,
)
// provideAdmissionPlugin is a Wire provider function that
// returns an admission plugin based on the environment
// configuration.
func provideAdmissionPlugin(client *scm.Client, orgs core.OrganizationService, users core.UserService, config spec.Config) core.AdmissionService {
return admission.Combine(
admission.Membership(orgs, config.Users.Filter),
admission.Open(config.Registration.Closed),
admission.Nobot(users, config.Users.MinAge),
)
}
// provideConfigPlugin is a Wire provider function that returns
// a yaml configuration plugin based on the environment
// configuration.
func provideConfigPlugin(client *scm.Client, contents core.FileService, conf spec.Config) core.ConfigService {
return config.Combine(
config.Global(
conf.Yaml.Endpoint,
conf.Yaml.Secret,
conf.Yaml.SkipVerify,
),
config.Jsonnet(contents, conf.Jsonnet.Enabled),
config.Repository(contents),
)
}
// provideRegistryPlugin is a Wire provider function that
// returns a registry plugin based on the environment
// configuration.
func provideRegistryPlugin(config spec.Config) core.RegistryService {
return registry.Combine(
registry.External(
config.Secrets.Endpoint,
config.Secrets.Password,
config.Secrets.SkipVerify,
),
registry.FileSource(
config.Docker.Config,
),
registry.EndpointSource(
config.Registries.Endpoint,
config.Registries.Password,
config.Registries.SkipVerify,
),
)
}
// provideSecretPlugin is a Wire provider function that returns
// a secret plugin based on the environment configuration.
func provideSecretPlugin(config spec.Config) core.SecretService {
return secret.External(
config.Secrets.Endpoint,
config.Secrets.Password,
config.Secrets.SkipVerify,
)
}
// provideWebhookPlugin is a Wire provider function that returns
// a webhook plugin based on the environment configuration.
func provideWebhookPlugin(config spec.Config) core.WebhookSender {
return webhook.New(
config.Webhook.Endpoint,
config.Webhook.Secret,
)
}