Skip to content

Commit

Permalink
Merge pull request #84 from TheThingsNetwork/feature/skip-cac
Browse files Browse the repository at this point in the history
Export CACs only on explicit request
  • Loading branch information
KrishnaIyer committed Jul 6, 2023
2 parents 5d909b7 + 1125cf5 commit 0ec3626
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added

- Each source has its own dedicated command.
- End Device Claim Authentication Codes are exported only if `--export-cacs` is set.

### Changed

Expand All @@ -22,6 +23,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed

- Wrong flag name `appplication-server-grpc-address` fixed to `application-server-grpc-address`.

### Security

## [v0.9.0]
Expand Down
17 changes: 13 additions & 4 deletions pkg/source/tts/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func New() (*Config, *pflag.FlagSet) {
os.Getenv("TTS_DEFAULT_GRPC_ADDRESS"),
"TTS default GRPC Address (optional)")
flags.StringVar(&config.ServerConfig.ApplicationServerGRPCAddress,
"appplication-server-grpc-address",
"application-server-grpc-address",
os.Getenv("TTS_APPLICATION_SERVER_GRPC_ADDRESS"),
"TTS Application Server GRPC Address")
flags.StringVar(&config.ServerConfig.IdentityServerGRPCAddress,
Expand All @@ -123,6 +123,12 @@ func New() (*Config, *pflag.FlagSet) {
false,
"TTS delete exported devices")

flags.BoolVar(&config.ExportCACs,
"export-cacs",
false,
"Export Claim Authentication Codes (CAC)",
)

return config, flags
}

Expand All @@ -131,11 +137,14 @@ type Config struct {

ServerConfig *serverConfig

caPath, appAPIKey,
AppID string
insecure bool
caPath string
appAPIKey string

insecure, NoSession,
ExportCACs bool
NoSession bool
DeleteSourceDevice bool
AppID string
}

func (c *Config) Initialize(rootConfig source.Config) error {
Expand Down
10 changes: 8 additions & 2 deletions pkg/source/tts/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ func (s Source) ExportDevice(devID string) (*ttnpb.EndDevice, error) {
return nil, errNoAppID.New()
}

isPaths, nsPaths, asPaths, jsPaths := splitEndDeviceGetPaths(ttnpb.BottomLevelFields(ttnpb.EndDeviceFieldPathsNested)...)
basePaths := ttnpb.EndDeviceFieldPathsNested

if !s.config.ExportCACs {
basePaths = ttnpb.ExcludeFields(basePaths, claimAuthenticationCodePaths...)
}

isPaths, nsPaths, asPaths, jsPaths := splitEndDeviceGetPaths(ttnpb.BottomLevelFields(basePaths)...)
if len(nsPaths) > 0 {
isPaths = ttnpb.AddFields(isPaths, "network_server_address")
}
Expand All @@ -73,7 +79,7 @@ func (s Source) ExportDevice(devID string) (*ttnpb.EndDevice, error) {
if err != nil {
return nil, err
}
if dev.ClaimAuthenticationCode.GetValue() != "" {
if dev.ClaimAuthenticationCode.GetValue() != "" || !s.config.ExportCACs {
// ClaimAuthenticationCode is already retrieved from the IS. We can unset the related JS paths
jsPaths = ttnpb.ExcludeFields(jsPaths, claimAuthenticationCodePaths...)
}
Expand Down

0 comments on commit 0ec3626

Please sign in to comment.