func()

in config/repository_resource.go [224:280]


func (r *repositoryResource) validate(ctx context.Context) (*ManagedResources, error) {
	var repoFormat string
	switch r.GetRepository().(type) {
	case *agentendpointpb.OSPolicy_Resource_RepositoryResource_Apt:
		if !packages.AptExists {
			return nil, errors.New("cannot manage Apt repository because apt-get does not exist on the system")
		}
		gpgkey := r.GetApt().GetGpgKey()
		r.managedRepository.Apt = &AptRepository{RepositoryResource: r.GetApt()}
		r.managedRepository.RepoFileContents = aptRepoContents(r.GetApt())
		repoFormat = agentconfig.AptRepoFormat()
		if gpgkey != "" {
			entityList, err := fetchGPGKey(gpgkey)
			if err != nil {
				return nil, fmt.Errorf("error fetching apt gpg key %q: %v", gpgkey, err)
			}
			keyContents, err := serializeGPGKeyEntity(entityList)
			if err != nil {
				return nil, fmt.Errorf("error fetching apt gpg key %q: %v", gpgkey, err)
			}

			r.managedRepository.Apt.GpgFileContents = keyContents
			r.managedRepository.Apt.GpgChecksum = checksum(bytes.NewReader(keyContents))
			r.managedRepository.Apt.GpgFilePath = filepath.Join(aptGPGDir, "osconfig_added_"+r.managedRepository.Apt.GpgChecksum+".gpg")
		}

	case *agentendpointpb.OSPolicy_Resource_RepositoryResource_Goo:
		if !packages.GooGetExists {
			return nil, errors.New("cannot manage googet repository because googet does not exist on the system")
		}
		r.managedRepository.GooGet = &GooGetRepository{RepositoryResource: r.GetGoo()}
		r.managedRepository.RepoFileContents = googetRepoContents(r.GetGoo())
		repoFormat = agentconfig.GooGetRepoFormat()

	case *agentendpointpb.OSPolicy_Resource_RepositoryResource_Yum:
		if !packages.YumExists {
			return nil, errors.New("cannot manage yum repository because yum does not exist on the system")
		}
		r.managedRepository.Yum = &YumRepository{RepositoryResource: r.GetYum()}
		r.managedRepository.RepoFileContents = yumRepoContents(r.GetYum())
		repoFormat = agentconfig.YumRepoFormat()

	case *agentendpointpb.OSPolicy_Resource_RepositoryResource_Zypper:
		if !packages.ZypperExists {
			return nil, errors.New("cannot manage zypper repository because zypper does not exist on the system")
		}
		r.managedRepository.Zypper = &ZypperRepository{RepositoryResource: r.GetZypper()}
		r.managedRepository.RepoFileContents = zypperRepoContents(r.GetZypper())
		repoFormat = agentconfig.ZypperRepoFormat()
	default:
		return nil, fmt.Errorf("Repository field not set or references unknown repository type: %v", r.GetRepository())
	}

	r.managedRepository.RepoChecksum = checksum(bytes.NewReader(r.managedRepository.RepoFileContents))
	r.managedRepository.RepoFilePath = fmt.Sprintf(repoFormat, r.managedRepository.RepoChecksum[:10])
	return &ManagedResources{Repositories: []ManagedRepository{r.managedRepository}}, nil
}