Skip to content

Commit

Permalink
Minor stylistic fixes reported by stylecheck linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Oct 5, 2022
1 parent 90950dc commit 7f781fe
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 49 deletions.
3 changes: 1 addition & 2 deletions cmd/ocfclient/ocfclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"time"

"github.com/plgd-dev/device/client"
local "github.com/plgd-dev/device/client"
"github.com/plgd-dev/device/schema/interfaces"
"github.com/plgd-dev/kit/v2/codec/json"
Expand Down Expand Up @@ -88,7 +87,7 @@ func (c *OCFClient) Discover(discoveryTimeout time.Duration) (string, error) {
func (c *OCFClient) OwnDevice(deviceID string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
return c.client.OwnDevice(ctx, deviceID, local.WithOTMs([]client.OTMType{client.OTMType_JustWorks}))
return c.client.OwnDevice(ctx, deviceID, local.WithOTMs([]local.OTMType{local.OTMType_JustWorks}))
}

// Get all resource Info of the device
Expand Down
10 changes: 5 additions & 5 deletions pkg/net/coap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func GetDeviceIDFromIdentityCertificate(cert *x509.Certificate) (string, error)
if !ekuHasClient {
return "", fmt.Errorf("not contains ExtKeyUsageClientAuth")
}
ekuHasOcfId := false
ekuHasOcfID := false
for _, eku := range cert.UnknownExtKeyUsage {
if eku.Equal(ExtendedKeyUsage_IDENTITY_CERTIFICATE) {
ekuHasOcfId = true
ekuHasOcfID = true
break
}
}
if !ekuHasOcfId {
if !ekuHasOcfID {
return "", fmt.Errorf("not contains ExtKeyUsage with OCF ID(1.3.6.1.4.1.44924.1.6")
}
cn := strings.Split(cert.Subject.CommonName, ":")
Expand All @@ -88,11 +88,11 @@ func GetDeviceIDFromIdentityCertificate(cert *x509.Certificate) (string, error)
if strings.ToLower(cn[0]) != "uuid" {
return "", fmt.Errorf("invalid subject common name %v: 'uuid' - not found", cert.Subject.CommonName)
}
deviceId, err := uuid.Parse(cn[1])
deviceID, err := uuid.Parse(cn[1])
if err != nil {
return "", fmt.Errorf("invalid subject common name %v: %w", cert.Subject.CommonName, err)
}
return deviceId.String(), nil
return deviceID.String(), nil
}

func VerifyIdentityCertificate(cert *x509.Certificate) error {
Expand Down
32 changes: 16 additions & 16 deletions schema/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,37 @@ const (
AllPermissions = Permission_CREATE | Permission_READ | Permission_WRITE | Permission_DELETE | Permission_NOTIFY
)

func (s Permission) String() string {
func (p Permission) String() string {
res := make([]string, 0, 5)
if s.Has(Permission_CREATE) {
if p.Has(Permission_CREATE) {
res = append(res, "CREATE")
s &^= Permission_CREATE
p &^= Permission_CREATE
}
if s.Has(Permission_READ) {
if p.Has(Permission_READ) {
res = append(res, "READ")
s &^= Permission_READ
p &^= Permission_READ
}
if s.Has(Permission_WRITE) {
if p.Has(Permission_WRITE) {
res = append(res, "WRITE")
s &^= Permission_WRITE
p &^= Permission_WRITE
}
if s.Has(Permission_DELETE) {
if p.Has(Permission_DELETE) {
res = append(res, "DELETE")
s &^= Permission_DELETE
p &^= Permission_DELETE
}
if s.Has(Permission_NOTIFY) {
if p.Has(Permission_NOTIFY) {
res = append(res, "NOTIFY")
s &^= Permission_NOTIFY
p &^= Permission_NOTIFY
}
if s != 0 {
res = append(res, fmt.Sprintf("unknown(%v)", int(s)))
if p != 0 {
res = append(res, fmt.Sprintf("unknown(%v)", int(p)))
}
return strings.Join(res, "|")
}

// Has returns true if the flag is set.
func (b Permission) Has(flag Permission) bool {
return b&flag != 0
func (p Permission) Has(flag Permission) bool {
return p&flag != 0
}

type Resource struct {
Expand Down Expand Up @@ -123,7 +123,7 @@ const (
ConnectionType_ANON_CLEAR ConnectionType = "anon-clear"
)

// anyof/oneof
// Subject contains anyof/oneof the subtypes
type Subject struct {
*Subject_Device
*Subject_Role
Expand Down
8 changes: 6 additions & 2 deletions schema/cloud/configuration.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Cloud Configuration Resource
// Package cloud implements Cloud Configuration Resource.
// https://github.com/openconnectivityfoundation/cloud-services/blob/master/swagger2.0/oic.r.coapcloudconf.swagger.json
package cloud

const (
// ConfigurationResourceType is the resource type of the Cloud Configuration Resource.
ConfigurationResourceType = "oic.r.coapcloudconf"
ConfigurationResourceURI = "/CoapCloudConfResURI"
// ConfigurationResourceURI is the URI of the Cloud Configuration Resource.
ConfigurationResourceURI = "/CoapCloudConfResURI"
)

// ProvisioningStatus indicates the Cloud Provisioning status of the Device.
Expand All @@ -18,6 +20,7 @@ const (
ProvisioningStatus_FAILED ProvisioningStatus = "failed"
)

// Configuration contains the supported fields of the Cloud Configuration Resource.
type Configuration struct {
ResourceTypes []string `json:"rt"`
Interfaces []string `json:"if"`
Expand All @@ -29,6 +32,7 @@ type Configuration struct {
ProvisioningStatus ProvisioningStatus `json:"cps"`
}

// ConfigurationUpdateRequest is used to update the Cloud Configuration Resource.
type ConfigurationUpdateRequest struct {
AuthorizationProvider string `json:"apn"`
URL string `json:"cis"`
Expand Down
2 changes: 1 addition & 1 deletion schema/csr/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CertificateSigningRequestResponse struct {
Interfaces []string `json:"if"`
ResourceTypes []string `json:"rt"`
Name string `json:"n"`
InstanceId string `json:"id"`
InstanceID string `json:"id"`
Encoding CertificateEncoding `json:"encoding"`
CertificateSigningRequest interface{} `json:"csr"`
}
Expand Down
48 changes: 25 additions & 23 deletions schema/pstat/pstat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Device Provisioning Status
// Package cloud implements Device Provisioning Status
// https://github.com/openconnectivityfoundation/security/blob/master/swagger2.0/oic.sec.pstat.swagger.json
package pstat

Expand All @@ -8,8 +8,10 @@ import (
)

const (
// ResourceType is the resource type of the Device Provisioning Status Resource.
ResourceType = "oic.r.pstat"
ResourceURI = "/oic/sec/pstat"
// ResourceURI is the URI of the Device Provisioning Status Resource.
ResourceURI = "/oic/sec/pstat"
)

type DeviceOnboardingState struct {
Expand All @@ -24,7 +26,7 @@ type ProvisionStatusResponse struct {
CurrentOperationalMode OperationalMode `json:"om"`
CurrentProvisioningMode ProvisioningMode `json:"cm"`
Name string `json:"n"`
InstanceId string `json:"id"`
InstanceID string `json:"id"`
DeviceIsOperational bool `json:"isop"`
TargetProvisioningMode ProvisioningMode `json:"tm"`
SupportedOperationalModes OperationalMode `json:"sm"`
Expand Down Expand Up @@ -78,29 +80,29 @@ const (
OperationalMode_CLIENT_DIRECTED
)

func (s OperationalMode) String() string {
func (m OperationalMode) String() string {
res := make([]string, 0, 4)
if s.Has(OperationalMode_SERVER_DIRECTED_UTILIZING_MULTIPLE_SERVICES) {
if m.Has(OperationalMode_SERVER_DIRECTED_UTILIZING_MULTIPLE_SERVICES) {
res = append(res, "SERVER_DIRECTED_UTILIZING_MULTIPLE_SERVICES")
s &^= OperationalMode_SERVER_DIRECTED_UTILIZING_MULTIPLE_SERVICES
m &^= OperationalMode_SERVER_DIRECTED_UTILIZING_MULTIPLE_SERVICES
}
if s.Has(OperationalMode_SERVER_DIRECTED_UTILIZING_SINGLE_SERVICE) {
if m.Has(OperationalMode_SERVER_DIRECTED_UTILIZING_SINGLE_SERVICE) {
res = append(res, "SERVER_DIRECTED_UTILIZING_SINGLE_SERVICE")
s &^= OperationalMode_SERVER_DIRECTED_UTILIZING_SINGLE_SERVICE
m &^= OperationalMode_SERVER_DIRECTED_UTILIZING_SINGLE_SERVICE
}
if s.Has(OperationalMode_CLIENT_DIRECTED) {
if m.Has(OperationalMode_CLIENT_DIRECTED) {
res = append(res, "CLIENT_DIRECTED")
s &^= OperationalMode_CLIENT_DIRECTED
m &^= OperationalMode_CLIENT_DIRECTED
}
if s != 0 {
res = append(res, fmt.Sprintf("unknown(%v)", int(s)))
if m != 0 {
res = append(res, fmt.Sprintf("unknown(%v)", int(m)))
}
return strings.Join(res, "|")
}

// Has returns true if the flag is set.
func (b OperationalMode) Has(flag OperationalMode) bool {
return b&flag != 0
func (m OperationalMode) Has(flag OperationalMode) bool {
return m&flag != 0
}

type ProvisioningMode uint16
Expand All @@ -112,23 +114,23 @@ const (
ProvisioningMode_INIT_SEC_SOFT_UPDATE ProvisioningMode = 1 << 7
)

func (s ProvisioningMode) String() string {
func (m ProvisioningMode) String() string {
res := make([]string, 0, 3)
if s.Has(ProvisioningMode_INIT_SOFT_VER_VALIDATION) {
if m.Has(ProvisioningMode_INIT_SOFT_VER_VALIDATION) {
res = append(res, "INIT_SOFT_VER_VALIDATION")
s &^= ProvisioningMode_INIT_SOFT_VER_VALIDATION
m &^= ProvisioningMode_INIT_SOFT_VER_VALIDATION
}
if s.Has(ProvisioningMode_INIT_SEC_SOFT_UPDATE) {
if m.Has(ProvisioningMode_INIT_SEC_SOFT_UPDATE) {
res = append(res, "INIT_SEC_SOFT_UPDATE")
s &^= ProvisioningMode_INIT_SEC_SOFT_UPDATE
m &^= ProvisioningMode_INIT_SEC_SOFT_UPDATE
}
if s != 0 {
res = append(res, fmt.Sprintf("unknown(%v)", int(s)))
if m != 0 {
res = append(res, fmt.Sprintf("unknown(%v)", int(m)))
}
return strings.Join(res, "|")
}

// Has returns true if the flag is set.
func (b ProvisioningMode) Has(flag ProvisioningMode) bool {
return b&flag != 0
func (m ProvisioningMode) Has(flag ProvisioningMode) bool {
return m&flag != 0
}

0 comments on commit 7f781fe

Please sign in to comment.