-
Notifications
You must be signed in to change notification settings - Fork 100
/
resource_artifactory_remote_docker_repository.go
81 lines (74 loc) · 3.3 KB
/
resource_artifactory_remote_docker_repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package artifactory
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type DockerRemoteRepository struct {
RemoteRepositoryBaseParams
ExternalDependenciesEnabled bool `hcl:"external_dependencies_enabled" json:"externalDependenciesEnabled"`
ExternalDependenciesPatterns []string `hcl:"external_dependencies_patterns" json:"externalDependenciesPatterns"`
EnableTokenAuthentication bool `hcl:"enable_token_authentication" json:"enableTokenAuthentication"`
BlockPushingSchema1 bool `hcl:"block_pushing_schema1" json:"blockPushingSchema1"`
}
func resourceArtifactoryRemoteDockerRepository() *schema.Resource {
const packageType = "docker"
var dockerRemoteSchema = mergeSchema(baseRemoteRepoSchema, map[string]*schema.Schema{
"external_dependencies_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Also known as 'Foreign Layers Caching' on the UI",
},
"enable_token_authentication": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Enable token (Bearer) based authentication.",
},
"block_pushing_schema1": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "When set, Artifactory will block the pulling of Docker images with manifest v2 schema 1 from the remote repository (i.e. the upstream). It will be possible to pull images with manifest v2 schema 1 that exist in the cache.",
},
"external_dependencies_patterns": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
RequiredWith: []string{"external_dependencies_enabled"},
Description: "An allow list of Ant-style path patterns that determine which remote VCS roots Artifactory will " +
"follow to download remote modules from, when presented with 'go-import' meta tags in the remote repository response. " +
"By default, this is set to '**', which means that remote modules may be downloaded from any external VCS source.",
},
}, repoLayoutRefSchema("remote", packageType))
var unpackDockerRemoteRepo = func(s *schema.ResourceData) (interface{}, string, error) {
d := &ResourceData{s}
repo := DockerRemoteRepository{
RemoteRepositoryBaseParams: unpackBaseRemoteRepo(s, packageType),
EnableTokenAuthentication: d.getBool("enable_token_authentication", false),
ExternalDependenciesEnabled: d.getBool("external_dependencies_enabled", false),
BlockPushingSchema1: d.getBool("block_pushing_schema1", false),
ExternalDependenciesPatterns: d.getList("external_dependencies_patterns"),
}
if len(repo.ExternalDependenciesPatterns) == 0 {
repo.ExternalDependenciesPatterns = []string{"**"}
}
return repo, repo.Id(), nil
}
// Special handling for "external_dependencies_patterns" attribute to match default value behavior in UI.
dockerRemoteRepoPacker := universalPack(
allHclPredicate(
ignoreHclPredicate("class", "rclass", "external_dependencies_patterns"),
schemaHasKey(dockerRemoteSchema),
),
)
return mkResourceSchema(dockerRemoteSchema, dockerRemoteRepoPacker, unpackDockerRemoteRepo, func() interface{} {
return &DockerRemoteRepository{
RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{
Rclass: "remote",
PackageType: packageType,
},
}
})
}