Skip to content

Commit

Permalink
Merge pull request #125 from formalco/add_user_async
Browse files Browse the repository at this point in the history
Add user async
  • Loading branch information
ahmb84 authored Sep 14, 2023
2 parents 31ef199 + 45ae293 commit a99e12f
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 1,963 deletions.
49 changes: 5 additions & 44 deletions formal/api/client.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,14 @@
package api

import (
"errors"
"fmt"
"io"
"net/http"
"time"
"github.com/formalco/go-sdk/sdk"
)

type Client struct {
HostURL string
HTTPClient *http.Client
APIKey string
type GrpcClient struct {
ReturnSensitiveValue bool
Sdk *sdk.FormalSDK
}

const FORMAL_HOST_URL string = "https://api.formalcloud.net"

func NewClient(apiKey string, returnSensitiveValue bool) (*Client, error) {
c := Client{
HTTPClient: &http.Client{Timeout: 100 * time.Second},
APIKey: apiKey,
HostURL: FORMAL_HOST_URL,
ReturnSensitiveValue: returnSensitiveValue,
}

return &c, nil
}

func (c *Client) doRequest(req *http.Request) ([]byte, error) {
if c.APIKey == "" {
return nil, errors.New("client was not initialized with an api key")
}
req.Header.Add("X-Api-Key", c.APIKey)

res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()

body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("status: %d, body: %s", res.StatusCode, body)
}

return body, err
func NewClient(apiKey string, returnSensitiveValue bool) *GrpcClient {
return &GrpcClient{Sdk: sdk.New(apiKey), ReturnSensitiveValue: returnSensitiveValue}
}
96 changes: 0 additions & 96 deletions formal/api/client_cloud_account.go

This file was deleted.

151 changes: 0 additions & 151 deletions formal/api/client_dataplane.go

This file was deleted.

Loading

0 comments on commit a99e12f

Please sign in to comment.