Skip to content

Commit

Permalink
adding Auth0 Provider (GoogleCloudPlatform#1225)
Browse files Browse the repository at this point in the history
* adding Auth0 Provider

* Delete .terraform.lock.hcl

* Delete versions.tf

* cleanup, adding readme
  • Loading branch information
markandersontrocme authored Feb 8, 2022
1 parent bef2ee2 commit 84481cb
Show file tree
Hide file tree
Showing 18 changed files with 905 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ A CLI tool that generates `tf`/`json` and `tfstate` files based on existing infr
* [Vault](/docs/vault.md)
* Identity
* [Okta](/docs/okta.md)
* [Auth0](/docs/auth0.md)
- [Contributing](#contributing)
- [Developing](#developing)
- [Infrastructure](#infrastructure)
Expand Down Expand Up @@ -299,6 +300,7 @@ Links to download Terraform Providers:
* Xen Orchestra provider >= 0.18.0 - [here](https://github.com/ddelnano/terraform-provider-xenorchestra)
* GmailFilter provider >= 1.0.1 - [here](https://github.com/yamamoto-febc/terraform-provider-gmailfilter)
* Vault provider - [here](https://github.com/hashicorp/terraform-provider-vault)
* Auth0 provider - [here](https://github.com/alexkappa/terraform-provider-auth0)

Information on provider plugins:
https://www.terraform.io/docs/configuration/providers.html
Expand Down
60 changes: 60 additions & 0 deletions cmd/provider_cmd_auth0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd

import (
"errors"
"os"

auth0_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/auth0"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

func newCmdAuth0Importer(options ImportOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "auth0",
Short: "Import current state to Terraform configuration from Auth0",
Long: "Import current state to Terraform configuration from Auth0",
RunE: func(cmd *cobra.Command, args []string) error {
domain := os.Getenv("AUTH0_DOMAIN")
if len(domain) == 0 {
return errors.New("Domain for Auth0 must be set through `AUTH0_DOMAIN` env var")
}
clientID := os.Getenv("AUTH0_CLIENT_ID")
if len(clientID) == 0 {
return errors.New("Client ID for Auht0 must be set through `AUTH0_CLIENT_ID` env var")
}
clientSecret := os.Getenv("AUTH0_CLIENT_SECRET")
if len(clientSecret) == 0 {
return errors.New("Clien Secret for Auth0 must be set through `AUTH0_CLIENT_SECRET` env var")
}

provider := newAuth0Provider()
err := Import(provider, options, []string{domain, clientID, clientSecret})
if err != nil {
return err
}
return nil
},
}
cmd.AddCommand(listCmd(newAuth0Provider()))
baseProviderFlags(cmd.PersistentFlags(), &options, "action", "action=name1:name2:name3")
return cmd
}

func newAuth0Provider() terraformutils.ProviderGenerator {
return &auth0_terraforming.Auth0Provider{}
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func providerImporterSubcommands() []func(options ImportOptions) *cobra.Command
newCmdGmailfilterImporter,
newCmdVaultImporter,
newCmdOktaImporter,
newCmdAuth0Importer,
}
}

Expand Down Expand Up @@ -129,6 +130,7 @@ func providerGenerators() map[string]func() terraformutils.ProviderGenerator {
newGmailfilterProvider,
newVaultProvider,
newOktaProvider,
newAuth0Provider,
} {
list[providerGen().GetName()] = providerGen
}
Expand Down
35 changes: 35 additions & 0 deletions docs/auth0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Use with Auth0

Example:

```
$ export AUTH0_DOMAIN=<DOMAIN>
$ export AUTH0_CLIENT_ID=<CLIENT_ID>
$ export AUTH0_CLIENT_SECRET=<CLIENT_SECRET>
$ terraformer import auth0 --resources=rule,user
```

List of supported Auth0 services:


* `action`
* `auth0_action`
* `client`
* `auth0_client`
* `client_grant`
* `auth0_client_grant`
* `hook`
* `auth0_hook`
* `resource_server`
* `auth0_resource_server`
* `role`
* `auth0_role`
* `rule`
* `auth0_rule`
* `rule_config`
* `auth0_rule_config`
* `trigger`
* `auth0_trigger`
* `user`
* `auth0_user`

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc v1.35.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/auth0.v5 v5.21.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
Expand All @@ -336,6 +337,7 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

require github.com/PuerkitoBio/rehttp v1.0.0 // indirect
require github.com/peterhellberg/link v1.1.0 // indirect

replace gopkg.in/jarcoal/httpmock.v1 => github.com/jarcoal/httpmock v1.0.5
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ github.com/PaloAltoNetworks/pango v0.6.0 h1:QKe17XsICz2P1S6sKpaH1w8zr/4Q3jYsYVq7
github.com/PaloAltoNetworks/pango v0.6.0/go.mod h1:xpwEKL6CHhniRcqKYTjIiGBzPd3QIyto3sz2ynsP1qg=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/rehttp v1.0.0 h1:aJ7A7YI2lIvOxcJVeUZY4P6R7kKZtLeONjgyKGwOIu8=
github.com/PuerkitoBio/rehttp v1.0.0/go.mod h1:ItsOiHl4XeMOV3rzbZqQRjLc3QQxbE6391/9iNG7rE8=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
github.com/SAP/go-hdb v0.105.2 h1:ZVsCj1fMBYFfAG9ZlsA9ARmM3dv24tzotBS2ghyKY0c=
Expand Down Expand Up @@ -387,12 +389,14 @@ github.com/aws/smithy-go v1.3.1/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAm
github.com/aws/smithy-go v1.4.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aws/smithy-go v1.9.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA=
github.com/aws/smithy-go v1.9.1/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aws/smithy-go v1.10.0 h1:gsoZQMNHnX+PaghNw4ynPsyGP7aUCqx5sY2dlPQsZ0w=
github.com/aws/smithy-go v1.10.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
Expand Down Expand Up @@ -1699,6 +1703,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/auth0.v5 v5.21.1 h1:aIqHBmnqaDv4eK2WSpTRsv2dEpT1jdHJPl+iwyDJNoo=
gopkg.in/auth0.v5 v5.21.1/go.mod h1:k1eJq1+II4rwUlecBabE7u4igEuzKUCEZAMa11PUfQk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
64 changes: 64 additions & 0 deletions providers/auth0/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2018 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package auth0

import (
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"gopkg.in/auth0.v5/management"
)

var (
ActionAllowEmptyValues = []string{}
)

type ActionGenerator struct {
Auth0Service
}

func (g ActionGenerator) createResources(actions []*management.Action) []terraformutils.Resource {
resources := []terraformutils.Resource{}
for _, action := range actions {
resourceName := *action.ID
resources = append(resources, terraformutils.NewSimpleResource(
resourceName,
resourceName+"_"+*action.Name,
"auth0_action",
"auth0",
ActionAllowEmptyValues,
))
}
return resources
}

func (g *ActionGenerator) InitResources() error {
m := g.generateClient()
list := []*management.Action{}

var page int
for {
l, err := m.Action.List(management.Page(page))
if err != nil {
return err
}
list = append(list, l.Actions...)
if !l.HasNext() {
break
}
page++
}

g.Resources = g.createResources(list)
return nil
}
104 changes: 104 additions & 0 deletions providers/auth0/auth0_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2018 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package auth0

import (
"errors"
"os"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/zclconf/go-cty/cty"
)

type Auth0Provider struct { //nolint
terraformutils.Provider
domain string
clientID string
clientSecret string
}

func (p *Auth0Provider) Init(args []string) error {
orgName := os.Getenv("AUTH0_DOMAIN")
if orgName == "" {
return errors.New("set AUTH0_DOMAIN env var")
}
p.domain = orgName

baseURL := os.Getenv("AUTH0_CLIENT_ID")
if baseURL == "" {
return errors.New("set AUTH0_CLIENT_ID env var")
}
p.clientID = baseURL

apiToken := os.Getenv("AUTH0_CLIENT_SECRET")
if apiToken == "" {
return errors.New("set AUTH0_CLIENT_SECRET env var")
}
p.clientSecret = apiToken

return nil
}

func (p *Auth0Provider) GetName() string {
return "auth0"
}

func (p *Auth0Provider) GetConfig() cty.Value {
return cty.ObjectVal(map[string]cty.Value{
"domain": cty.StringVal(p.domain),
"client_id": cty.StringVal(p.clientID),
"client_secret": cty.StringVal(p.clientSecret),
})
}

func (p *Auth0Provider) InitService(serviceName string, verbose bool) error {
var isSupported bool
if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported {
return errors.New(p.GetName() + ": " + serviceName + " not supported service")
}
p.Service = p.GetSupportedService()[serviceName]
p.Service.SetName(serviceName)
p.Service.SetVerbose(verbose)
p.Service.SetProviderName(p.GetName())
p.Service.SetArgs(map[string]interface{}{
"domain": p.domain,
"client_id": p.clientID,
"client_secret": p.clientSecret,
})
return nil
}

func (p *Auth0Provider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
return map[string]terraformutils.ServiceGenerator{
"auth0_action": &ActionGenerator{},
"auth0_client": &ClientGenerator{},
"auth0_client_grant": &ClientGrantGenerator{},
"auth0_hook": &HookGenerator{},
"auth0_resource_server": &ResourceServerGenerator{},
"auth0_role": &RoleGenerator{},
"auth0_rule": &RuleGenerator{},
"auth0_rule_config": &RuleConfigGenerator{},
"auth0_trigger": &TriggerBindingGenerator{},
"auth0_user": &UserGenerator{},
}
}

func (p Auth0Provider) GetResourceConnections() map[string]map[string][]string {
return map[string]map[string][]string{}
}

func (p Auth0Provider) GetProviderData(arg ...string) map[string]interface{} {
return map[string]interface{}{}
}
Loading

0 comments on commit 84481cb

Please sign in to comment.