Skip to content

Commit

Permalink
replicas and other resources with same prefix (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolte authored Oct 3, 2020
1 parent 10f8376 commit 707d052
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
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

0 comments on commit 707d052

Please sign in to comment.