Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Authlete support #1331

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ A CLI tool that generates `tf`/`json` and `tfstate` files based on existing infr
* [Okta](/docs/okta.md)
* [Auth0](/docs/auth0.md)
* [AzureAD](/docs/azuread.md)
* [Authlete](/docs/authlete.md)
- [Contributing](#contributing)
- [Developing](#developing)
- [Infrastructure](#infrastructure)
Expand Down Expand Up @@ -313,8 +314,10 @@ 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)
* Identity
* Auth0 provider - [here](https://github.com/alexkappa/terraform-provider-auth0)
* AzureAD provider - [here](https://github.com/hashicorp/terraform-provider-azuread)
* Authlete provider - [here](https://github.com/authlete/terraform-provider-authlete)

Information on provider plugins:
https://www.terraform.io/docs/configuration/providers.html
Expand Down
95 changes: 95 additions & 0 deletions cmd/provider_cmd_authlete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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"
"fmt"
"os"

authlete_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/authlete"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils/terraformerstring"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func newCmdAuthleteImporter(options ImportOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "authlete",
Short: "Import current state to Terraform configuration from Authlete",
Long: "Import current state to Terraform configuration from Authlete",
RunE: func(cmd *cobra.Command, args []string) error {
apiServer := os.Getenv("AUTHLETE_API_SERVER")
if len(apiServer) == 0 {
apiServer = "https://api.authlete.com"
}
soKey := os.Getenv("AUTHLETE_SO_KEY")
soSecret := os.Getenv("AUTHLETE_SO_SECRET")
apiKey := os.Getenv("AUTHLETE_API_KEY")
apiSecret := os.Getenv("AUTHLETE_API_SECRET")

if terraformerstring.ContainsString(options.Resources, "authlete_service") ||
terraformerstring.ContainsString(options.Resources, "*") {
if len(soKey) == 0 {
return errors.New("Service Owner Key for Authlete must be set through `AUTHLETE_SO_KEY` env var in order to import the services")
}
if len(soSecret) == 0 {
return errors.New("Service Owner Secret for Authlete must be set through `AUTHLETE_SO_SECRET` env var in order to import the services")
}
}
if terraformerstring.ContainsString(options.Resources, "authlete_client") ||
terraformerstring.ContainsString(options.Resources, "*") {

if len(apiKey) == 0 {
return errors.New("API Key for Authlete must be set through `AUTHLETE_API_KEY` env var in order to import the clients")
}
if len(apiSecret) == 0 {
return errors.New("API Secret for Authlete must be set through `AUTHLETE_API_SECRET` env var in order to import the clients")
}
}
provider := newAuthleteProvider()
err := Import(provider, options, []string{apiServer, soKey, soSecret, apiKey, apiSecret})
if err != nil {
return err
}

return nil
},
}
cmd.AddCommand(listAuthleteCmd())
baseProviderFlags(cmd.PersistentFlags(), &options, "authlete_service", "authlete_service=apikey1:apikey2:apikey3")
return cmd
}

func newAuthleteProvider() terraformutils.ProviderGenerator {
return &authlete_terraforming.AuthleteProvider{}
}

func listAuthleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List supported resources for authlete provider",
Long: "List supported resources for authlete provider",
RunE: func(cmd *cobra.Command, args []string) error {
services := []string{"authlete_service", "authlete_client"}
for _, k := range services {
fmt.Println(k)
}
return nil
},
}
cmd.Flags().AddFlag(&pflag.Flag{Name: "resources"})
return cmd
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func providerImporterSubcommands() []func(options ImportOptions) *cobra.Command
newCmdVaultImporter,
newCmdOktaImporter,
newCmdAuth0Importer,
newCmdAuthleteImporter,
}
}

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


#### importing services definitions
Example:

```
$ export AUTHLETE_SO_KEY=<SERVICE_OWNER_KEY>
$ export AUTHLETE_SO_SECRET=<SERVICE_OWNER_SECRET>
$ terraformer import authlete --resources=authlete_service
```

#### importing clients definitions
Example:

```
$ export AUTHLETE_API_KEY=<API_KEY>
$ export AUTHLETE_API_SECRET=<API_SECRET>
$ terraformer import authlete --resources=authlete_client
```

#### importing services and client definitions
Example:

```
$ export AUTHLETE_SO_KEY=<SERVICE_OWNER_KEY>
$ export AUTHLETE_SO_SECRET=<SERVICE_OWNER_SECRET>
$ export AUTHLETE_API_KEY=<API_KEY>
$ export AUTHLETE_API_SECRET=<API_SECRET>
$ terraformer import authlete --resources=authlete_service,authlete_client
```

#### dedicated cloud or running on premise


```
$ export AUTHLETE_API_SERVER=https://<api-server-fqdn>
$ export AUTHLETE_SO_KEY=<SERVICE_OWNER_KEY>
$ export AUTHLETE_SO_SECRET=<SERVICE_OWNER_SECRET>
$ export AUTHLETE_API_KEY=<API_KEY>
$ export AUTHLETE_API_SECRET=<API_SECRET>
$ terraformer import authlete --resources=authlete_service,authlete_client
```



#### List of supported Authlete services:


* `authlete_service`
* `authlete_client`

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ require (
github.com/yandex-cloud/go-sdk v0.0.0-20220314105123-d0c2a928feb6
github.com/zclconf/go-cty v1.10.0
github.com/zorkian/go-datadog-api v2.30.0+incompatible
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401
golang.org/x/text v0.3.7
gonum.org/v1/gonum v0.7.0
google.golang.org/api v0.70.0
Expand Down Expand Up @@ -314,7 +314,7 @@ require (
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down Expand Up @@ -359,6 +359,7 @@ require (
github.com/Myra-Security-GmbH/signature v1.0.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/authlete/openapi-for-go v1.1.0 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/fatih/color v1.7.0 // indirect
Expand Down