forked from redpanda-data/kminion
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package kafka | ||
|
||
// SASLGSSAPIConfig represents the Kafka Kerberos config | ||
type OAUTHBEARERConfig struct { | ||
Type OAUTHBEARERType `koanf:"type"` | ||
AdobeIMS AdobeIMSConfig `koanf:"adobeIMS"` | ||
} | ||
|
||
type OAUTHBEARERType string | ||
|
||
const ( | ||
AdobeOAUTH OAUTHBEARERType = "AdobeIMS" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kafka | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/adobe/ims-go/ims" | ||
"github.com/twmb/franz-go/pkg/kgo" | ||
"github.com/twmb/franz-go/pkg/sasl/oauth" | ||
) | ||
|
||
type AdobeIMSConfig struct { | ||
Code string `koanf:"imsClientCode"` | ||
ClientID string `koanf:"imsClientId"` | ||
ClientSecret string `koanf:"imsClientSecret"` | ||
Endpoint string `koanf:"imsEndpoint"` | ||
} | ||
|
||
type AdobeOAUTHBearer struct { | ||
config AdobeIMSConfig | ||
client *ims.Client | ||
token string | ||
} | ||
|
||
func NewAdobeOAUTHBearer(config AdobeIMSConfig) (*AdobeOAUTHBearer, error) { | ||
client, err := ims.NewClient(&ims.ClientConfig{ | ||
URL: config.Endpoint, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to retrieve token: %v", err) | ||
} | ||
|
||
token, err := client.Token(&ims.TokenRequest{ | ||
Code: config.Code, | ||
ClientID: config.ClientID, | ||
ClientSecret: config.ClientSecret, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to get token from IMS: %v", err) | ||
} | ||
|
||
return &AdobeOAUTHBearer{ | ||
config: config, | ||
client: client, | ||
token: token.AccessToken, | ||
}, nil | ||
} | ||
|
||
func (a *AdobeOAUTHBearer) Opt() kgo.Opt { | ||
return kgo.SASL(oauth.Oauth(func(ctx context.Context) (oauth.Auth, error) { | ||
return oauth.Auth{ | ||
Token: a.token, | ||
}, nil | ||
})) | ||
} |