Skip to content

Commit 5fa8b76

Browse files
committed
ccm/ocm: Add external credential support for cross-instance usage sharing
Extract credential interface from *defaultCredential to support both default (OAuth) and external (remote proxy) credential types. External credentials proxy requests to a remote ccm/ocm instance with bearer token auth, poll a /status endpoint for utilization, and parse aggregated rate limit headers from responses. Add allow_external_usage user flag to control whether balancer/fallback providers may select external credentials. Add status endpoint (/ccm/v1/status, /ocm/v1/status) returning averaged utilization across eligible credentials. Rewrite response rate limit headers for external users with aggregated values.
1 parent 7aef716 commit 5fa8b76

9 files changed

Lines changed: 1792 additions & 474 deletions

File tree

option/ccm.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ type CCMServiceOptions struct {
1919
}
2020

2121
type CCMUser struct {
22-
Name string `json:"name,omitempty"`
23-
Token string `json:"token,omitempty"`
24-
Credential string `json:"credential,omitempty"`
22+
Name string `json:"name,omitempty"`
23+
Token string `json:"token,omitempty"`
24+
Credential string `json:"credential,omitempty"`
25+
ExternalCredential string `json:"external_credential,omitempty"`
26+
AllowExternalUsage bool `json:"allow_external_usage,omitempty"`
2527
}
2628

2729
type _CCMCredential struct {
2830
Type string `json:"type,omitempty"`
2931
Tag string `json:"tag"`
3032
DefaultOptions CCMDefaultCredentialOptions `json:"-"`
33+
ExternalOptions CCMExternalCredentialOptions `json:"-"`
3134
BalancerOptions CCMBalancerCredentialOptions `json:"-"`
3235
FallbackOptions CCMFallbackCredentialOptions `json:"-"`
3336
}
@@ -40,6 +43,8 @@ func (c CCMCredential) MarshalJSON() ([]byte, error) {
4043
case "", "default":
4144
c.Type = ""
4245
v = c.DefaultOptions
46+
case "external":
47+
v = c.ExternalOptions
4348
case "balancer":
4449
v = c.BalancerOptions
4550
case "fallback":
@@ -63,6 +68,8 @@ func (c *CCMCredential) UnmarshalJSON(bytes []byte) error {
6368
case "", "default":
6469
c.Type = "default"
6570
v = &c.DefaultOptions
71+
case "external":
72+
v = &c.ExternalOptions
6673
case "balancer":
6774
v = &c.BalancerOptions
6875
case "fallback":
@@ -87,6 +94,15 @@ type CCMBalancerCredentialOptions struct {
8794
PollInterval badoption.Duration `json:"poll_interval,omitempty"`
8895
}
8996

97+
type CCMExternalCredentialOptions struct {
98+
URL string `json:"url"`
99+
ServerOptions
100+
Token string `json:"token"`
101+
Detour string `json:"detour,omitempty"`
102+
UsagesPath string `json:"usages_path,omitempty"`
103+
PollInterval badoption.Duration `json:"poll_interval,omitempty"`
104+
}
105+
90106
type CCMFallbackCredentialOptions struct {
91107
Credentials badoption.Listable[string] `json:"credentials"`
92108
PollInterval badoption.Duration `json:"poll_interval,omitempty"`

option/ocm.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ type OCMServiceOptions struct {
1919
}
2020

2121
type OCMUser struct {
22-
Name string `json:"name,omitempty"`
23-
Token string `json:"token,omitempty"`
24-
Credential string `json:"credential,omitempty"`
22+
Name string `json:"name,omitempty"`
23+
Token string `json:"token,omitempty"`
24+
Credential string `json:"credential,omitempty"`
25+
ExternalCredential string `json:"external_credential,omitempty"`
26+
AllowExternalUsage bool `json:"allow_external_usage,omitempty"`
2527
}
2628

2729
type _OCMCredential struct {
2830
Type string `json:"type,omitempty"`
2931
Tag string `json:"tag"`
3032
DefaultOptions OCMDefaultCredentialOptions `json:"-"`
33+
ExternalOptions OCMExternalCredentialOptions `json:"-"`
3134
BalancerOptions OCMBalancerCredentialOptions `json:"-"`
3235
FallbackOptions OCMFallbackCredentialOptions `json:"-"`
3336
}
@@ -40,6 +43,8 @@ func (c OCMCredential) MarshalJSON() ([]byte, error) {
4043
case "", "default":
4144
c.Type = ""
4245
v = c.DefaultOptions
46+
case "external":
47+
v = c.ExternalOptions
4348
case "balancer":
4449
v = c.BalancerOptions
4550
case "fallback":
@@ -63,6 +68,8 @@ func (c *OCMCredential) UnmarshalJSON(bytes []byte) error {
6368
case "", "default":
6469
c.Type = "default"
6570
v = &c.DefaultOptions
71+
case "external":
72+
v = &c.ExternalOptions
6673
case "balancer":
6774
v = &c.BalancerOptions
6875
case "fallback":
@@ -87,6 +94,15 @@ type OCMBalancerCredentialOptions struct {
8794
PollInterval badoption.Duration `json:"poll_interval,omitempty"`
8895
}
8996

97+
type OCMExternalCredentialOptions struct {
98+
URL string `json:"url"`
99+
ServerOptions
100+
Token string `json:"token"`
101+
Detour string `json:"detour,omitempty"`
102+
UsagesPath string `json:"usages_path,omitempty"`
103+
PollInterval badoption.Duration `json:"poll_interval,omitempty"`
104+
}
105+
90106
type OCMFallbackCredentialOptions struct {
91107
Credentials badoption.Listable[string] `json:"credentials"`
92108
PollInterval badoption.Duration `json:"poll_interval,omitempty"`

0 commit comments

Comments
 (0)