Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect Group Policies for sources #3367

Merged
merged 3 commits into from
Jun 21, 2023
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
5 changes: 5 additions & 0 deletions src/AppInstallerCLITests/TestSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ namespace TestCommon
}
}

std::string_view TestSourceFactory::TypeName() const
{
return "*TestSource"sv;
}

std::shared_ptr<ISourceReference> TestSourceFactory::Create(const SourceDetails& details)
{
if (OnOpenWithCustomHeader)
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLITests/TestSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace TestCommon
TestSourceFactory(OpenFunctorWithCustomHeader open) : OnOpenWithCustomHeader(std::move(open)) {}

// ISourceFactory
std::string_view TypeName() const override;
std::shared_ptr<AppInstaller::Repository::ISourceReference> Create(const AppInstaller::Repository::SourceDetails& details) override;
bool Add(AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override;
bool Update(const AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ namespace AppInstaller::Repository::Microsoft
// The actual factory implementation.
struct ConfigurableTestSourceFactoryImpl : public ISourceFactory
{
std::string_view TypeName() const override final
{
return ConfigurableTestSourceFactory::Type();
}

std::shared_ptr<ISourceReference> Create(const SourceDetails& details) override final
{
return std::make_shared<ConfigurableTestSourceReference>(details);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ namespace AppInstaller::Repository::Microsoft
// The base class for a package that comes from a preindexed packaged source.
struct PreIndexedFactoryBase : public ISourceFactory
{
std::string_view TypeName() const override final
{
return PreIndexedPackageSourceFactory::Type();
}

std::shared_ptr<ISourceReference> Create(const SourceDetails& details) override final
{
// With more than one source implementation, we will probably need to probe first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ namespace AppInstaller::Repository::Microsoft
// The factory for the predefined installed source.
struct Factory : public ISourceFactory
{
std::string_view TypeName() const override final
{
return PredefinedInstalledSourceFactory::Type();
}

std::shared_ptr<ISourceReference> Create(const SourceDetails& details) override final
{
THROW_HR_IF(E_INVALIDARG, details.Type != PredefinedInstalledSourceFactory::Type());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace AppInstaller::Repository::Microsoft
// The factory for the predefined installing source.
struct PredefinedWriteableSourceFactoryImpl : public ISourceFactory
{
std::string_view TypeName() const override final
{
return PredefinedWriteableSourceFactory::Type();
}

std::shared_ptr<ISourceReference> Create(const SourceDetails& details) override final;

bool Add(SourceDetails&, IProgressCallback&) override final
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ namespace AppInstaller::Repository

struct PackageTrackingCatalogSourceFactoryImpl : public ISourceFactory
{
std::string_view TypeName() const override final
{
return PackageTrackingCatalogSourceFactory::Type();
}

std::shared_ptr<ISourceReference> Create(const SourceDetails& details) override final
{
THROW_HR_IF(E_INVALIDARG, !Utility::CaseInsensitiveEquals(details.Type, PackageTrackingCatalogSourceFactory::Type()));
Expand Down
9 changes: 9 additions & 0 deletions src/AppInstallerRepositoryCore/RepositorySource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ namespace AppInstaller::Repository

Source::Source(WellKnownSource source)
{
THROW_HR_IF(APPINSTALLER_CLI_ERROR_BLOCKED_BY_POLICY, !IsWellKnownSourceEnabled(source));

SourceDetails details = GetWellKnownSourceDetailsInternal(source);
m_sourceReferences.emplace_back(CreateSourceFromDetails(details));
}
Expand Down Expand Up @@ -601,6 +603,13 @@ namespace AppInstaller::Repository

auto& sourceDetails = m_sourceReferences[0]->GetDetails();

// If the source type is empty, use a default.
// AddSourceForDetails will also check for empty, but we need the actual type before that for validation.
if (sourceDetails.Type.empty())
{
sourceDetails.Type = ISourceFactory::GetForType("")->TypeName();
}

AICLI_LOG(Repo, Info, << "Adding source: Name[" << sourceDetails.Name << "], Type[" << sourceDetails.Type << "], Arg[" << sourceDetails.Arg << "]");

// Check all sources for the given name.
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerRepositoryCore/Rest/RestSourceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ namespace AppInstaller::Repository::Rest
// The base class for data that comes from a rest based source.
struct RestSourceFactoryImpl : public ISourceFactory
{
std::string_view TypeName() const override final
{
return RestSourceFactory::Type();
}

std::shared_ptr<ISourceReference> Create(const SourceDetails& details) override final
{
THROW_HR_IF(E_INVALIDARG, !Utility::CaseInsensitiveEquals(details.Type, RestSourceFactory::Type()));
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerRepositoryCore/SourceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace AppInstaller::Repository
{
virtual ~ISourceFactory() = default;

// Gets the name of the source type.
virtual std::string_view TypeName() const = 0;

// Creates a source object from the given details.
virtual std::shared_ptr<ISourceReference> Create(const SourceDetails& details) = 0;

Expand Down
Loading