github.com/kubeshop/testkube@v1.17.23/pkg/tcl/apitcl/v1/pro.go (about)

     1  // Copyright 2024 Testkube.
     2  //
     3  // Licensed as a Testkube Pro file under the Testkube Community
     4  // License (the "License"); you may not use this file except in compliance with
     5  // the License. You may obtain a copy of the License at
     6  //
     7  //	https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt
     8  
     9  package v1
    10  
    11  import (
    12  	"net/http"
    13  
    14  	"github.com/gofiber/fiber/v2"
    15  	"github.com/pkg/errors"
    16  )
    17  
    18  func (s *apiTCL) isPro() bool {
    19  	return s.ProContext != nil
    20  }
    21  
    22  //nolint:unused
    23  func (s *apiTCL) isProPaid() bool {
    24  	// TODO: Replace with proper implementation
    25  	return s.isPro()
    26  }
    27  
    28  func (s *apiTCL) pro(h fiber.Handler) fiber.Handler {
    29  	return func(ctx *fiber.Ctx) error {
    30  		if s.isPro() {
    31  			return h(ctx)
    32  		}
    33  		return s.Error(ctx, http.StatusPaymentRequired, errors.New("this functionality is only for the Pro/Enterprise subscription"))
    34  	}
    35  }
    36  
    37  //nolint:unused
    38  func (s *apiTCL) proPaid(h fiber.Handler) fiber.Handler {
    39  	return func(ctx *fiber.Ctx) error {
    40  		if s.isProPaid() {
    41  			return h(ctx)
    42  		}
    43  		return s.Error(ctx, http.StatusPaymentRequired, errors.New("this functionality is only for paid plans of Pro/Enterprise subscription"))
    44  	}
    45  }