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

replicas and other resources with same prefix #82

Merged
merged 12 commits into from
Oct 3, 2020
11 changes: 5 additions & 6 deletions harbor/resource_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ func findLabelByNameAndScope(d *schema.ResourceData, m interface{}) (*models.Lab
return &models.Label{}, err
}

if len(resp.Payload) < 1 {
return &models.Label{}, fmt.Errorf("no label found with name %v", searchName)
} else if resp.Payload[0].Name != searchName {
return &models.Label{},
fmt.Errorf("response Name %v not match with Expected Name %v", resp.Payload[0].Name, searchName)
for _, element := range resp.Payload {
if element.Name == searchName {
return element, nil
}
}

return resp.Payload[0], nil
return &models.Label{}, fmt.Errorf("no label found with name %v", searchName)
}
}

Expand Down
12 changes: 5 additions & 7 deletions harbor/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,13 @@ func findProjectByName(d *schema.ResourceData, m interface{}) (*models.Project,
d.SetId("")
return &models.Project{}, err
}

if len(resp.Payload) < 1 {
return &models.Project{}, fmt.Errorf("no project found with name %v", projectName)
} else if resp.Payload[0].Name != projectName {
return &models.Project{},
fmt.Errorf("response Name %v not match with Expected Name %v", resp.Payload[0].Name, projectName)
for _, element := range resp.Payload {
if element.Name == projectName {
return element, nil
}
}

return resp.Payload[0], nil
return &models.Project{}, fmt.Errorf("no project found with name %v", projectName)
}

return &models.Project{}, fmt.Errorf("fail to lookup project by Name")
Expand Down
13 changes: 5 additions & 8 deletions harbor/resource_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,12 @@ func findRegistryByName(d *schema.ResourceData, m interface{}) (*models.Registry
d.SetId("")
return &models.Registry{}, err
}

if len(resp.Payload) < 1 {
return &models.Registry{}, fmt.Errorf("no Registry found with name %v", registryName)
} else if resp.Payload[0].Name != registryName {
return &models.Registry{},
fmt.Errorf("response Name %v not match with Expected Name %v", resp.Payload[0].Name, registryName)
for _, element := range resp.Payload {
if element.Name == registryName {
return element, nil
}
}

return resp.Payload[0], nil
return &models.Registry{}, fmt.Errorf("no Registry found with name %v", registryName)
}

return &models.Registry{}, fmt.Errorf("fail to lookup Registry by Name")
Expand Down
13 changes: 5 additions & 8 deletions harbor/resource_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,12 @@ func findReplicationByName(d *schema.ResourceData, m interface{}) (*models.Repli
d.SetId("")
return &models.ReplicationPolicy{}, err
}

if len(resp.Payload) < 1 {
return &models.ReplicationPolicy{}, fmt.Errorf("no Replication found with name %v", registryName)
} else if resp.Payload[0].Name != registryName {
return &models.ReplicationPolicy{},
fmt.Errorf("response Name %v not match with Expected Name %v", resp.Payload[0].Name, registryName)
for _, element := range resp.Payload {
if element.Name == registryName {
return element, nil
}
}

return resp.Payload[0], nil
return &models.ReplicationPolicy{}, fmt.Errorf("no Replication found with name %v", registryName)
}

return &models.ReplicationPolicy{}, fmt.Errorf("fail to lookup Replication by Name")
Expand Down