forked from atlassian/terraform-provider-artifactory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a second datasource that can be used to access file infos only
- Loading branch information
1 parent
3c21e86
commit ced27f4
Showing
3 changed files
with
117 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package artifactory | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/atlassian/go-artifactory/v2/artifactory" | ||
"github.com/atlassian/go-artifactory/v2/artifactory/v1" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceArtifactoryFileInfo() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceFileInfoRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"repository": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"path": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"created": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_by": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_modified": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"modified_by": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_updated": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"download_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"mimetype": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"size": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"md5": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sha1": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sha256": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceFileInfoRead(d *schema.ResourceData, m interface{}) error { | ||
c := m.(*artifactory.Artifactory) | ||
|
||
repository := d.Get("repository").(string) | ||
path := d.Get("path").(string) | ||
|
||
fileInfo, _, err := c.V1.Artifacts.FileInfo(context.Background(), repository, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return packFileInfo(fileInfo, d) | ||
} | ||
|
||
func packFileInfo(fileInfo *v1.FileInfo, d *schema.ResourceData) error { | ||
hasErr := false | ||
logErr := cascadingErr(&hasErr) | ||
|
||
d.SetId(*fileInfo.DownloadUri) | ||
|
||
logErr(d.Set("created", *fileInfo.Created)) | ||
logErr(d.Set("created_by", *fileInfo.CreatedBy)) | ||
logErr(d.Set("last_modified", *fileInfo.LastModified)) | ||
logErr(d.Set("modified_by", *fileInfo.ModifiedBy)) | ||
logErr(d.Set("last_updated", *fileInfo.LastUpdated)) | ||
logErr(d.Set("download_uri", *fileInfo.DownloadUri)) | ||
logErr(d.Set("mimetype", *fileInfo.MimeType)) | ||
logErr(d.Set("size", *fileInfo.Size)) | ||
|
||
if fileInfo.Checksums != nil { | ||
logErr(d.Set("md5", *fileInfo.Checksums.Md5)) | ||
logErr(d.Set("sha1", *fileInfo.Checksums.Sha1)) | ||
logErr(d.Set("sha256", *fileInfo.Checksums.Sha256)) | ||
} | ||
|
||
if hasErr { | ||
return fmt.Errorf("failed to pack fileInfo") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters