MCPcopy Index your code
hub / github.com/aptly-dev/aptly / apiMirrorsCreate

Function apiMirrorsCreate

api/mirror.go:135–201  ·  view source on GitHub ↗

@Summary Create Mirror @Description **Create a mirror of a remote repository** @Tags Mirrors @Consume json @Param request body mirrorCreateParams true "Parameters" @Produce json @Success 200 {object} deb.RemoteRepo @Failure 400 {object} Error "Bad Request" @Router /api/mirrors [post]

(c *gin.Context)

Source from the content-addressed store, hash-verified

133// @Failure 400 {object} Error "Bad Request"
134// @Router /api/mirrors [post]
135func apiMirrorsCreate(c *gin.Context) {
136 var err error
137 var b mirrorCreateParams
138
139 b.DownloadSources = context.Config().DownloadSourcePackages
140 b.IgnoreSignatures = context.Config().GpgDisableVerify
141 b.Architectures = context.ArchitecturesList()
142
143 if c.Bind(&b) != nil {
144 return
145 }
146
147 collectionFactory := context.NewCollectionFactory()
148 collection := collectionFactory.RemoteRepoCollection()
149
150 if strings.HasPrefix(b.ArchiveURL, "ppa:") {
151 b.ArchiveURL, b.Distribution, b.Components, err = deb.ParsePPA(b.ArchiveURL, context.Config())
152 if err != nil {
153 AbortWithJSONError(c, 400, err)
154 return
155 }
156 }
157
158 if b.Filter != "" {
159 _, err = query.Parse(b.Filter)
160 if err != nil {
161 AbortWithJSONError(c, 400, fmt.Errorf("unable to create mirror: %s", err))
162 return
163 }
164 }
165
166 repo, err := deb.NewRemoteRepo(b.Name, b.ArchiveURL, b.Distribution, b.Components, b.Architectures,
167 b.DownloadSources, b.DownloadUdebs, b.DownloadInstaller, b.DownloadAppStream)
168
169 if err != nil {
170 AbortWithJSONError(c, 400, fmt.Errorf("unable to create mirror: %s", err))
171 return
172 }
173
174 repo.Filter = b.Filter
175 repo.FilterWithDeps = b.FilterWithDeps
176 repo.SkipComponentCheck = b.SkipComponentCheck
177 repo.SkipArchitectureCheck = b.SkipArchitectureCheck
178 repo.DownloadSources = b.DownloadSources
179 repo.DownloadUdebs = b.DownloadUdebs
180
181 verifier, err := getVerifier(b.Keyrings)
182 if err != nil {
183 AbortWithJSONError(c, 400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
184 return
185 }
186
187 downloader := context.NewDownloader(nil)
188 err = repo.Fetch(downloader, verifier, b.IgnoreSignatures)
189 if err != nil {
190 AbortWithJSONError(c, 400, fmt.Errorf("unable to fetch mirror: %s", err))
191 return
192 }

Callers

nothing calls this directly

Calls 13

RemoteRepoCollectionMethod · 0.95
FetchMethod · 0.95
ParsePPAFunction · 0.92
ParseFunction · 0.92
NewRemoteRepoFunction · 0.92
AbortWithJSONErrorFunction · 0.85
ConfigMethod · 0.80
ArchitecturesListMethod · 0.80
NewCollectionFactoryMethod · 0.80
NewDownloaderMethod · 0.80
getVerifierFunction · 0.70
HasPrefixMethod · 0.65

Tested by

no test coverage detected