2019-02-19 23:56:41 +00:00
|
|
|
// 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"
|
2019-09-03 06:05:30 +00:00
|
|
|
"github.com/drone/drone/plugin/converter"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/plugin/registry"
|
|
|
|
"github.com/drone/drone/plugin/secret"
|
2019-09-03 06:05:30 +00:00
|
|
|
"github.com/drone/drone/plugin/validator"
|
2019-02-19 23:56:41 +00:00
|
|
|
"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,
|
2019-09-03 06:05:30 +00:00
|
|
|
provideConvertPlugin,
|
2019-02-19 23:56:41 +00:00
|
|
|
provideRegistryPlugin,
|
|
|
|
provideSecretPlugin,
|
2019-09-03 06:05:30 +00:00
|
|
|
provideValidatePlugin,
|
2019-02-19 23:56:41 +00:00
|
|
|
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),
|
2019-09-19 05:52:13 +00:00
|
|
|
admission.External(
|
|
|
|
config.Authn.Endpoint,
|
|
|
|
config.Authn.Secret,
|
|
|
|
config.Authn.SkipVerify,
|
|
|
|
),
|
2019-02-19 23:56:41 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(
|
2020-09-15 21:28:45 +00:00
|
|
|
config.Memoize(
|
|
|
|
config.Global(
|
|
|
|
conf.Yaml.Endpoint,
|
|
|
|
conf.Yaml.Secret,
|
|
|
|
conf.Yaml.SkipVerify,
|
2020-09-15 21:38:32 +00:00
|
|
|
conf.Yaml.Timeout,
|
2020-09-15 21:28:45 +00:00
|
|
|
),
|
2019-02-19 23:56:41 +00:00
|
|
|
),
|
|
|
|
config.Repository(contents),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-03 06:05:30 +00:00
|
|
|
// provideConvertPlugin is a Wire provider function that returns
|
|
|
|
// a yaml conversion plugin based on the environment
|
|
|
|
// configuration.
|
2021-05-27 13:58:23 +00:00
|
|
|
func provideConvertPlugin(client *scm.Client, conf spec.Config, templateStore core.TemplateStore) core.ConvertService {
|
2019-09-03 06:05:30 +00:00
|
|
|
return converter.Combine(
|
|
|
|
converter.Legacy(false),
|
2021-06-01 13:14:23 +00:00
|
|
|
converter.Starlark(
|
2020-11-20 13:56:47 +00:00
|
|
|
conf.Starlark.Enabled,
|
|
|
|
),
|
2019-09-03 06:05:30 +00:00
|
|
|
converter.Jsonnet(
|
|
|
|
conf.Jsonnet.Enabled,
|
|
|
|
),
|
2021-05-27 13:58:23 +00:00
|
|
|
converter.Template(
|
|
|
|
templateStore,
|
|
|
|
),
|
2020-09-15 21:28:45 +00:00
|
|
|
converter.Memoize(
|
|
|
|
converter.Remote(
|
|
|
|
conf.Convert.Endpoint,
|
|
|
|
conf.Convert.Secret,
|
|
|
|
conf.Convert.Extension,
|
|
|
|
conf.Convert.SkipVerify,
|
2020-09-15 21:38:32 +00:00
|
|
|
conf.Convert.Timeout,
|
2020-09-15 21:28:45 +00:00
|
|
|
),
|
2021-05-14 18:06:47 +00:00
|
|
|
conf.Convert.CacheSize,
|
2019-09-03 06:05:30 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-02-19 23:56:41 +00:00
|
|
|
// 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(
|
2019-09-17 19:18:35 +00:00
|
|
|
config.Secrets.Endpoint,
|
|
|
|
config.Secrets.Password,
|
|
|
|
config.Secrets.SkipVerify,
|
2019-02-19 23:56:41 +00:00
|
|
|
),
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-03 06:05:30 +00:00
|
|
|
// provideValidatePlugin is a Wire provider function that
|
|
|
|
// returns a yaml validation plugin based on the environment
|
|
|
|
// configuration.
|
|
|
|
func provideValidatePlugin(conf spec.Config) core.ValidateService {
|
2019-09-03 22:05:53 +00:00
|
|
|
return validator.Combine(
|
|
|
|
validator.Remote(
|
|
|
|
conf.Validate.Endpoint,
|
|
|
|
conf.Validate.Secret,
|
|
|
|
conf.Validate.SkipVerify,
|
2020-07-20 23:37:21 +00:00
|
|
|
conf.Validate.Timeout,
|
2019-09-03 22:05:53 +00:00
|
|
|
),
|
2020-09-15 21:28:45 +00:00
|
|
|
// THIS FEATURE IS INTERNAL USE ONLY AND SHOULD
|
|
|
|
// NOT BE USED OR RELIED UPON IN PRODUCTION.
|
|
|
|
validator.Filter(
|
|
|
|
nil,
|
|
|
|
conf.Repository.Ignore,
|
|
|
|
),
|
2019-09-03 22:05:53 +00:00
|
|
|
)
|
2019-09-03 06:05:30 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 23:56:41 +00:00
|
|
|
// provideWebhookPlugin is a Wire provider function that returns
|
|
|
|
// a webhook plugin based on the environment configuration.
|
2019-04-16 15:21:05 +00:00
|
|
|
func provideWebhookPlugin(config spec.Config, system *core.System) core.WebhookSender {
|
|
|
|
return webhook.New(webhook.Config{
|
2019-07-28 19:22:16 +00:00
|
|
|
Events: config.Webhook.Events,
|
2019-04-16 15:21:05 +00:00
|
|
|
Endpoint: config.Webhook.Endpoint,
|
|
|
|
Secret: config.Webhook.Secret,
|
|
|
|
System: system,
|
|
|
|
})
|
2019-02-19 23:56:41 +00:00
|
|
|
}
|