-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcommon.go
More file actions
55 lines (47 loc) · 1.68 KB
/
common.go
File metadata and controls
55 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package realtimeengine
import (
"os"
"github.com/checkmarx/ast-cli/internal/params"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/pkg/errors"
)
// IsFeatureFlagEnabled checks if a specific feature flag is enabled.
func IsFeatureFlagEnabled(flagWrapper wrappers.FeatureFlagsWrapper, flagName string) (bool, error) {
enabled, err := flagWrapper.GetSpecificFlag(flagName)
if err != nil {
return false, errors.Wrap(err, "failed to get feature flag")
}
return enabled.Status, nil
}
// EnsureLicense validates that a valid JWT wrapper is available.
func EnsureLicense(jwtWrapper wrappers.JWTWrapper) error {
if jwtWrapper == nil {
return errors.New("JWT wrapper is not initialized, cannot ensure license")
}
assistAllowed, err := jwtWrapper.IsAllowedEngine(params.CheckmarxOneAssistType)
if err != nil {
return errors.Wrap(err, "failed to check CheckmarxOneAssistType engine allowance")
}
aiAllowed, err := jwtWrapper.IsAllowedEngine(params.AIProtectionType)
if err != nil {
return errors.Wrap(err, "failed to check AIProtectionType engine allowance")
}
if aiAllowed || assistAllowed {
return nil
}
return errors.Wrap(err, "user does not have \"Checkmarx One Assist\" or \"AI Protection\" license")
}
// ValidateFilePath validates that the file path exists and is accessible.
func ValidateFilePath(filePath string) error {
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return errors.Errorf("file does not exist: %s", filePath)
}
fileInfo, err := os.Stat(filePath)
if err != nil {
return errors.Errorf("cannot access file: %s", filePath)
}
if fileInfo.IsDir() {
return errors.Errorf("path is a directory, expected a file: %s", filePath)
}
return nil
}