|
|
@@ -45,6 +45,7 @@ func NewCreateReleaseHandler(
|
|
|
|
|
|
func (c *CreateReleaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
user, _ := r.Context().Value(types.UserScope).(*models.User)
|
|
|
+ proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
|
|
|
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
|
|
|
namespace := r.Context().Value(types.NamespaceScope).(string)
|
|
|
operationID := oauth.CreateRandomState()
|
|
|
@@ -122,6 +123,7 @@ func (c *CreateReleaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|
|
if request.GithubActionConfig != nil {
|
|
|
_, _, err := createGitAction(
|
|
|
c.Config(),
|
|
|
+ proj,
|
|
|
user.ID,
|
|
|
cluster.ProjectID,
|
|
|
cluster.ID,
|
|
|
@@ -200,6 +202,7 @@ func createReleaseFromHelmRelease(
|
|
|
|
|
|
func createGitAction(
|
|
|
config *config.Config,
|
|
|
+ project *models.Project,
|
|
|
userID, projectID, clusterID uint,
|
|
|
request *types.CreateGitActionConfigRequest,
|
|
|
name, namespace string,
|
|
|
@@ -241,7 +244,7 @@ func createGitAction(
|
|
|
|
|
|
// if this isn't a dry run, generate the token
|
|
|
if !isDryRun {
|
|
|
- encoded, err = getToken(config, userID, projectID, clusterID, request)
|
|
|
+ encoded, err = getToken(config, project, userID, projectID, clusterID, request)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, nil, err
|
|
|
@@ -322,6 +325,7 @@ func createGitAction(
|
|
|
|
|
|
func getToken(
|
|
|
config *config.Config,
|
|
|
+ proj *models.Project,
|
|
|
userID, projectID, clusterID uint,
|
|
|
request *types.CreateGitActionConfigRequest,
|
|
|
) (string, error) {
|
|
|
@@ -407,6 +411,10 @@ func getToken(
|
|
|
SecretKey: hashedToken,
|
|
|
}
|
|
|
|
|
|
+ if !proj.APITokensEnabled {
|
|
|
+ return "", fmt.Errorf("api tokens are not enabled for this project")
|
|
|
+ }
|
|
|
+
|
|
|
apiToken, err = config.Repo.APIToken().CreateAPIToken(apiToken)
|
|
|
|
|
|
if err != nil {
|