https://github.com/hazcod/go-intigriti
Go library to interact with the intigriti API.
https://github.com/hazcod/go-intigriti
go intigriti library
Last synced: about 1 year ago
JSON representation
Go library to interact with the intigriti API.
- Host: GitHub
- URL: https://github.com/hazcod/go-intigriti
- Owner: hazcod
- License: apache-2.0
- Created: 2020-06-09T07:14:14.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-13T04:38:29.000Z (about 2 years ago)
- Last Synced: 2024-06-19T00:50:13.416Z (about 2 years ago)
- Topics: go, intigriti, library
- Language: Go
- Homepage: https://github.com/hazcod/go-intigriti
- Size: 303 KB
- Stars: 9
- Watchers: 3
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# go-intigriti
Go library and commandline client for interacting with the [Intigriti](https://www.intigriti.com/) external API.
Checkout the autogenerated [SDK docs on pkg.go.dev](https://pkg.go.dev/github.com/hazcod/go-intigriti).
## Commandline client
Usage:
```shell
# list out all company programs
# also try: inti c list
% inti company list-programs
# list out all company submissions across all programs
# also try: inti c sub
% inti company list-submissions
# verify if a specific IP address is linked to an Intigriti user
# also try: inti c ip 1.1.1.1
% inti company check-ip 1.1.1.1
```
### Setup
Ensure the external API enabled on your company account and an integration is created with a redirect URI value of `http://localhost:1337/`.
Afterwards create the following local configuration file:
```yaml
log.level: info
auth:
client_id: YOUR-CLIENT-ID
client_secret: YOUR-CLIENT-SECRET
```
For the first call it will ask you to perform browser interaction to authenticate.
Future calls will not need to since your token will be cached in your configuration file.
If you selected 'non-expiring access tokens in the Intigriti administration panel, this code will only need interactive authentication once.
Afterwards, it will re-use the access token in your YAML configuration file.
## Library
API Swagger documentation is available on the [ReadMe](https://intigriti.readme.io/reference/introduction).
### Usage
```go
package main
import (
"flag"
"github.com/hazcod/go-intigriti/cmd/cli/company"
"github.com/hazcod/go-intigriti/cmd/config"
intigriti "github.com/hazcod/go-intigriti/pkg/api"
apiConfig "github.com/hazcod/go-intigriti/pkg/config"
"github.com/sirupsen/logrus"
"strings"
)
func main() {
logger := logrus.New()
configPath := flag.String("config", "inti.yml", "Path to your config file.")
logLevelStr := flag.String("log", "", "Log level.")
flag.Parse()
if *logLevelStr != "" {
logLevel, err := logrus.ParseLevel(*logLevelStr)
if err != nil {
logger.WithError(err).Fatal("could not parse log level")
}
logger.SetLevel(logLevel)
logger.WithField("level", logLevel.String()).Debugf("log level set")
}
cfg, err := config.Load(logger, *configPath)
if err != nil {
logger.Fatalf("could not load configuration: %s", err)
}
if err := cfg.Validate(); err != nil {
logger.WithError(err).Fatal("invalid configuration")
}
if cfg.Log.Level != "" && *logLevelStr == "" {
logLevel, err := logrus.ParseLevel(cfg.Log.Level)
if err != nil {
logger.WithError(err).Fatal("could not parse log level")
}
logger.SetLevel(logLevel)
logger.WithField("level", logLevel.String()).Debugf("log level set")
}
//browser := ui.SystemBrowser{}
apiScopes := []string{"company_external_api", "core_platform:read"}
inti, err := intigriti.New(apiConfig.Config{
// our Intigriti API credentials
Credentials: struct {
ClientID string
ClientSecret string
}{ClientID: cfg.Auth.ClientID, ClientSecret: cfg.Auth.ClientSecret},
APIScopes: apiScopes,
// cache tokens as much as possible to reduce times we have to authenticate
TokenCache: &apiConfig.CachedToken{
RefreshToken: cfg.Cache.RefreshToken,
AccessToken: cfg.Cache.AccessToken,
ExpiryDate: cfg.Cache.ExpiryDate,
Type: cfg.Cache.Type,
},
// use our logger and our logging levels
Logger: logger,
})
if err != nil {
logger.WithError(err).Fatal("could not initialize client")
}
token, err := inti.GetToken()
if err != nil {
logger.Fatalf("failed to cache token: %v", err)
}
if err := cfg.CacheAuth(logger, *configPath, token); err != nil {
logger.Fatalf("failed to cache token: %v", err)
}
logger.WithField("authenticated", inti.IsAuthenticated()).Debug("initialized client")
if err != nil {
logger.Fatal(err)
}
programs, err := inti.GetPrograms()
if err != nil {
logger.Fatal(err)
}
for _, program := range programs {
logger.Println(program.Name)
}
}
```
### Testing
```shell script
# test on production using inti.yml
go test -tags integration -v ./...
# test on staging using inti.yml
INTI_TOKEN_URL=="testing.api.com" INTI_AUTH_URL=="subs.testing.api.com" INTI_API_URL="api.testing.com" go test -tags integration -v ./...
```