forked from GoogleCloudPlatform/terraformer
-
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.
adding Auth0 Provider (GoogleCloudPlatform#1225)
* adding Auth0 Provider * Delete .terraform.lock.hcl * Delete versions.tf * cleanup, adding readme
- Loading branch information
1 parent
bef2ee2
commit 84481cb
Showing
18 changed files
with
905 additions
and
0 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,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{} | ||
} |
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,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` | ||
|
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
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,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 | ||
} |
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,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{}{} | ||
} |
Oops, something went wrong.