Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# FOSSA CLI Changelog
## 3.11.9

- Get the snippet-scan-retention-days setting from an organization, and pass it into Ficus ([#1586](https://github.com/fossas/fossa-cli/pull/1586))

## 3.11.8

- Update latest version of a dependency for `--x-snippet-scan`. This change outputs errors from the snippet scanning CLI so that we can debug more easily ([#1587](https://github.com/fossas/fossa-cli/pull/1587))
Expand Down
2 changes: 1 addition & 1 deletion integration-test/Analysis/FicusSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec = do
testDataExists <- PIO.doesDirExist testDataDir
testDataExists `shouldBe` True

result <- runStack . runDiagnostics . ignoreStickyLogger . ignoreLogger . runExecIO . runReadFSIO $ analyzeWithFicus testDataDir apiOpts revision Nothing
result <- runStack . runDiagnostics . ignoreStickyLogger . ignoreLogger . runExecIO . runReadFSIO $ analyzeWithFicus testDataDir apiOpts revision Nothing (Just 10)

case result of
Success _warnings analysisResult -> do
Expand Down
4 changes: 2 additions & 2 deletions src/App/Fossa/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import Effect.Logger (
)
import Effect.ReadFS (ReadFS)
import Errata (Errata (..))
import Fossa.API.Types (Organization (Organization, orgSupportsReachability))
import Fossa.API.Types (Organization (Organization, orgSnippetScanSourceCodeRetentionDays, orgSupportsReachability))
import Path (Abs, Dir, Path, toFilePath)
import Path.IO (makeRelative)
import Prettyprinter (
Expand Down Expand Up @@ -348,7 +348,7 @@ analyze cfg = Diag.context "fossa-analyze" $ do
then do
logInfo "Running in VSI only mode, skipping snippet-scan"
pure Nothing
else Diag.context "snippet-scanning" . runStickyLogger SevInfo $ analyzeWithFicus basedir maybeApiOpts revision $ Config.licenseScanPathFilters vendoredDepsOptions
else Diag.context "snippet-scanning" . runStickyLogger SevInfo $ analyzeWithFicus basedir maybeApiOpts revision (Config.licenseScanPathFilters vendoredDepsOptions) (orgSnippetScanSourceCodeRetentionDays =<< orgInfo)
let ficusResults = join . resultToMaybe $ maybeFicusResults
maybeLernieResults <-
Diag.errorBoundaryIO . diagToDebug $
Expand Down
12 changes: 8 additions & 4 deletions src/App/Fossa/Ficus/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ analyzeWithFicus ::
Maybe ApiOpts ->
ProjectRevision ->
Maybe LicenseScanPathFilters ->
Maybe Int ->
m (Maybe FicusSnippetScanResults)
analyzeWithFicus rootDir apiOpts revision filters = do
analyzeWithFicusMain rootDir apiOpts revision filters
analyzeWithFicus rootDir apiOpts revision filters snippetScanRetentionDays = do
analyzeWithFicusMain rootDir apiOpts revision filters snippetScanRetentionDays

analyzeWithFicusMain ::
( Has Diagnostics sig m
Expand All @@ -98,8 +99,9 @@ analyzeWithFicusMain ::
Maybe ApiOpts ->
ProjectRevision ->
Maybe LicenseScanPathFilters ->
Maybe Int ->
m (Maybe FicusSnippetScanResults)
analyzeWithFicusMain rootDir apiOpts revision filters = do
analyzeWithFicusMain rootDir apiOpts revision filters snippetScanRetentionDays = do
logDebugWithTime "Preparing Ficus analysis configuration..."
messages <- runFicus ficusConfig
logDebugWithTime "runFicus completed, processing results..."
Expand All @@ -119,6 +121,7 @@ analyzeWithFicusMain rootDir apiOpts revision filters = do
, ficusConfigSecret = apiOptsApiKey <$> apiOpts
, ficusConfigRevision = revision
, ficusConfigFlags = [All $ FicusAllFlag SkipHiddenFiles, All $ FicusAllFlag Gitignore]
, ficusConfigSnippetScanRetentionDays = snippetScanRetentionDays
}

ficusMessagesToFicusSnippetScanResults :: FicusMessages -> Maybe FicusSnippetScanResults
Expand Down Expand Up @@ -273,7 +276,8 @@ ficusCommand ficusConfig bin = do
logDebug $ "Ficus command: " <> pretty (maskApiKeyInCommand $ renderCommand cmd)
pure cmd
where
configArgs endpoint = ["analyze", "--secret", secret, "--endpoint", endpoint, "--locator", locator, "--set", "all:skip-hidden-files", "--set", "all:gitignore", "--exclude", ".git", "--exclude", ".git/**"] ++ configExcludes ++ [targetDir]
snippetScanRetentionDays = ficusConfigSnippetScanRetentionDays ficusConfig
configArgs endpoint = ["analyze", "--secret", secret, "--endpoint", endpoint, "--locator", locator, "--set", "all:skip-hidden-files", "--set", "all:gitignore", "--exclude", ".git", "--exclude", ".git/**"] ++ configExcludes ++ maybe [] (\days -> ["--snippet-scan-retention-days", toText days]) snippetScanRetentionDays ++ [targetDir]
targetDir = toText $ toFilePath $ ficusConfigRootDir ficusConfig
secret = maybe "" (toText . unApiKey) $ ficusConfigSecret ficusConfig
locator = renderLocator $ Locator "custom" (projectName $ ficusConfigRevision ficusConfig) (Just $ projectRevision $ ficusConfigRevision ficusConfig)
Expand Down
1 change: 1 addition & 0 deletions src/App/Fossa/Ficus/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ data FicusConfig = FicusConfig
, ficusConfigSecret :: Maybe ApiKey
, ficusConfigRevision :: ProjectRevision -- TODO: get this from `projectRevision AnalyzeConfig`
, ficusConfigFlags :: [FicusPerStrategyFlag]
, ficusConfigSnippetScanRetentionDays :: Maybe Int
}
deriving (Show, Eq, Generic)

Expand Down
3 changes: 3 additions & 0 deletions src/Fossa/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ data Organization = Organization
, orgSupportsReachability :: Bool
, orgSupportsPreflightChecks :: Bool
, orgSubscription :: Subscription
, orgSnippetScanSourceCodeRetentionDays :: Maybe Int
}
deriving (Eq, Ord, Show)

Expand All @@ -535,6 +536,7 @@ blankOrganization =
, orgSupportsReachability = False
, orgSupportsPreflightChecks = False
, orgSubscription = Free
, orgSnippetScanSourceCodeRetentionDays = Nothing
}

instance FromJSON Organization where
Expand All @@ -556,6 +558,7 @@ instance FromJSON Organization where
<*> obj .:? "supportsReachability" .!= False
<*> obj .:? "supportsPreflightChecks" .!= False
<*> obj .:? "subscription" .!= Free
<*> obj .:? "snippetScanSourceCodeRetentionDays" .!= Nothing

data TokenType
= Push
Expand Down
8 changes: 4 additions & 4 deletions test/App/Fossa/API/BuildLinkSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ spec = do
describe "SAML URL builder" $ do
it' "should render simple locators" $ do
let locator = Locator "fetcher123" "project123" $ Just "revision123"
org = Just $ Organization (OrgId 1) True False True CLILicenseScan True True True False False False False [] False False API.Free
org = Just $ Organization (OrgId 1) True False True CLILicenseScan True True True False False False False [] False False API.Free Nothing
revision = ProjectRevision "" "not this revision" $ Just "master123"
actual <- getBuildURLWithOrg org revision Fixtures.apiOpts locator

actual `shouldBe'` simpleSamlPath

it' "should render git@ locators" $ do
let locator = Locator "fetcher@123/abc" "git@github.com/user/repo" $ Just "revision@123/abc"
org = Just $ Organization (OrgId 103) True False True CLILicenseScan True True True False False False False [] False False API.Free
org = Just $ Organization (OrgId 103) True False True CLILicenseScan True True True False False False False [] False False API.Free Nothing
revision = ProjectRevision "not this project name" "not this revision" $ Just "weird--branch"
actual <- getBuildURLWithOrg org revision Fixtures.apiOpts locator

actual `shouldBe'` gitSamlPath

it' "should render full url correctly" $ do
let locator = Locator "a" "b" $ Just "c"
org = Just $ Organization (OrgId 33) True False True CLILicenseScan True True True False False False False [] False False API.Free
org = Just $ Organization (OrgId 33) True False True CLILicenseScan True True True False False False False [] False False API.Free Nothing
revision = ProjectRevision "" "not this revision" $ Just "master"
actual <- getBuildURLWithOrg org revision Fixtures.apiOpts locator

Expand All @@ -75,7 +75,7 @@ spec = do
describe "Fossa URL Builder" $
it' "should render from API info" $ do
GetApiOpts `returnsOnce` Fixtures.apiOpts
GetOrganization `returnsOnce` Organization (OrgId 1) True False True CLILicenseScan True True True False False False False [] False False API.Free
GetOrganization `returnsOnce` Organization (OrgId 1) True False True CLILicenseScan True True True False False False False [] False False API.Free Nothing
let locator = Locator "fetcher123" "project123" $ Just "revision123"
revision = ProjectRevision "" "not this revision" $ Just "master123"
actual <- getFossaBuildUrl revision locator
Expand Down
3 changes: 3 additions & 0 deletions test/Test/Fixtures.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ organization =
, orgSupportsReachability = False
, orgSupportsPreflightChecks = False
, orgSubscription = Free
, orgSnippetScanSourceCodeRetentionDays = Nothing
}

organizationWithPreflightChecks :: API.Organization
Expand All @@ -164,6 +165,7 @@ organizationWithPreflightChecks =
, orgSupportsReachability = False
, orgSupportsPreflightChecks = True
, orgSubscription = Free
, orgSnippetScanSourceCodeRetentionDays = Nothing
}

organizationWithPremiumSubscription :: API.Organization
Expand All @@ -185,6 +187,7 @@ organizationWithPremiumSubscription =
, orgSupportsReachability = False
, orgSupportsPreflightChecks = True
, orgSubscription = Premium
, orgSnippetScanSourceCodeRetentionDays = Nothing
}

pushToken :: API.TokenTypeResponse
Expand Down
Loading