Skip to content

Commit

Permalink
PTRENG-2827 - all references to atlassian are removed (not just for a…
Browse files Browse the repository at this point in the history
…ccess tokens). We took the extra step of simplifying client access too
  • Loading branch information
Christian Bongiorno committed Sep 4, 2021
1 parent 36cd6eb commit 4b46eb8
Show file tree
Hide file tree
Showing 27 changed files with 331 additions and 327 deletions.
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2019 Atlassian Pty Ltd
Copyright 2020 JFrog Ltd

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ and is willing to have it used in distributions and derivative works
[Sign the CLA](https://cla-assistant.io/jfrog/terraform-provider-artifactory)

## License
Copyright (c) 2019 Atlassian and others.
Copyright (c) 2020 JFrog.

Apache 2.0 licensed, see [LICENSE][LICENSE] file.
Expand Down
18 changes: 1 addition & 17 deletions docs/resources/artifactory_permission_target.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Artifactory Permission Target Resource

**Requires Artifactory >= 6.6.0.**

***permissions target V1 is no longer supported***
**Requires Artifactory >= 6.6.0. If using a lower version see [here](./artifactory_permission_target_v1.md)**

Provides an Artifactory permission target resource. This can be used to create and manage Artifactory permission targets.

Expand Down Expand Up @@ -42,18 +40,6 @@ resource "artifactory_permission_target" "test-perm" {
}
}
}
release_bundle {
includes_pattern = ["**"]
repositories = ["example-repo-local"]
actions {
users {
name = "anonymous"
permissions = ["read", "write"]
}
}
}
}
```

Expand All @@ -70,9 +56,7 @@ The following arguments are supported:
* `users` - (Optional) Users this permission target applies for.
* `groups` - (Optional) Groups this permission applies for.
* `build` - (Optional) As for repo but for artifactory-build-info permssions.
* `release_bundle` - (Optional)

Please see the docs [here](https://www.jfrog.com/confluence/display/JFROG/Security+Configuration+JSON#SecurityConfigurationJSON-application/vnd.org.jfrog.artifactory.security.PermissionTarget+json)
## Import

Permission targets can be imported using their name, e.g.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/jfrog/terraform-provider-artifactory

require (
github.com/atlassian/go-artifactory/v2 v2.5.0
github.com/go-resty/resty/v2 v2.4.0
github.com/google/go-querystring v1.0.0
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.7.0
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/atlassian/go-artifactory/v2 v2.3.0/go.mod h1:mMEbxu89yTyKev4mysL03aSioTEdZ8+08KuMGG7myUY=
github.com/atlassian/go-artifactory/v2 v2.5.0 h1:NKs9kuGgb2Gj+pU+Y7BzFlx6D/e6P82zP3m/FJZpy40=
github.com/atlassian/go-artifactory/v2 v2.5.0/go.mod h1:mMEbxu89yTyKev4mysL03aSioTEdZ8+08KuMGG7myUY=
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.25.3 h1:uM16hIw9BotjZKMZlX05SN2EFtaWfi/NonPKIARiBLQ=
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
Expand Down
7 changes: 3 additions & 4 deletions pkg/artifactory/datasource_artifactory_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/go-resty/resty/v2"
"io"
"os"

Expand Down Expand Up @@ -102,14 +103,12 @@ func dataSourceArtifactoryFile() *schema.Resource {
}

func dataSourceFileRead(d *schema.ResourceData, m interface{}) error {
client := m.(*ArtClient).Resty

repository := d.Get("repository").(string)
path := d.Get("path").(string)
outputPath := d.Get("output_path").(string)
forceOverwrite := d.Get("force_overwrite").(bool)
fileInfo := FileInfo{}
_,err := client.R().SetResult(&fileInfo).Get(fmt.Sprintf("artifactory/api/storage/%s/%s", repository, path))
_,err := m.(*resty.Client).R().SetResult(&fileInfo).Get(fmt.Sprintf("artifactory/api/storage/%s/%s", repository, path))
if err != nil {
return err
}
Expand All @@ -129,7 +128,7 @@ func dataSourceFileRead(d *schema.ResourceData, m interface{}) error {
_ = outFile.Close()
}(outFile)

_, err = client.R().SetOutput(outputPath).Get(fileInfo.DownloadUri)
_, err = m.(*resty.Client).R().SetOutput(outputPath).Get(fileInfo.DownloadUri)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/artifactory/datasource_artifactory_fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package artifactory

import (
"fmt"
"github.com/go-resty/resty/v2"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down Expand Up @@ -67,13 +68,11 @@ func dataSourceArtifactoryFileInfo() *schema.Resource {
}

func dataSourceFileInfoRead(d *schema.ResourceData, m interface{}) error {
c := m.(*ArtClient).Resty

repository := d.Get("repository").(string)
path := d.Get("path").(string)

fileInfo := FileInfo{}
_, err := c.R().SetResult(&fileInfo).Get(fmt.Sprintf("artifactory/api/storage/%s/%s", repository, path))
_, err := m.(*resty.Client).R().SetResult(&fileInfo).Get(fmt.Sprintf("artifactory/api/storage/%s/%s", repository, path))
if err != nil {
return err
}
Expand Down
91 changes: 45 additions & 46 deletions pkg/artifactory/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ package artifactory

import (
"fmt"
artifactoryold "github.com/atlassian/go-artifactory/v2/artifactory"
"github.com/go-resty/resty/v2"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/jasonwbarnett/go-xray/xray"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
"github.com/jfrog/jfrog-client-go/utils/log"
"net/http"
"net/url"
)



var Version = "2.2.16"

const repositoriesEndpoint = "artifactory/api/repositories/"

type ArtClient struct {
ArtOld *artifactoryold.Artifactory

ArtNew *jfroghttpclient.JfrogHttpClient
Xray *xray.Xray
Resty *resty.Client
Expand All @@ -32,28 +29,28 @@ func Provider() terraform.ResourceProvider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_URL", func() (interface{}, error) {
return "http://localhost:8082",nil
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_URL", func() (interface{}, error) {
return "http://localhost:8082", nil
}),
ValidateFunc: validation.IsURLWithHTTPorHTTPS,
},
"username": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_USERNAME", func() (interface{}, error) {
return "admin",nil
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_USERNAME", func() (interface{}, error) {
return "admin", nil
}),
ConflictsWith: []string{"access_token", "api_key"},
ValidateFunc: validation.StringIsNotEmpty,
},
"password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_PASSWORD", func() (interface{}, error) {
return "password",nil
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_PASSWORD", func() (interface{}, error) {
return "password", nil
}),
ConflictsWith: []string{"access_token", "api_key"},
ValidateFunc: validation.StringIsNotEmpty,
Expand Down Expand Up @@ -111,15 +108,9 @@ func Provider() terraform.ResourceProvider {
return p
}

func buildResty(d *schema.ResourceData, terraformVersion string) (*resty.Client, error) {
func buildResty(URL string) (*resty.Client, error) {

if key, ok := d.GetOk("url"); key == nil || key == "" || !ok {
return nil, fmt.Errorf("you must supply a URL")
}

log.SetLogger(log.NewLogger(log.INFO, nil))

u, err := url.ParseRequestURI(d.Get("url").(string))
u, err := url.ParseRequestURI(URL)

if err != nil {
return nil, err
Expand All @@ -134,48 +125,56 @@ func buildResty(d *schema.ResourceData, terraformVersion string) (*resty.Client,
}
return nil
}).
SetHeader("content-type", "application/json").
SetHeader("accept", "*/*").
SetHeader("user-agent", "jfrog/terraform-provider-artifactory:"+Version)
SetHeader("content-type", "application/json").
SetHeader("accept", "*/*").
SetHeader("user-agent", "jfrog/terraform-provider-artifactory:"+Version)
restyBase.DisableWarn = true
return restyBase, nil

username := d.Get("username").(string)
password := d.Get("password").(string)
apiKey := d.Get("api_key").(string)
accessToken := d.Get("access_token").(string)
}

func addAuthToResty(client *resty.Client, username, password, apiKey, accessToken string) (*resty.Client, error) {

if username != "" && password != "" {
restyBase = restyBase.SetBasicAuth(username, password)
return client.SetBasicAuth(username, password), nil
}
if apiKey != "" {
restyBase = restyBase.SetHeader("X-JFrog-Art-Api", apiKey)
return client.SetHeader("X-JFrog-Art-Api", apiKey), nil
}
if accessToken != "" {
restyBase = restyBase.SetAuthToken(accessToken)
return client.SetAuthToken(accessToken), nil
}
restyBase.DisableWarn = true
return restyBase, nil
return nil, fmt.Errorf("no authentication details supplied")
}

// Creates the client for artifactory, will prefer token auth over basic auth if both set
func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
restyBase, err := buildResty(d, terraformVersion)
URL, ok := d.GetOk("url")
if URL == nil || URL == "" || !ok {
return nil, fmt.Errorf("you must supply a URL")
}

restyBase, err := buildResty(URL.(string))
if err != nil {
return nil, err
}
_, err = sendUsageRepo(restyBase, terraformVersion)
username := d.Get("username").(string)
password := d.Get("password").(string)
apiKey := d.Get("api_key").(string)
accessToken := d.Get("access_token").(string)

restyBase, err = addAuthToResty(restyBase, username, password, apiKey, accessToken)
if err != nil {
return nil, err
}
_, err = sendUsageRepo(restyBase, terraformVersion)

rt := &ArtClient{
ArtOld: nil,
ArtNew: nil,
Xray: nil,
Resty: restyBase,
if err != nil {
return nil, err
}

return rt, nil

return restyBase, nil

}

Expand Down
Loading

0 comments on commit 4b46eb8

Please sign in to comment.