/*
Copyright 2020 The cert-manager Authors.

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 internal

import (
	"context"

	"github.com/cert-manager/cert-manager/e2e-tests/framework/config"
)

// Addon is an interface that defines an e2e addon.
type Addon interface {
	// For non-global addons, this function is called on all ginkgo processes without
	// any arguments. For global addons, this function is called on ginkgo process #1
	// without any arguments, but the returned data is passed to the Setup function
	// on all other ginkgo processes.
	Setup(ctx context.Context, cfg *config.Config, leaderData ...AddonTransferableData) (AddonTransferableData, error)

	// For non-global addons, this function is called on all ginkgo processes. For global
	// addons, this function is called only on ginkgo process #1.
	Provision(ctx context.Context) error

	// For non-global addons, this function is called on all ginkgo processes. For global
	// addons, this function is called only on ginkgo process #1.
	Deprovision(ctx context.Context) error

	SupportsGlobal() bool
}

// TransferableData is data generated by a global addons' Setup function running on ginigo
// process #1 that should be copied to all other ginkgo processes. This is used to setup these
// processes with the same data as ginkgo process #1. The data has to be json serializable.
//
// e.g., The process #1 Setup function generates a private key and certificate and transfers
// it to all other ginkgo processes. Process #1 then starts a shared server that trusts the
// certificate. All other ginkgo processes can authenticate to this server using the private
// key and certificate that was transferred to them.
type AddonTransferableData interface{}
