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

OSPolicies: correct apt repo extension, remove yum/zypper gpgcheck override #301

Merged
merged 1 commit into from
Mar 31, 2021
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: 2 additions & 2 deletions agentconfig/agentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func YumRepoDir() string {
return yumRepoDir
}

// YumRepoFilePath is the location where the zypper repo file will be created.
// YumRepoFilePath is the location where the yum repo file will be created.
func YumRepoFilePath() string {
return getAgentConfig().yumRepoFilePath
}
Expand All @@ -511,7 +511,7 @@ func AptRepoDir() string {
return aptRepoDir
}

// AptRepoFilePath is the location where the zypper repo file will be created.
// AptRepoFilePath is the location where the apt repo file will be created.
func AptRepoFilePath() string {
return getAgentConfig().aptRepoFilePath
}
Expand Down
8 changes: 3 additions & 5 deletions config/repository_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func yumRepoContents(repo *agentendpointpb.OSPolicy_Resource_RepositoryResource_
baseurl=https://repo-url
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://repo-url/gpg1
http://repo-url/gpg2
*/
Expand All @@ -138,7 +137,7 @@ func yumRepoContents(repo *agentendpointpb.OSPolicy_Resource_RepositoryResource_
buf.WriteString(fmt.Sprintf("name=%s\n", repo.DisplayName))
}
buf.WriteString(fmt.Sprintf("baseurl=%s\n", repo.BaseUrl))
buf.WriteString("enabled=1\ngpgcheck=1\nrepo_gpgcheck=1\n")
buf.WriteString("enabled=1\ngpgcheck=1\n")
if len(repo.GpgKeys) > 0 {
buf.WriteString(fmt.Sprintf("gpgkey=%s\n", repo.GpgKeys[0]))
for _, k := range repo.GpgKeys[1:] {
Expand All @@ -156,7 +155,6 @@ func zypperRepoContents(repo *agentendpointpb.OSPolicy_Resource_RepositoryResour
baseurl=https://repo-url
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://repo-url/gpg1
http://repo-url/gpg2
*/
Expand All @@ -169,7 +167,7 @@ func zypperRepoContents(repo *agentendpointpb.OSPolicy_Resource_RepositoryResour
buf.WriteString(fmt.Sprintf("name=%s\n", repo.DisplayName))
}
buf.WriteString(fmt.Sprintf("baseurl=%s\n", repo.BaseUrl))
buf.WriteString("enabled=1\ngpgcheck=1\nrepo_gpgcheck=1\n")
buf.WriteString("enabled=1\ngpgcheck=1\n")
if len(repo.GpgKeys) > 0 {
buf.WriteString(fmt.Sprintf("gpgkey=%s\n", repo.GpgKeys[0]))
for _, k := range repo.GpgKeys[1:] {
Expand Down Expand Up @@ -225,7 +223,7 @@ func (r *repositoryResource) validate(ctx context.Context) (*ManagedResources, e
gpgkey := r.GetApt().GetGpgKey()
r.managedRepository.Apt = &AptRepository{RepositoryResource: r.GetApt()}
r.managedRepository.RepoFileContents = aptRepoContents(r.GetApt())
filePath = filepath.Join(agentconfig.AptRepoDir(), "osconfig_managed_%s.repo")
filePath = filepath.Join(agentconfig.AptRepoDir(), "osconfig_managed_%s.list")
if gpgkey != "" {
keyContents, err := fetchGPGKey(gpgkey)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions config/repository_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestRepositoryResourceValidate(t *testing.T) {
},
RepoChecksum: "8faacd43b230b08e7a1da7b670bf6f90fcc59ade1a5e7179a0ccffc9aa3d7cdf",
RepoFileContents: []byte("# Repo file managed by Google OSConfig agent\ndeb uri distribution c1 c2\n"),
RepoFilePath: "/etc/apt/sources.list.d/osconfig_managed_8faacd43b2.repo",
RepoFilePath: "/etc/apt/sources.list.d/osconfig_managed_8faacd43b2.list",
},
},
{
Expand Down Expand Up @@ -101,9 +101,9 @@ func TestRepositoryResourceValidate(t *testing.T) {
Yum: &YumRepository{
RepositoryResource: yumRepositoryResource,
},
RepoChecksum: "9eddc09d15a4e9b515068cffb2e0640dab010ccd9cb0eeb63b8c455e06696656",
RepoFileContents: []byte("# Repo file managed by Google OSConfig agent\n[id]\nname=displayname\nbaseurl=baseurl\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=key1\n key2\n"),
RepoFilePath: "/etc/yum.repos.d/osconfig_managed_9eddc09d15.repo",
RepoChecksum: "c588551e69834e5f2f4d825324b2add5df3064af7d5d68021e83a308c6f62048",
RepoFileContents: []byte("# Repo file managed by Google OSConfig agent\n[id]\nname=displayname\nbaseurl=baseurl\nenabled=1\ngpgcheck=1\ngpgkey=key1\n key2\n"),
RepoFilePath: "/etc/yum.repos.d/osconfig_managed_c588551e69.repo",
},
},
{
Expand All @@ -117,9 +117,9 @@ func TestRepositoryResourceValidate(t *testing.T) {
Zypper: &ZypperRepository{
RepositoryResource: zypperRepositoryResource,
},
RepoChecksum: "9eddc09d15a4e9b515068cffb2e0640dab010ccd9cb0eeb63b8c455e06696656",
RepoFileContents: []byte("# Repo file managed by Google OSConfig agent\n[id]\nname=displayname\nbaseurl=baseurl\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=key1\n key2\n"),
RepoFilePath: "/etc/zypp/repos.d/osconfig_managed_9eddc09d15.repo",
RepoChecksum: "c588551e69834e5f2f4d825324b2add5df3064af7d5d68021e83a308c6f62048",
RepoFileContents: []byte("# Repo file managed by Google OSConfig agent\n[id]\nname=displayname\nbaseurl=baseurl\nenabled=1\ngpgcheck=1\ngpgkey=key1\n key2\n"),
RepoFilePath: "/etc/zypp/repos.d/osconfig_managed_c588551e69.repo",
},
},
}
Expand Down