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

feat(lwdomain): export go package #545

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ func main() {

Look at the [lwconfig/](lwconfig/) folder for more information.

## Lacework Domain ([`lwdomain`](lwdomain/))

Go package to disseminate a domain URL into account, cluster and whether or not
it is an internal account.

### Basic Usage
```go
package main

import (
"fmt"
"os"

"github.com/lacework/go-sdk/lwdomain"
)

func main() {
domain, err := lwdomain.New("https://account.fra.lacework.net")
if err != nil {
fmt.Printf("Error %s\n", err)
os.Exit(1)
}

// Output: Lacework Account Name: account
fmt.Println("Lacework Account Name: %s", domain.Account)
}
```


## Release Process

The release process of this repository is documented at the following [Wiki page](https://github.com/lacework/go-sdk/wiki/Release-Process).
Expand Down
4 changes: 2 additions & 2 deletions api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package api

import "github.com/lacework/go-sdk/internal/domain"
import "github.com/lacework/go-sdk/lwdomain"

// AccountService is a service that interacts with Account related
// endpoints from the Lacework Server
Expand All @@ -44,6 +44,6 @@ type accountOrganizationInfoResponse struct {
}

func (r accountOrganizationInfoResponse) AccountName() string {
d, _ := domain.New(r.OrgAccountURL)
d, _ := lwdomain.New(r.OrgAccountURL)
return d.String()
}
4 changes: 2 additions & 2 deletions api/user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package api
import (
"strings"

"github.com/lacework/go-sdk/internal/domain"
"github.com/lacework/go-sdk/lwdomain"
)

// UserProfileService is the service that interacts with the UserProfile
Expand Down Expand Up @@ -49,7 +49,7 @@ type UserProfile struct {
}

func (p *UserProfile) OrgAccountName() string {
d, err := domain.New(p.URL)
d, err := lwdomain.New(p.URL)
if err != nil {
return p.URL
}
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/lacework/go-sdk/internal/domain"
"github.com/lacework/go-sdk/internal/format"
"github.com/lacework/go-sdk/lwconfig"
"github.com/lacework/go-sdk/lwdomain"
)

var (
Expand Down Expand Up @@ -242,7 +242,7 @@ func promptConfigureSetup(newProfile *lwconfig.Profile) error {
answer, ok := ans.(string)
if ok && strings.Contains(answer, ".lacework.net") {

d, err := domain.New(answer)
d, err := lwdomain.New(answer)
if err != nil {
cli.Log.Warn(err)
return answer
Expand Down Expand Up @@ -365,7 +365,7 @@ func loadUIJsonFile(file string) error {
cli.Subaccount = strings.ToLower(auth.SubAccount)

if auth.Account != "" {
d, err := domain.New(auth.Account)
d, err := lwdomain.New(auth.Account)
if err != nil {
return err
}
Expand Down
44 changes: 44 additions & 0 deletions lwdomain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Lacework Domain

Use this package to disseminate a domain URL into account, cluster and whether or not
it is an internal account.

## Usage

Download the library into your `$GOPATH`:

$ go get github.com/lacework/go-sdk/lwdomain

Import the library into your tool:

```go
import "github.com/lacework/go-sdk/lwdomain"
```

## Examples

The following URL `https://account.fra.lacework.net` would be disseminated into:
* `account` as the account name
* `fra` as the cluster name

```go
package main

import (
"fmt"
"os"

"github.com/lacework/go-sdk/lwdomain"
)

func main() {
domain, err := lwdomain.New("https://account.fra.lacework.net")
if err != nil {
fmt.Printf("Error %s\n", err)
os.Exit(1)
}

// Output: Lacework Account Name: account
fmt.Println("Lacework Account Name: %s", domain.Account)
}
```
6 changes: 3 additions & 3 deletions internal/domain/domain.go → lwdomain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.
//

package domain
package lwdomain

import (
"fmt"
Expand All @@ -39,9 +39,9 @@ type domain struct {
//
// For instance, the following URL:
// ```
// d := domain.New("https://account.fra.lacework.net")
// d, err := lwdomain.New("https://account.fra.lacework.net")
// ```
// Would be dessiminated into:
// Would be disseminated into:
// * `account` as the account name
// * `fra` as the cluster name
func New(url string) (domain, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/domain/domain_test.go → lwdomain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
// limitations under the License.
//

package domain_test
package lwdomain_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

subject "github.com/lacework/go-sdk/internal/domain"
subject "github.com/lacework/go-sdk/lwdomain"
)

func TestDomains(t *testing.T) {
Expand Down