Skip to content

Commit a73cbcb

Browse files
authored
feat(ui,cli): set service (name, type, region) on new consumer (#6118)
Signed-off-by: francois samin <[email protected]>
1 parent 4fef95a commit a73cbcb

File tree

7 files changed

+114
-20
lines changed

7 files changed

+114
-20
lines changed

cli/cdsctl/consumer.go

+41-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ var authConsumerNewCmd = cli.Command{
9191
Name: "duration",
9292
Usage: "Validity period of the token generated for the consumer (in days)",
9393
},
94+
{
95+
Name: "service-name",
96+
Usage: "Name of the service",
97+
},
98+
{
99+
Name: "service-type",
100+
Usage: "Type of service (hatchery, etc.)",
101+
},
102+
{
103+
Name: "service-region",
104+
Usage: "Region where the service will be started",
105+
},
94106
},
95107
}
96108

@@ -167,13 +179,40 @@ func authConsumerNewRun(v cli.Values) error {
167179
duration = time.Duration(iDuration) * (24 * time.Hour)
168180
}
169181

170-
res, err := client.AuthConsumerCreateForUser(username, sdk.AuthConsumer{
182+
var svcName = v.GetString("service-name")
183+
if svcName == "" && !v.GetBool("no-interactive") {
184+
svcName = cli.AskValue("Service name")
185+
}
186+
187+
var svcType = v.GetString("service-type")
188+
if svcType == "" && !v.GetBool("no-interactive") {
189+
svcType = cli.AskValue("Service type")
190+
}
191+
192+
var svcRegion = v.GetString("service-region")
193+
if svcRegion == "" && !v.GetBool("no-interactive") {
194+
svcRegion = cli.AskValue("Service region")
195+
}
196+
197+
var consumer = sdk.AuthConsumer{
171198
Name: name,
172199
Description: description,
173200
GroupIDs: groupIDs,
174201
ScopeDetails: sdk.NewAuthConsumerScopeDetails(scopes...),
175202
ValidityPeriods: sdk.NewAuthConsumerValidityPeriod(time.Now(), duration),
176-
})
203+
}
204+
205+
if svcName != "" {
206+
consumer.ServiceName = &svcName
207+
}
208+
if svcType != "" {
209+
consumer.ServiceType = &svcType
210+
}
211+
if svcRegion != "" {
212+
consumer.ServiceRegion = &svcRegion
213+
}
214+
215+
res, err := client.AuthConsumerCreateForUser(username, consumer)
177216
if err != nil {
178217
return err
179218
}

engine/api/auth_consumer.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ func (api *API) postConsumerByUserHandler() service.Handler {
8585

8686
// Create the new built in consumer from request data
8787
consumerOpts := builtin.NewConsumerOptions{
88-
Name: reqData.Name,
89-
Description: reqData.Description,
90-
Duration: reqData.ValidityPeriods.Latest().Duration,
91-
GroupIDs: reqData.GroupIDs,
92-
Scopes: reqData.ScopeDetails,
93-
ServiceName: reqData.ServiceName,
94-
ServiceType: reqData.ServiceType,
88+
Name: reqData.Name,
89+
Description: reqData.Description,
90+
Duration: reqData.ValidityPeriods.Latest().Duration,
91+
GroupIDs: reqData.GroupIDs,
92+
Scopes: reqData.ScopeDetails,
93+
ServiceName: reqData.ServiceName,
94+
ServiceType: reqData.ServiceType,
95+
ServiceRegion: reqData.ServiceRegion,
9596
}
9697
newConsumer, token, err := builtin.NewConsumer(ctx, tx, consumerOpts, consumer)
9798
if err != nil {

engine/api/authentication/builtin/builtin.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ func (d AuthDriver) CheckSigninRequest(req sdk.AuthConsumerSigninRequest) error
6666
// NewConsumer returns a new builtin consumer for given data.
6767
// The parent consumer should be given with all data loaded including the authentified user.
6868
type NewConsumerOptions struct {
69-
Name string
70-
Description string
71-
Duration time.Duration
72-
GroupIDs []int64
73-
Scopes sdk.AuthConsumerScopeDetails
74-
ServiceName *string
75-
ServiceType *string
69+
Name string
70+
Description string
71+
Duration time.Duration
72+
GroupIDs []int64
73+
Scopes sdk.AuthConsumerScopeDetails
74+
ServiceName *string
75+
ServiceType *string
76+
ServiceRegion *string
7677
}
7778

7879
func NewConsumer(ctx context.Context, db gorpmapper.SqlExecutorWithTx, opts NewConsumerOptions, parentConsumer *sdk.AuthConsumer) (*sdk.AuthConsumer, string, error) {
@@ -112,6 +113,7 @@ func NewConsumer(ctx context.Context, db gorpmapper.SqlExecutorWithTx, opts NewC
112113
ValidityPeriods: sdk.NewAuthConsumerValidityPeriod(time.Now(), opts.Duration),
113114
ServiceName: opts.ServiceName,
114115
ServiceType: opts.ServiceType,
116+
ServiceRegion: opts.ServiceRegion,
115117
}
116118

117119
if err := authentication.InsertConsumer(ctx, db, &c); err != nil {

ui/src/app/model/authentication.model.ts

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export class AuthConsumer {
8888
warnings: Array<AuthConsumerWarning>;
8989
validity_periods: Array<AuthConsumerValidityPeriod>;
9090
last_authentication: string;
91+
service_name: string;
92+
service_type: string;
93+
service_region: string;
9194

9295
// UI fields
9396
parent: AuthConsumer;

ui/src/app/views/settings/user/consumer-create-modal/consumer-create-modal.component.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export enum FormStepName {
2828
INFORMATIONS = 0,
2929
GROUPS = 1,
3030
SCOPES = 2,
31-
TOKEN = 3
31+
SERVICE = 3,
32+
TOKEN = 4
3233
}
3334

3435
@Component({
@@ -182,6 +183,9 @@ export class ConsumerCreateModalComponent {
182183
case FormStepName.SCOPES:
183184
this.activeStep = FormStepName.GROUPS;
184185
break;
186+
case FormStepName.SERVICE:
187+
this.activeStep = FormStepName.SCOPES;
188+
break;
185189
default:
186190
return;
187191
}
@@ -201,6 +205,9 @@ export class ConsumerCreateModalComponent {
201205
this.activeStep = FormStepName.SCOPES;
202206
break;
203207
case FormStepName.SCOPES:
208+
this.activeStep = FormStepName.SERVICE;
209+
break;
210+
case FormStepName.SERVICE:
204211
this.save();
205212
return;
206213
default:
@@ -234,6 +241,8 @@ export class ConsumerCreateModalComponent {
234241
return true;
235242
case FormStepName.SCOPES:
236243
return this.selectedScopeDetails.length > 0;
244+
case FormStepName.SERVICE:
245+
return true;
237246
default:
238247
return false;
239248
}

ui/src/app/views/settings/user/consumer-create-modal/consumer-create-modal.html

+34-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@
6767
</table>
6868
</div>
6969
</sui-accordion-panel>
70+
<sui-accordion-panel [isOpen]="activeStep === formStepName.SERVICE" [isDisabled]="true">
71+
<div title (click)="clickOpenStep(formStepName.SERVICE)">
72+
<i class="dropdown icon"></i>
73+
Service
74+
</div>
75+
<div content>
76+
<div class="ui form">
77+
<div class="ui message">
78+
<p>Optional fields for consumer used by services (eg. hatcheries).</p>
79+
</div>
80+
<div class="ui wide field">
81+
<div class="fields">
82+
<div class="six wide field">
83+
<label>{{'common_name' | translate}}</label>
84+
<input class="ui input" type="text" name="name"
85+
[(ngModel)]="newConsumer.service_name">
86+
</div>
87+
<div class="six wide field">
88+
<label>Type</label>
89+
<input class="ui input" type="text" name="type"
90+
[(ngModel)]="newConsumer.service_type">
91+
</div>
92+
<div class="six wide field">
93+
<label>Region</label>
94+
<input class="ui input" type="text" name="region"
95+
[(ngModel)]="newConsumer.service_region">
96+
</div>
97+
</div>
98+
</div>
99+
</div>
100+
</div>
101+
</sui-accordion-panel>
70102
</sui-accordion>
71103
<app-consumer-display-signin-token *ngIf="newConsumer.id" [consumer]="newConsumer"
72104
[signinToken]="signinToken">
@@ -77,15 +109,15 @@
77109
<div class="actions">
78110
<div class="ui grid">
79111
<div class="four wide column left aligned">
80-
<button *ngIf="activeStep === formStepName.GROUPS || activeStep === formStepName.SCOPES"
112+
<button *ngIf="activeStep === formStepName.GROUPS || activeStep === formStepName.SCOPES || activeStep === formStepName.SERVICE"
81113
class="ui primary button" (click)="clickBack()">
82114
{{ 'btn_back' | translate }}
83115
</button>
84116
</div>
85117
<div class="eight wide column centered">
86118
<button *ngIf="activeStep !== formStepName.TOKEN" class="ui green button" [class.loading]="loading"
87119
(click)="clickNext()">
88-
<ng-container *ngIf="activeStep === formStepName.SCOPES; then createButton; else nextButton">
120+
<ng-container *ngIf="activeStep === formStepName.SERVICE; then createButton; else nextButton">
89121
</ng-container>
90122
<ng-template #createButton>
91123
<i class="save icon"></i>{{ 'btn_create' | translate }}

ui/src/app/views/settings/user/consumer-details-modal/consumer-details-modal.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@
3535
<div class="two fields">
3636
<div class="field">
3737
<label>Last authentication</label>
38-
{{consumer.last_authentication}}
38+
{{consumer.last_authentication ? consumer.last_authentication : 'never'}}
39+
</div>
40+
<div class="field" *ngIf="consumer.service_name || consumer.service_type || consumer.service_region">
41+
<label>Service detail</label>
42+
<ul>
43+
<li>Name: {{consumer.service_name}}</li>
44+
<li>Type: {{consumer.service_type}}</li>
45+
<li>Region: {{consumer.service_region}}</li>
46+
</ul>
3947
</div>
4048
</div>
4149
<div class="field">

0 commit comments

Comments
 (0)