From 235ec9886f31a6c81463c2c3cdc7184bc518c228 Mon Sep 17 00:00:00 2001 From: Sajad Parra Date: Wed, 25 Aug 2021 13:09:13 +0530 Subject: [PATCH] change profile to id --- DESIGN.md | 12 ++++----- PROVIDERS.md | 30 +++++++++++----------- README.md | 16 ++++++------ internal/runner/options.go | 28 ++++++++++---------- internal/runner/runner.go | 12 ++++----- pkg/inventory/inventory.go | 4 +-- pkg/providers/alibaba/alibaba.go | 16 ++++++------ pkg/providers/alibaba/instances.go | 6 ++--- pkg/providers/aws/aws.go | 16 ++++++------ pkg/providers/aws/instances.go | 6 ++--- pkg/providers/aws/route53.go | 6 ++--- pkg/providers/cloudflare/cloudflare.go | 16 ++++++------ pkg/providers/cloudflare/dns.go | 8 +++--- pkg/providers/digitalocean/digitalocean.go | 16 ++++++------ pkg/providers/digitalocean/instances.go | 8 +++--- pkg/providers/fastly/fastly.go | 16 ++++++------ pkg/providers/fastly/services.go | 6 ++--- pkg/providers/gcp/dns.go | 4 +-- pkg/providers/gcp/gcp.go | 14 +++++----- pkg/providers/heroku/applications.go | 6 ++--- pkg/providers/heroku/heroku.go | 16 ++++++------ pkg/providers/linode/instances.go | 6 ++--- pkg/providers/linode/linode.go | 16 ++++++------ pkg/providers/namecheap/domains.go | 6 ++--- pkg/providers/namecheap/namecheap.go | 16 ++++++------ pkg/providers/scaleway/instances.go | 6 ++--- pkg/providers/scaleway/scaleway.go | 16 ++++++------ pkg/schema/schema.go | 18 ++++++------- 28 files changed, 172 insertions(+), 174 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index f07770e..93b65bc 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -17,8 +17,8 @@ Each Provider implements the below described `schema.Provider` interface. The co type Provider interface { // Name returns the name of the provider Name() string - // ProfileName returns the name of the provider profile - ProfileName() string + // ID returns the name of the provider id + ID() string // Resources returns the provider for an resource deployment source. Resources(ctx context.Context) (*Resources, error) } @@ -62,7 +62,7 @@ switch value { ### Resource -A resource is a single unit in cloud belonging to an Organization. Some metadata is provided, like whether is the asset public facing or private, provider, profile name, as well as any IP addresses and DNS Names (Either among IP or DNS must always be provided). +A resource is a single unit in cloud belonging to an Organization. Some metadata is provided, like whether is the asset public facing or private, provider, id name, as well as any IP addresses and DNS Names (Either among IP or DNS must always be provided). Providers return `schema.Resource` structure that contains an array of resources and provides some convenience wrappers on top of the array like `Append` and `Merge`. These can be used during the resource collection phase to minimize boilerplate. @@ -73,10 +73,8 @@ type Resource struct { Public bool `json:"public"` // Provider is the name of provider for instance Provider string `json:"provider"` - // Profile is the profile name of the resource provider - Profile string `json:"profile,omitempty"` - // ProfileName is the name of the key profile - ProfileName string `json:"profile_name,omitempty"` + // ID is the id the resource provider + ID string `json:"id,omitempty"` // PublicIPv4 is the public ipv4 address of the instance. PublicIPv4 string `json:"public_ipv4,omitempty"` // PrivateIpv4 is the private ipv4 address of the instance diff --git a/PROVIDERS.md b/PROVIDERS.md index 23c507c..4a7c510 100644 --- a/PROVIDERS.md +++ b/PROVIDERS.md @@ -7,8 +7,8 @@ Amazon Web Services can be integrated by using the following configuration block ```yaml - # provider is the name of the provider provider: aws - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # aws_access_key is the access key for AWS account aws_access_key: AKIAXXXXXXXXXXXXXX # aws_secret_key is the secret key for AWS account @@ -32,8 +32,8 @@ Google Cloud Platform can be integrated by using the following configuration blo ```yaml - # provider is the name of the provider provider: gcp - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # gcp_service_account_key is the key token of service account. gcp_service_account_key: '{}' ``` @@ -107,8 +107,8 @@ Heroku can be integrated by using the following configuration block. ```yaml - # provider is the name of the provider provider: heroku - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # heroku_api_token is the authorization token for Heroku account heroku_api_token: cf0e05d9-4eca-4948-a012-b9xxxxxxxxxx ``` @@ -138,8 +138,8 @@ Fastly can be integrated by using the following configuration block. ```yaml - # provider is the name of the provider provider: fastly - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # fastly_api_key is the personal API token for fastly account fastly_api_key: XX-XXXXXXXXXXXXXXXXXXXXXX- ``` @@ -157,13 +157,13 @@ Linode can be integrated by using the following configuration block. ```yaml - # provider is the name of the provider provider: linode - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # linode_personal_access_token is the personal access token for Linode account linode_personal_access_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` -`linode_personal_access_token` can be created from https://cloud.linode.com/profile/tokens. Minimum scope needed is `Read Only` for `Linodes` resource. +`linode_personal_access_token` can be created from https://cloud.linode.com/id/tokens. Minimum scope needed is `Read Only` for `Linodes` resource. References - 1. https://www.linode.com/docs/guides/getting-started-with-the-linode-api/#get-an-access-token @@ -176,8 +176,8 @@ Namecheap can be integrated by using the following configuration block. ```yaml - # provider is the name of the provider provider: namecheap - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # namecheap_api_key is the api key for namecheap account namecheap_api_key: xxxxxxxxxxxxxxxxxx # namecheap_user_name is the username of the namecheap account @@ -203,8 +203,8 @@ Alibaba Cloud can be integrated by using the following configuration block. ```yaml - # provider is the name of the provider provider: alibaba - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # alibaba_region_id is the region id of the resources alibaba_region_id: ap-XXXXXXX # alibaba_access_key is the access key ID for alibaba cloud account diff --git a/README.md b/README.md index 0c710df..10bf3d0 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ The default config file should be located in `$HOME/.config/cloudlist/config.yam # Configuration file for cloudlist enumeration agent - # provider is the name of the provider (Digitalocean) provider: do - # profile is the name of the provider profile - profile: xxxx + # id is the name of the provider id + id: xxxx # digitalocean_token is the API key for digitalocean cloud platform digitalocean_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx @@ -94,8 +94,8 @@ The default config file should be located in `$HOME/.config/cloudlist/config.yam - # provider is the name of the provider (Amazon Web Services) provider: aws - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # aws_access_key is the access key for AWS account aws_access_key: AKIAXXXXXXXXXXXXXX # aws_secret_key is the secret key for AWS account @@ -103,15 +103,15 @@ The default config file should be located in `$HOME/.config/cloudlist/config.yam - # provider is the name of the provider (Google Cloud Platform) provider: gcp - # profile is the name of the provider profile - profile: logs + # id is the name of the provider id + id: logs # gcp_service_account_key is the minified json of a google cloud service account with list permissions gcp_service_account_key: '{xxxxxxxxxxxxx}' - # provider is the name of the provider provider: fastly - # profile is the name of the provider profile - profile: staging + # id is the name of the provider id + id: staging # fastly_api_key is the personal API token for fastly account fastly_api_key: XX-XXXXXXXXXXXXXXXXXXXXXX- ``` diff --git a/internal/runner/options.go b/internal/runner/options.go index 1e31d97..9877f04 100644 --- a/internal/runner/options.go +++ b/internal/runner/options.go @@ -115,8 +115,8 @@ func userHomeDir() string { const defaultConfigFile = `# Configuration file for cloudlist enumeration agent #- # provider is the name of the provider # provider: do -# # profile is the name of the provider profile -# profile: xxxx +# # id is the name of the provider id +# id: xxxx # # digitalocean_token is the API key for digitalocean cloud platform # digitalocean_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # @@ -129,8 +129,8 @@ const defaultConfigFile = `# Configuration file for cloudlist enumeration agent # #- # provider is the name of the provider # provider: aws -# # profile is the name of the provider profile -# profile: staging +# # id is the name of the provider id +# id: staging # # aws_access_key is the access key for AWS account # aws_access_key: AKIAXXXXXXXXXXXXXX # # aws_secret_key is the secret key for AWS account @@ -145,29 +145,29 @@ const defaultConfigFile = `# Configuration file for cloudlist enumeration agent #- # provider is the name of the provider # provider: heroku -# # profile is the name of the provider profile -# profile: staging +# # id is the name of the provider id +# id: staging # # heroku_api_token is the api key for Heroku account # heroku_api_token: xxxxxxxxxxxxxxxxxxxx #- # provider is the name of the provider # provider: linode -# # profile is the name of the provider profile -# profile: staging +# # id is the name of the provider id +# id: staging # # linode_personal_access_token is the personal access token for linode account # linode_personal_access_token: XXXXXXXXXXXXXXXXXXXXXXXX #- # provider is the name of the provider # provider: fastly -# # profile is the name of the provider profile -# profile: staging +# # id is the name of the provider id +# id: staging # # fastly_api_key is the personal API token for fastly account # fastly_api_key: XX-XXXXXXXXXXXXXXXXXXXXXX- #- # provider is the name of the provider # provider: alibaba -# # profile is the name of the provider profile -# profile: staging +# # id is the name of the provider id +# id: staging # # alibaba_region_id is the region id of the resources # alibaba_region_id: ap-XXXXXXX # # alibaba_access_key is the access key ID for alibaba cloud account @@ -177,8 +177,8 @@ const defaultConfigFile = `# Configuration file for cloudlist enumeration agent # - # provider is the name of the provider # provider: namecheap -# # profile is the name of the provider profile -# profile: staging +# # id is the name of the provider id +# id: staging # # namecheap_api_key is the api key for namecheap account # namecheap_api_key: XXXXXXXXXXXXXXXXXXXXXXX # # namecheap_user_name is the username of the namecheap account diff --git a/internal/runner/runner.go b/internal/runner/runner.go index cab66f4..1d8d552 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -36,8 +36,8 @@ func (r *Runner) Enumerate() { if item == nil { continue } - if _, ok := item["profile"]; !ok { - item["profile"] = "" + if _, ok := item["id"]; !ok { + item["id"] = "" } // Validate and only pass the correct items to input if r.options.Provider != "" { @@ -74,10 +74,10 @@ func (r *Runner) Enumerate() { } } - gologger.Info().Msgf("Listing assets from %s (%s) provider\n", provider.Name(), provider.ProfileName()) + gologger.Info().Msgf("Listing assets from %s (%s) provider\n", provider.Name(), provider.ID()) instances, err := provider.Resources(context.Background()) if err != nil { - gologger.Warning().Msgf("Could not get resources for provider %s %s: %s\n", provider.Name(), provider.ProfileName(), err) + gologger.Warning().Msgf("Could not get resources for provider %s %s: %s\n", provider.Name(), provider.ID(), err) continue } var hostsCount, ipCount int @@ -177,9 +177,9 @@ func (r *Runner) Enumerate() { logBuilder.WriteString(" IP Addresses") } if hostsCount == 0 && ipCount == 0 { - gologger.Warning().Msgf("No results found for %s (%s)\n", provider.Name(), provider.ProfileName()) + gologger.Warning().Msgf("No results found for %s (%s)\n", provider.Name(), provider.ID()) } else { - gologger.Info().Msgf("Found %s for %s (%s)\n", logBuilder.String(), provider.Name(), provider.ProfileName()) + gologger.Info().Msgf("Found %s for %s (%s)\n", logBuilder.String(), provider.Name(), provider.ID()) } } } diff --git a/pkg/inventory/inventory.go b/pkg/inventory/inventory.go index d4c45f3..ca9b817 100644 --- a/pkg/inventory/inventory.go +++ b/pkg/inventory/inventory.go @@ -31,10 +31,10 @@ func New(options schema.Options) (*Inventory, error) { if !ok { continue } - profile, _ := block.GetMetadata("profile") + id, _ := block.GetMetadata("id") provider, err := nameToProvider(value, block) if err != nil { - gologger.Warning().Msgf("Could not initialize provider %s %s: %s\n", value, profile, err) + gologger.Warning().Msgf("Could not initialize provider %s %s: %s\n", value, id, err) continue } inventory.Providers = append(inventory.Providers, provider) diff --git a/pkg/providers/alibaba/alibaba.go b/pkg/providers/alibaba/alibaba.go index 98558ab..acc56e4 100644 --- a/pkg/providers/alibaba/alibaba.go +++ b/pkg/providers/alibaba/alibaba.go @@ -16,8 +16,8 @@ const ( // Provider is a data provider for alibaba API type Provider struct { - profile string - client *ecs.Client + id string + client *ecs.Client } // New creates a new provider client for alibaba API @@ -35,7 +35,7 @@ func New(options schema.OptionBlock) (*Provider, error) { return nil, &schema.ErrNoSuchKey{Name: accessKeySecret} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") client, err := ecs.NewClientWithAccessKey( regionID, // region ID @@ -46,7 +46,7 @@ func New(options schema.OptionBlock) (*Provider, error) { return nil, err } - return &Provider{client: client, profile: profile}, nil + return &Provider{client: client, id: id}, nil } // Name returns the name of the provider @@ -54,14 +54,14 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - ecsprovider := &instanceProvider{client: p.client, profile: p.profile} + ecsprovider := &instanceProvider{client: p.client, id: p.id} list, err := ecsprovider.GetResource(ctx) if err != nil { return nil, err diff --git a/pkg/providers/alibaba/instances.go b/pkg/providers/alibaba/instances.go index cb56fa8..eaa2495 100644 --- a/pkg/providers/alibaba/instances.go +++ b/pkg/providers/alibaba/instances.go @@ -9,8 +9,8 @@ import ( // instanceProvider is an instance provider for alibaba API type instanceProvider struct { - profile string - client *ecs.Client + id string + client *ecs.Client } // GetResource returns all the resources in the store for a provider. @@ -34,7 +34,7 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, privateIPv4 = instance.NetworkInterfaces.NetworkInterface[0].PrivateIpSets.PrivateIpSet[0].PrivateIpAddress } list.Append(&schema.Resource{ - Profile: d.profile, + ID: d.id, Provider: providerName, PublicIPv4: ipv4, PrivateIpv4: privateIPv4, diff --git a/pkg/providers/aws/aws.go b/pkg/providers/aws/aws.go index 9e84f0f..83797e7 100644 --- a/pkg/providers/aws/aws.go +++ b/pkg/providers/aws/aws.go @@ -14,7 +14,7 @@ import ( // Provider is a data provider for aws API type Provider struct { - profile string + id string ec2Client *ec2.EC2 route53Client *route53.Route53 regions *ec2.DescribeRegionsOutput @@ -31,7 +31,7 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, &schema.ErrNoSuchKey{Name: apiSecretKey} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") config := aws.NewConfig() config.WithRegion("us-east-1") @@ -49,7 +49,7 @@ func New(options schema.OptionBlock) (*Provider, error) { if err != nil { return nil, errors.Wrap(err, "could not get list of regions") } - return &Provider{ec2Client: ec2Client, profile: profile, regions: regions, route53Client: route53Client, session: session}, nil + return &Provider{ec2Client: ec2Client, id: id, regions: regions, route53Client: route53Client, session: session}, nil } const apiAccessKey = "aws_access_key" @@ -61,19 +61,19 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - ec2provider := &instanceProvider{ec2Client: p.ec2Client, profile: p.profile, session: p.session, regions: p.regions} + ec2provider := &instanceProvider{ec2Client: p.ec2Client, id: p.id, session: p.session, regions: p.regions} list, err := ec2provider.GetResource(ctx) if err != nil { return nil, err } - route53Provider := &route53Provider{route53: p.route53Client, profile: p.profile, session: p.session} + route53Provider := &route53Provider{route53: p.route53Client, id: p.id, session: p.session} zones, err := route53Provider.GetResource(ctx) if err != nil { return nil, err diff --git a/pkg/providers/aws/instances.go b/pkg/providers/aws/instances.go index 7ee2084..a460ce4 100644 --- a/pkg/providers/aws/instances.go +++ b/pkg/providers/aws/instances.go @@ -13,7 +13,7 @@ import ( // awsInstanceProvider is an instance provider for aws API type instanceProvider struct { - profile string + id string ec2Client *ec2.EC2 session *session.Session regions *ec2.DescribeRegionsOutput @@ -49,14 +49,14 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, if privateIp4 != "" { list.Append(&schema.Resource{ - Profile: d.profile, + ID: d.id, Provider: providerName, PrivateIpv4: privateIp4, Public: false, }) } list.Append(&schema.Resource{ - Profile: d.profile, + ID: d.id, Provider: providerName, PublicIPv4: ip4, Public: true, diff --git a/pkg/providers/aws/route53.go b/pkg/providers/aws/route53.go index 256208b..5f62f13 100644 --- a/pkg/providers/aws/route53.go +++ b/pkg/providers/aws/route53.go @@ -13,7 +13,7 @@ import ( // route53Provider is a provider for aws Route53 API type route53Provider struct { - profile string + id string route53 *route53.Route53 session *session.Session } @@ -64,13 +64,13 @@ func (d *route53Provider) listResourceRecords(zone string) (*schema.Resources, e ip4 = aws.StringValue(item.ResourceRecords[0].Value) } list.Append(&schema.Resource{ - Profile: d.profile, + ID: d.id, Public: true, DNSName: name, Provider: providerName, }) list.Append(&schema.Resource{ - Profile: d.profile, + ID: d.id, Public: true, PublicIPv4: ip4, Provider: providerName, diff --git a/pkg/providers/cloudflare/cloudflare.go b/pkg/providers/cloudflare/cloudflare.go index 3a47864..e7c4d7a 100644 --- a/pkg/providers/cloudflare/cloudflare.go +++ b/pkg/providers/cloudflare/cloudflare.go @@ -9,8 +9,8 @@ import ( // Provider is a data provider for cloudflare API type Provider struct { - profile string - client *cloudflare.API + id string + client *cloudflare.API } // New creates a new provider client for cloudflare API @@ -23,14 +23,14 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, &schema.ErrNoSuchKey{Name: apiEmail} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") // Construct a new API object api, err := cloudflare.New(accessKey, apiEmail) if err != nil { return nil, err } - return &Provider{profile: profile, client: api}, nil + return &Provider{id: id, client: api}, nil } const apiAccessKey = "api_key" @@ -42,14 +42,14 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - dnsProvider := &dnsProvider{profile: p.profile, client: p.client} + dnsProvider := &dnsProvider{id: p.id, client: p.client} list, err := dnsProvider.GetResource(ctx) if err != nil { return nil, err diff --git a/pkg/providers/cloudflare/dns.go b/pkg/providers/cloudflare/dns.go index 2663caa..180ae22 100644 --- a/pkg/providers/cloudflare/dns.go +++ b/pkg/providers/cloudflare/dns.go @@ -10,8 +10,8 @@ import ( // dnsProvider is a provider for cloudflare dns resources type dnsProvider struct { - profile string - client *cloudflare.API + id string + client *cloudflare.API } // GetResource returns all the resources in the store for a provider. @@ -36,13 +36,13 @@ func (d *dnsProvider) GetResource(ctx context.Context) (*schema.Resources, error Public: true, Provider: providerName, DNSName: record.Name, - Profile: d.profile, + ID: d.id, }) list.Append(&schema.Resource{ Public: true, Provider: providerName, PublicIPv4: record.Content, - Profile: d.profile, + ID: d.id, }) } } diff --git a/pkg/providers/digitalocean/digitalocean.go b/pkg/providers/digitalocean/digitalocean.go index aef90f4..08c48b1 100644 --- a/pkg/providers/digitalocean/digitalocean.go +++ b/pkg/providers/digitalocean/digitalocean.go @@ -9,8 +9,8 @@ import ( // Provider is a data provider for digitalocean API type Provider struct { - profile string - client *godo.Client + id string + client *godo.Client } // New creates a new provider client for digitalocean API @@ -19,8 +19,8 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, &schema.ErrNoSuchKey{Name: apiKey} } - profile, _ := options.GetMetadata("profile") - return &Provider{profile: profile, client: godo.NewFromToken(token)}, nil + id, _ := options.GetMetadata("id") + return &Provider{id: id, client: godo.NewFromToken(token)}, nil } const providerName = "do" @@ -30,15 +30,15 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } const apiKey = "digitalocean_token" // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - provider := &instanceProvider{client: p.client, profile: p.profile} + provider := &instanceProvider{client: p.client, id: p.id} return provider.GetResource(ctx) } diff --git a/pkg/providers/digitalocean/instances.go b/pkg/providers/digitalocean/instances.go index 4c1e225..aa89d76 100644 --- a/pkg/providers/digitalocean/instances.go +++ b/pkg/providers/digitalocean/instances.go @@ -9,8 +9,8 @@ import ( // instanceProvider is an instance provider for digitalocean API type instanceProvider struct { - profile string - client *godo.Client + id string + client *godo.Client } // GetInstances returns all the instances in the store for a provider. @@ -31,13 +31,13 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, if privateIP4 != "" { list.Append(&schema.Resource{ Provider: providerName, - Profile: d.profile, + ID: d.id, PrivateIpv4: privateIP4, }) } list.Append(&schema.Resource{ Provider: providerName, - Profile: d.profile, + ID: d.id, PublicIPv4: ip4, Public: true, }) diff --git a/pkg/providers/fastly/fastly.go b/pkg/providers/fastly/fastly.go index 6b0e719..6dbdfdc 100644 --- a/pkg/providers/fastly/fastly.go +++ b/pkg/providers/fastly/fastly.go @@ -15,8 +15,8 @@ const ( // Provider is a data provider for fastly API type Provider struct { - client *fastly.Client - profile string + client *fastly.Client + id string } // New creates a new provider client for fastly API @@ -25,13 +25,13 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, errors.New("could not get API Key") } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") client, err := fastly.NewClient(apiKey) if err != nil { return nil, err } - return &Provider{client: client, profile: profile}, err + return &Provider{client: client, id: id}, err } // Name returns the name of the provider @@ -39,14 +39,14 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - serviceProvider := &serviceProvider{client: p.client, profile: p.profile} + serviceProvider := &serviceProvider{client: p.client, id: p.id} services, err := serviceProvider.GetResource(ctx) if err != nil { return nil, err diff --git a/pkg/providers/fastly/services.go b/pkg/providers/fastly/services.go index 350cbcc..d775380 100644 --- a/pkg/providers/fastly/services.go +++ b/pkg/providers/fastly/services.go @@ -9,8 +9,8 @@ import ( // type serviceProvider struct { - client *fastly.Client - profile string + client *fastly.Client + id string } // GetResource returns all the resources in the store for a provider. @@ -32,7 +32,7 @@ func (d *serviceProvider) GetResource(ctx context.Context) (*schema.Resources, e list.Append(&schema.Resource{ Provider: providerName, DNSName: domain.Name, - Profile: d.profile, + ID: d.id, }) } } diff --git a/pkg/providers/gcp/dns.go b/pkg/providers/gcp/dns.go index 4f24f5f..5db4ecb 100644 --- a/pkg/providers/gcp/dns.go +++ b/pkg/providers/gcp/dns.go @@ -10,7 +10,7 @@ import ( // cloudDNSProvider is a provider for aws Route53 API type cloudDNSProvider struct { - profile string + id string dns *dns.Service projects []string } @@ -58,7 +58,7 @@ func (d *cloudDNSProvider) parseRecordsForResourceSet(r *dns.ResourceRecordSetsL DNSName: resource.Name, Public: true, PublicIPv4: data, - Profile: d.profile, + ID: d.id, Provider: providerName, }) } diff --git a/pkg/providers/gcp/gcp.go b/pkg/providers/gcp/gcp.go index 90b2f76..8d7fbda 100644 --- a/pkg/providers/gcp/gcp.go +++ b/pkg/providers/gcp/gcp.go @@ -13,7 +13,7 @@ import ( // Provider is a data provider for gcp API type Provider struct { dns *dns.Service - profile string + id string projects []string } @@ -23,7 +23,7 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, errors.New("could not get API Key") } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") creds := option.WithCredentialsJSON([]byte(gcpDNSKey)) dnsService, err := dns.NewService(context.Background(), creds) @@ -43,7 +43,7 @@ func New(options schema.OptionBlock) (*Provider, error) { } return nil }) - return &Provider{dns: dnsService, projects: projects, profile: profile}, err + return &Provider{dns: dnsService, projects: projects, id: id}, err } const serviceAccountJSON = "gcp_service_account_key" @@ -54,14 +54,14 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - cloudDNSProvider := &cloudDNSProvider{dns: p.dns, profile: p.profile, projects: p.projects} + cloudDNSProvider := &cloudDNSProvider{dns: p.dns, id: p.id, projects: p.projects} zones, err := cloudDNSProvider.GetResource(ctx) if err != nil { return nil, err diff --git a/pkg/providers/heroku/applications.go b/pkg/providers/heroku/applications.go index a71875d..5b222e5 100644 --- a/pkg/providers/heroku/applications.go +++ b/pkg/providers/heroku/applications.go @@ -9,8 +9,8 @@ import ( // instanceProvider is an instance provider for Heroku API type instanceProvider struct { - profile string - client *heroku.Service + id string + client *heroku.Service } // GetResource returns all the applications for the Heroku provider. @@ -33,7 +33,7 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, list.Append(&schema.Resource{ DNSName: app.WebURL, Public: isPublic, - Profile: d.profile, + ID: d.id, Provider: providerName, }) } diff --git a/pkg/providers/heroku/heroku.go b/pkg/providers/heroku/heroku.go index 2f710e8..8dfd393 100644 --- a/pkg/providers/heroku/heroku.go +++ b/pkg/providers/heroku/heroku.go @@ -15,8 +15,8 @@ const ( // Provider is a data provider for Heroku API type Provider struct { - profile string - client *heroku.Service + id string + client *heroku.Service } // New creates a new provider client for Heroku API @@ -25,11 +25,11 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, &schema.ErrNoSuchKey{Name: apiKey} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") heroku.DefaultTransport.BearerToken = token - return &Provider{profile: profile, client: heroku.NewService(heroku.DefaultClient)}, nil + return &Provider{id: id, client: heroku.NewService(heroku.DefaultClient)}, nil } // Name returns the name of the provider @@ -37,13 +37,13 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - provider := &instanceProvider{client: p.client, profile: p.profile} + provider := &instanceProvider{client: p.client, id: p.id} return provider.GetResource(ctx) } diff --git a/pkg/providers/linode/instances.go b/pkg/providers/linode/instances.go index 66bfe7b..b299fa3 100644 --- a/pkg/providers/linode/instances.go +++ b/pkg/providers/linode/instances.go @@ -9,8 +9,8 @@ import ( // instanceProvider is an instance provider for linode API type instanceProvider struct { - profile string - client *linodego.Client + id string + client *linodego.Client } // GetResource returns all the instance resources for a provider. @@ -32,7 +32,7 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, list.Append(&schema.Resource{ Provider: providerName, PublicIPv4: ip4, - Profile: d.profile, + ID: d.id, Public: ip4 != "", }) } diff --git a/pkg/providers/linode/linode.go b/pkg/providers/linode/linode.go index d1ae830..b468e0b 100644 --- a/pkg/providers/linode/linode.go +++ b/pkg/providers/linode/linode.go @@ -16,8 +16,8 @@ const ( // Provider is a data provider for linode API type Provider struct { - profile string - client *linodego.Client + id string + client *linodego.Client } // New creates a new provider client for linode API @@ -26,7 +26,7 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, &schema.ErrNoSuchKey{Name: apiKey} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey}) oc := &http.Client{ @@ -38,7 +38,7 @@ func New(options schema.OptionBlock) (*Provider, error) { client := linodego.NewClient(oc) - return &Provider{profile: profile, client: &client}, nil + return &Provider{id: id, client: &client}, nil } // Name returns the name of the provider @@ -46,13 +46,13 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - provider := &instanceProvider{client: p.client, profile: p.profile} + provider := &instanceProvider{client: p.client, id: p.id} return provider.GetResource(ctx) } diff --git a/pkg/providers/namecheap/domains.go b/pkg/providers/namecheap/domains.go index 9b050d3..4c938c4 100644 --- a/pkg/providers/namecheap/domains.go +++ b/pkg/providers/namecheap/domains.go @@ -9,8 +9,8 @@ import ( // domainProvider is an domain provider for NameCheap API type domainProvider struct { - profile string - client *namecheap.Client + id string + client *namecheap.Client } // GetResource returns all the applications for the NameCheap provider. @@ -34,7 +34,7 @@ func (d *domainProvider) GetResource(ctx context.Context) (*schema.Resources, er list.Append(&schema.Resource{ Provider: providerName, DNSName: *domain.Name, - Profile: d.profile, + ID: d.id, }) } if *domainList.Paging.TotalItems <= (*domainList.Paging.PageSize * *domainList.Paging.CurrentPage) { diff --git a/pkg/providers/namecheap/namecheap.go b/pkg/providers/namecheap/namecheap.go index 98f7855..355534c 100644 --- a/pkg/providers/namecheap/namecheap.go +++ b/pkg/providers/namecheap/namecheap.go @@ -17,8 +17,8 @@ const ( // Provider is a data provider for NameCheap API type Provider struct { - profile string - client *namecheap.Client + id string + client *namecheap.Client } // New creates a new provider client for NameCheap API @@ -32,7 +32,7 @@ func New(options schema.OptionBlock) (*Provider, error) { return nil, &schema.ErrNoSuchKey{Name: userName} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") //using iputil to fetch public ip publicIp, err := iputil.WhatsMyIP() @@ -48,7 +48,7 @@ func New(options schema.OptionBlock) (*Provider, error) { UseSandbox: false, } - return &Provider{profile: profile, client: namecheap.NewClient(&clientOptions)}, nil + return &Provider{id: id, client: namecheap.NewClient(&clientOptions)}, nil } // Name returns the name of the provider @@ -56,13 +56,13 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } // Resources returns the provider for an resource func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - provider := &domainProvider{client: p.client, profile: p.profile} + provider := &domainProvider{client: p.client, id: p.id} return provider.GetResource(ctx) } diff --git a/pkg/providers/scaleway/instances.go b/pkg/providers/scaleway/instances.go index f2e068f..c3cb8b9 100644 --- a/pkg/providers/scaleway/instances.go +++ b/pkg/providers/scaleway/instances.go @@ -10,7 +10,7 @@ import ( // instanceProvider is an instance provider for scaleway API type instanceProvider struct { - profile string + id string instanceAPI *instance.API } @@ -42,13 +42,13 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources, if privateIP4 != "" { list.Append(&schema.Resource{ Provider: providerName, - Profile: d.profile, + ID: d.id, PrivateIpv4: privateIP4, }) } list.Append(&schema.Resource{ Provider: providerName, - Profile: d.profile, + ID: d.id, PublicIPv4: ip4, Public: true, }) diff --git a/pkg/providers/scaleway/scaleway.go b/pkg/providers/scaleway/scaleway.go index a1868cd..68531dc 100644 --- a/pkg/providers/scaleway/scaleway.go +++ b/pkg/providers/scaleway/scaleway.go @@ -10,8 +10,8 @@ import ( // Provider is a data provider for scaleway API type Provider struct { - profile string - client *scw.Client + id string + client *scw.Client } // New creates a new provider client for scaleway API @@ -24,13 +24,13 @@ func New(options schema.OptionBlock) (*Provider, error) { if !ok { return nil, &schema.ErrNoSuchKey{Name: apiAccessToken} } - profile, _ := options.GetMetadata("profile") + id, _ := options.GetMetadata("id") client, err := scw.NewClient(scw.WithAuth(accessKey, accessToken)) if err != nil { return nil, err } - return &Provider{client: client, profile: profile}, nil + return &Provider{client: client, id: id}, nil } const providerName = "scw" @@ -40,9 +40,9 @@ func (p *Provider) Name() string { return providerName } -// ProfileName returns the name of the provider profile -func (p *Provider) ProfileName() string { - return p.profile +// ID returns the name of the provider id +func (p *Provider) ID() string { + return p.id } const apiAccessKey = "scaleway_access_key" @@ -50,6 +50,6 @@ const apiAccessToken = "scaleway_access_token" // Resources returns the provider for an resource deployment source. func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) { - provider := &instanceProvider{instanceAPI: instance.NewAPI(p.client), profile: p.profile} + provider := &instanceProvider{instanceAPI: instance.NewAPI(p.client), id: p.id} return provider.GetResource(ctx) } diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 11d2785..9c02f1a 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -15,8 +15,8 @@ import ( type Provider interface { // Name returns the name of the provider Name() string - // ProfileName returns the name of the provider profile - ProfileName() string + // ID returns the name of the provider id + ID() string // Resources returns the provider for an resource deployment source. Resources(ctx context.Context) (*Resources, error) } @@ -46,10 +46,10 @@ func init() { } // appendResourceWithTypeAndMeta appends a resource with a type and metadata -func (r *Resources) appendResourceWithTypeAndMeta(resourceType validate.ResourceType, item, profile, provider string) { +func (r *Resources) appendResourceWithTypeAndMeta(resourceType validate.ResourceType, item, id, provider string) { resource := &Resource{ Provider: provider, - Profile: profile, + ID: id, } switch resourceType { case validate.DNSName: @@ -70,17 +70,17 @@ func (r *Resources) appendResourceWithTypeAndMeta(resourceType validate.Resource func (r *Resources) appendResource(resource *Resource) { if _, ok := uniqueMap.Load(resource.DNSName); !ok && resource.DNSName != "" { resourceType := validator.Identify(resource.DNSName) - r.appendResourceWithTypeAndMeta(resourceType, resource.DNSName, resource.Profile, resource.Provider) + r.appendResourceWithTypeAndMeta(resourceType, resource.DNSName, resource.ID, resource.Provider) uniqueMap.Store(resource.DNSName, struct{}{}) } if _, ok := uniqueMap.Load(resource.PublicIPv4); !ok && resource.PublicIPv4 != "" { resourceType := validator.Identify(resource.PublicIPv4) - r.appendResourceWithTypeAndMeta(resourceType, resource.PublicIPv4, resource.Profile, resource.Provider) + r.appendResourceWithTypeAndMeta(resourceType, resource.PublicIPv4, resource.ID, resource.Provider) uniqueMap.Store(resource.PublicIPv4, struct{}{}) } if _, ok := uniqueMap.Load(resource.PrivateIpv4); !ok && resource.PrivateIpv4 != "" { resourceType := validator.Identify(resource.PrivateIpv4) - r.appendResourceWithTypeAndMeta(resourceType, resource.PrivateIpv4, resource.Profile, resource.Provider) + r.appendResourceWithTypeAndMeta(resourceType, resource.PrivateIpv4, resource.ID, resource.Provider) uniqueMap.Store(resource.PrivateIpv4, struct{}{}) } } @@ -103,8 +103,8 @@ type Resource struct { Public bool `json:"public"` // Provider is the name of provider for instance Provider string `json:"provider"` - // Profile is the profile name of the resource provider - Profile string `json:"profile,omitempty"` + // ID is the id name of the resource provider + ID string `json:"id,omitempty"` // PublicIPv4 is the public ipv4 address of the instance. PublicIPv4 string `json:"public_ipv4,omitempty"` // PrivateIpv4 is the private ipv4 address of the instance